CMPT 166 Lecture Notes - Lecture 26: Ellipse

55 views8 pages

Document Summary

In these notes you will learn: how to create a class that animates a bouncing ball based on the sprite class, how to create randomly initialized bouncing balls. A ball that bounces around the screen has been one of our key examples in this course. Bouncingball ball = new bouncingball(); void setup() { size(500, 500); ball. x = 250; ball. y = 250; ball. dx = -1. 2; ball. dy = 2. 5; ball. diam = 50; ball. fillcolor = color(0, 0, 255); void draw() { background(255); ball. update(); ball. render(); An important detail to notice here is that the bouncingball class overrides the update() function from sprite. That means that bouncingballprovides its own implementation of update() and ignores the one in sprite. With the bouncingball class written, it is now relatively easy to create multiple bouncing balls. As you can see, initializing all the variables of the bouncingball object takes a lot of code. Processing has a built-in function called random that generates random numbers.

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