Skip to content

Instantly share code, notes, and snippets.

@memish
Last active November 26, 2018 00:57
Show Gist options
  • Save memish/d58352e76110b9c7ad31f0b855233c86 to your computer and use it in GitHub Desktop.
Save memish/d58352e76110b9c7ad31f0b855233c86 to your computer and use it in GitHub Desktop.
//coordinates of the button/rectangle
float x = 100;
float y = 50;
float w = 150;
float h = 80;
//boolean that will become true when button pressed
boolean mpress = false;
void setup(){
size(500,500);
}
void draw(){
background(255);
fill(255,0,0);
if(mpress){//change color if button pressed
fill(0,0,255);
}
//draw rectangle
rect(x,y,w,h);
}
void mousePressed(){
//check to see if you clicked mouse in the rectangle
if(mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h){
println("The mouse is pressed and over the button");
mpress=true;
//do stuff
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment