/* moving_a_rectangle.pde Written by Susan Evans Change the horizontal position of a rectangle using the left and right arrows on the keyboard. */ int x = 215; // position of the rectangle void setup() { size(480,120); } void draw() { background(0); // color over previous frames rect(x,45,50,50); // draw rectangle at position x if(keyPressed) { // if a key was pressed if(key == CODED) { // if the key was non-ASCII if(keyCode == LEFT) { x = x - 1; // move rectangle to the left } if(keyCode == RIGHT) { x = x + 1; // move rectangle to the right } } } }