float x, y; float xv, yv; float diam, radius; void setup() { size(500, 400); background(200); frameRate(10); x = random(width); y = random(height); xv = random(10)+1; yv = random(10)+1; diam = 50; radius = diam/2.0; } void draw() { background(200); fill(0, 0, 200); noStroke(); ellipseMode(CORNER); ellipse(x, y, diam, diam); // move the ball x += xv; y += yv; // handle right wall if (x>width) { xv = -xv; x = width; } // handle left wall if (x<0) { xv = -xv; x = 0; } // handle bottom if (y>height-radius) { yv = -yv; y = height-radius; } // handle top if (y<0) { yv = -yv; y = 0; } // add cheap gravity yv += 1; }