float x,y,xD,yD; void setup() { size(400,400); framerate(25); x=width/2; y=height/2; xD=random(50)-25; yD=random(50)-25; ellipseMode(CENTER_DIAMETER); } void loop() { background(200); ellipse(x,y, 20,20); y=y+yD; x=x+xD; if(y>height) yD=-yD; else if(y<0) yD=-yD; if(x>width) xD=-xD; else if(x<0) xD=-xD; }