float x=random(0,100); float y=random(0,100); float vx = random(1,3); float vy = random(1,3); float r = 5; void setup() { size(100,100); frameRate(25); } void draw() { background(255); fill(0,255,0); ellipse(x,y,r*2,r*2); x=x+vx; y=y+vy; if( x > width && vx > 0) { vx = -vx; } if( x < 0 && vx < 0 ) { vx = -vx; } if( ( y > height && vy > 0) || (y < 0 && vy < 0) ) { vy = -vy; } }