class Ball { float x, y; // position float vx=0, vy=0; // velocity float r=10; // radius Ball(float x0, float y0) { x = x0; y = y0; } void draw() { 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; } } }