// COMP1405/1005 - Day 07 // circle moves horizontally on // the screen, bouncing back and forth // mjh-2013 // declare variables to be used in the // program int x,y; // coordinate of circle int stepx; // step size of each movement // Initialize program void setup(){ size(600,400); background(222,222,0); fill(0); x = 0; // starting point y = height/2; // for circle textSize(40); stepx = 4; // initial step size } // main body of program void draw(){ // check if the circle has hit a wall // turn around if it did if (x > width){ stepx = -1 * stepx; }else if( x<0 ){ stepx = -1 * stepx; } // draw the ball (and mouse location) background(222,222,0); text( "(" + x + "," + y + ")", 30,30); ellipse(x,y,20,20); // compute new x position (take a step) x = x + stepx ; }