Click the mouse to draw a rectangle. Hit the space bar to clear the window.
Example
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 3-5: mousePressed and keyPressed
void setup() {
  size(200,200);
  background(255);
}

void draw() {
 // Nothing happens in draw() in this example!
}

// Whenever a user clicks the mouse the code written inside mousePressed() is executed.
void mousePressed() {
  stroke(0);
  fill(175);
  rectMode(CENTER);
  rect(mouseX,mouseY,16,16);
}

// Whenever a user presses a key the code written inside keyPressed() is executed.
void keyPressed() {
  background(255);
}


»

No comments yet.

Leave a comment