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