Part 1 —
Re-read Learning Processing Chapter 8.
Read the class notes.
Part 2 —
Take the following code that creates a bouncing ball and make a bouncing ball class. Email me the class code. (Just write the class, you don’t need to create/initialize/call the object unless you’re feeling ambitious!)
// Non-OOP Code // The global variables int x = 0; int speed = 1; void setup() { size(200, 200); } void draw() { background(255); move(); bounce(); display(); } // A function to move the ball void move() { // Change the x location by speed x = x + speed; } // A function to bounce the ball void bounce() { // If we’ve reached an edge, reverse speed if ((x > width) || (x < 0)) { speed = speed * -1; } } // A function to display the ball void display() { stroke(0); fill(175); ellipse(x, 100, 32, 32); }
**Here’s something to get you started
class BouncingBall{ //Declare the data variables BouncingBall(){ //Initialize data variables } //Write out the bouncing ball functions } //close Bouncing Ball class