topical media & game development

talk show tell print

graphic-processing-learning-05-example-5-4-example-5-4.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 5-4: Hold down the button
  boolean button = false;
  
  int x = 50;
  int y = 50;
  int w = 100;
  int h = 75;
  
  void setup() {
    size(200,200); 
  }
  
  void draw() {
    // The button is pressed if (mouseX,mouseY) is inside the rectangle and mousePressed is true.
    if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && mousePressed) {
      button = true; 
    } else {
      button = false;
    }
  
   if (button) {
      background(255);
      stroke(0);
    } else {
      background(0);
      stroke(255);
    }
    
    fill(175);
    rect(x,y,w,h);
  }
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.