CMPT 166 Lecture Notes - Lecture 13: Ellipse, Physics Engine

101 views7 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions