class Ball { float x, y; // position float vx, vy; // velocity color c; float r; // radius Ball(float x0, float y0) { x = x0; y = y0; vx = random(-5,5); vy = random(-5,5); c = color(random(255),random(255),random(255)); r = random(2,10); } void draw() { fill(c); ellipse(x,y,2*r,2*r); } void update() { x += vx; y += vy; // Bounce if (x > width-r) { x = width-r; vx = -vx; } else if (x < r) { x = r; vx = -vx; } if (y > height-r) { y = height-r; vy = -vy; } else if (y < r) { y = r; vy = -vy; } } }