Skip to content

Instantly share code, notes, and snippets.

@slambert
Created February 9, 2017 14:18
Show Gist options
  • Save slambert/aad8f0216cdf8a06b81d151c7925533e to your computer and use it in GitHub Desktop.
Save slambert/aad8f0216cdf8a06b81d151c7925533e to your computer and use it in GitHub Desktop.
example of how to use a mouse click to throw a switch using a boolean variable
/* Switch Sketch
Steve Lambert
*/
// declare boolean variable
boolean switchstatus = false;
int circleWidth = 30;
void setup(){
size(500,500);
background(0);
}
void draw(){
// Conditional colors
if(switchstatus == true){
fill(255,0,0); // red
} else {
fill(255); // white
}
// Draw the circle
background(0); //make it black!
// make a circle that wont go away
noStroke();
// fill(255);
ellipse(mouseX,mouseY,circleWidth,circleWidth);
ellipse(mouseX-(circleWidth*1.5),mouseY,circleWidth*.75,circleWidth*.75);
println("Switch is: " + switchstatus);
} //draw
void mouseReleased(){
switchstatus = !switchstatus;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment