class BouncingBall {
//Declare the data variables
color c;
int x;
int y;
int speed;
//Initialize data variables
BouncingBall() {
c = color(175);
x = 0;
y = 100;
speed = -1
}
//Write out the bouncing ball functions
move() {
x = x + speed; // Change the x location by speed
}
// A function to bounce the ball
bounce() {
// If we’ve reached an edge, reverse speed
if ((x > width) || (x < 0)) {
speed = speed * -1;
}
}
// A function to display the ball
display() {
stroke(0);
fill(c);
ellipse(x, y, 32, 32);
}
} //close Bouncing Ball class