/** FirstAnimation: A program to illustrate motion in Processing By: F. Green, 9/2006. Last modified: 10/24/2007. */ //xspeed is the horizontal speed of the ball float xspeed; //x its horizontal position float x; //Initialize the position and speed of the ball etc. void setup () { size(400, 400); background(0); xspeed = 2.5; x = 10; frameRate(100); ellipseMode(CENTER); } void draw () { background(0); smooth(); //Draw the ball: ellipse(x, 200, 20, 20); //Update its position: x = x + xspeed; //Detect collision with the walls: if (x > width - 10 || x < 10) xspeed = -xspeed; }