aaaven
2/26/2017 - 4:29 PM

Button.pde

//this is the button class
class Button {
  float x, y, size;
  int result = 0;
  color buttonColor = color(100);
  boolean click;
  boolean hover;
  boolean preClick = false;
  boolean curClick = false;

  Button(float _x, float _y, float _size) {
    x = _x;
    y = _y;
    size = _size;
  }
  void check() {
    hover = false;
    click = false;
    //boolean curClick = false;
    float distance = dist(x, y, mouseX, mouseY);
    if ( distance < size/2 && !mousePressed) { 
      hover = true; //mouse hover
    }
    if (distance < size/2 && mousePressed) { 
      click = true; //click
    } 
    if (!preClick&&click) {//preClick == false && click == true
      //pushStyle();
      //fill(0, 255, 0);
      //text("on-click", 20, 20);
      //popStyle();
      println("on-click");
    }
    if (preClick&&!click) {
      //pushStyle();
      //fill(0,0,255);
      //text("off-click", 20, 20);
      //popStyle();
      println("off-click");
    }
    preClick = click;
  }

  void newCheck() {
  }

  void update() {
    buttonColor = color(100);
    if (click) {
      buttonColor = color(random(255), random(255), random(255));
    }
    if (hover) {
      buttonColor = color(255, 0, 0);
    }
  }
  void display() {
    pushStyle();
    fill(buttonColor);
    ellipse(x, y, size, size);
    popStyle();
  }
  void run() {
    check();
    update();
    display();
  }
}
//Aven,02/26/2017
//Interactive Installation
//New Media, WPP, SADA

Button button1, button2;
void setup() {
  size(400, 400);
  stroke(0);
  button1 = new Button(width/2,height/3,100);
  button2 = new Button(width/2,2*height/3,50);
}
void draw() {
  background(100);
  button1.run();
  //button2.run();
}