CMPT 166 Lecture Notes - Lecture 13: Ellipse, Physics Engine
Document Summary
In this note, we will start the following program makes a red ball bounce around the screen. //background(255); nostroke(); fill(255, 0, 0); ellipse(x, y, 2 * radius, 2 * radius); // update position x += dx; y += dy; Notice that we"ve declared two variables on the same line, e. g. float x, y; This is just to save a bit of typing. It is the same as if we had written it out like this: float x; float y; Suppose we want the program to reset itself any time we press a key. By that we mean the screen should be cleared of any trails, and the ball should go back to its initial starting position (with its initial velocity). The easiest way to do that is to use the built-in keypressed() function. Now when you press (almost) any key on the keyboard, the screen should erase itself, and the ball should restart in the middle.