// declare global variables int x = 100; int speed = 5; void setup() { size(400, 400); smooth(); } void draw() { background(255); //change x by speed x = x + speed; // if we've reached an edge, reverse speed if ((x > 330) || (x < 75)) { speed = speed * -1; } // display circle at x location stroke(0); background(0); fill(175); ellipse(x, 345, 32, 32); fill(0, 255, 0); rect(340, 100, 10, 350); rect(50, 100, 10, 350); }