Skip to content

Instantly share code, notes, and snippets.

@moziauddin
Created April 7, 2020 02:58
Show Gist options
  • Save moziauddin/f1f0ea22e9fb19c69b529ee719fc262a to your computer and use it in GitHub Desktop.
Save moziauddin/f1f0ea22e9fb19c69b529ee719fc262a to your computer and use it in GitHub Desktop.
Processing Mouse Envents
int rectSize = 100;
float rectX ;
float rectY;
void setup() {
size(400,400);
background(250);
rectX = width* 0.4;
rectY = height * 0.4;
}
void draw() {
fill(99);
rect(rectX, rectY, rectSize, rectSize);
}
void mousePressed() {
if((mouseX > rectX && mouseX < (rectX + rectSize)) &&
(mouseY > rectY && mouseY < (rectY + rectSize))){
println("Clicked within the square. MouseX: " + mouseX + " - MouseY: " + mouseY);
} else {
println("You've crossed your boundaries, how dare you?");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment