class Ball { float x, y; // position float vx=0, vy=0; // velocity in the two directions float r=2.5; // radius float gravity=0.05; // the amount of acceleration color c; // Initialize a Ball at position (x0,y0) Ball(float x0, float y0, color c) { x = x0; y = y0; this.c = c; } void draw() { fill(c); ellipse(x,y,r*2,r*2); } void update() { // Accelerate according to gravity vy += gravity; // Move in the appropriate direction by the step size x += vx; y += vy; // Bounce if (y > height-r) { y = height-r; vy = -vy; } } }