/* keyboard_dots.pde Edited by Justin Hsia (orig. Susan Evans) Draw colored dots on canvas based on key presses. */ int position = 0; // variable to track current position void setup() { size(1000,100); // wide canvas to show many dots noStroke(); background(0); // black background fill(0); // start with "invisible" circle initially } void draw() { // always draw an ellipse at the current position ellipse(position, 40, 40, 40); } // change fill color to green, yellow, or magenta // based on which key was pressed void keyPressed() { if(key == 'g') { fill(0, 255, 0); // set fill to green } if(key == 'y') { fill(255, 255, 0); // set fill to yellow } if(key == 'm') { fill(255, 0, 255); // set fill to magenta } // always update position, regardless // of which key was pressed position = position + 50; }