Created
February 9, 2017 14:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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