Skip to content

Instantly share code, notes, and snippets.

@clavis-magna
Created May 12, 2015 00:31
Show Gist options
  • Save clavis-magna/71c4b056502687899a5a to your computer and use it in GitHub Desktop.
Save clavis-magna/71c4b056502687899a5a to your computer and use it in GitHub Desktop.
change color of screen based on mouse click
//tests if mouse button is pressed and where the mouse is on the screen
//changes background color accordingly
void setup(){
size(500,500);
background(255,0,0);
}
void draw(){
//top left quater of screen && mouse pressed
if(mousePressed && mouseX > 0 && mouseY > 0 && mouseX < 250 && mouseY < 250){
background(0,255,0);
}
//top right quarter of screen && mouse pressed
else if(mousePressed && mouseX > 250 && mouseY > 0 && mouseX < 500 && mouseY < 250){
background(0,0,255);
}
//anything else
else{
background(255,0,0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment