//Animate a square moving across the screen //introduction draw loop and to global variables //THIS CODE IS INTENTIONALLY BROKEN //it shows why we actually need global variable declaration //Processing Copyright info http://processing.org/copyright.html //This code copyright BitMonkey Labs under Creative Commons Licence: http://creativecommons.org/licenses/by/2.5/ //10/01/2008 int x, inc_x; int y, inc_y; //yes, I was thinking of writing a pong-clone, just got lazy :( void setup() { size(500, 500); x=0; //set the initial value of x inc_x=10; y=0; //set the initial value of x inc_y=15; frameRate(30); //play with the value here <-- speed in frames per second } void draw() //everything in draw loop with be repeated foreeeeeeeeeeeever......... { background(255, 0, 0); rect(x, y, 50, 50); x=x+inc_x; //each time through the loop increment the value of x y=y+inc_y; //each time through the loop increment the value of x if ((x>width)||(x<0)) //make sure the box bounces back :) //the two pipes above mean "OR", look up "logical operators" in the reference { inc_x=inc_x*-1; } if ((y>height)||(y<0)) //make sure the box bounces back :) //the two pipes above mean "OR", look up "logical operators" in the reference { inc_y=inc_y*-1; } if((x>mouseX)&&(x