int numBalls = 10; Ball[] balls; void setup() { size(600, 600); balls = new Ball[numBalls]; for (int i = 0; i < numBalls; i++) { float radius = random(10, 30); // Random size balls[i] = new Ball(random(width), random(height / 2), radius, int(random(30, 150))); // Random delay } } void draw() { background(220); for (Ball b : balls) { b.update(); b.display(); } } class Ball { float x, y, radius; float speedY = 0; float gravity = 0.5; // Acceleration due to gravity float bounceFactor = 0.7; // Energy loss on bounce int delay; // Time before falling int timer = 0; // Counts frames color ballColor; // Stores ball color Ball(float x, float y, float radius, int delay) { this.x = x; this.y = y; this.radius = radius; this.delay = delay; // Set color based on size if (radius >= 20) { ballColor = color(255, 0, 0); // Red for larger balls } else { ballColor = color(0, 255, 0); // Green for smaller balls } } void update() { timer++; // Count frames if (timer > delay) { // Start falling after delay speedY += gravity; y += speedY; // Bounce when hitting the bottom if (y + radius > height) { y = height - radius; speedY *= -bounceFactor; } } } void display() { fill(ballColor); noStroke(); ellipse(x, y, radius * 2, radius * 2); } }