class Ball { int w; int h; float x; float y; float spdX; float spdY; float gravity = .03; // Constructor Ball() { w = h = 20; x = random(0, width/2); y = random(10, 20); spdX = random(0.5, 1.3); spdY = 0; } void update() { x += spdX; spdY += gravity; y += spdY; // reaching right or left edge, reverse x if (x + w/2 > width || x - w/2 < 0) { spdX = -spdX; } // reaching bottom or top edge, reverse y and apply damping if ( y + h/2 > height || y - h/2 < 0) { spdY = -spdY; } } void display() { ellipse(x, y, w, h); } }