// Example OOP: Ball as a class
class Ball {
// Attributes/Properties of all Ball objects
float x, y; // location in sketch
float radius; // ball radius
color ballColor;

// Move and gravity attributes
float dx = random(-2, 2);
float speed = 5.0;
float gravity = 0.1;
float dampen = 0.95;

// Constuctor
Ball() {
//x = random(width);
y = random(height/2);
x = width/2;
radius = 25;
ballColor = color(random(255), random(255), random(255));
} // end of Ball constructor

Ball(float r) {
x = width/2;
y = random(height/2);
radius = r;
ballColor = color(random(255), random(255), random(255));
} // end of Ball constructor

// behaviors
void display() {
push();
fill(ballColor);
noStroke();
circle(x, y, 2*radius);
pop();
} // display()

void move() {
x = x + dx;
y = y + speed;
speed = speed + gravity;

bounce();
} // move()

void bounce() {
if (x > (width-radius)) {
dx = -dx;
}
if (x < radius) {
dx = -dx;
}
if (y > (height-radius)) {
speed = -speed*dampen;
}
} // bounce()

} // end of class Ball