Skip to content

Instantly share code, notes, and snippets.

@liamartinez
Created September 18, 2012 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamartinez/3744207 to your computer and use it in GitHub Desktop.
Save liamartinez/3744207 to your computer and use it in GitHub Desktop.
simple state switch
color redColor;
color blueColor;
boolean colorIsRed;
void setup () {
redColor = color (255, 0, 0);
blueColor = color (0, 0, 255);
colorIsRed = false; //default to a blue color
}
void draw () {
//conditional changes the fill color based on the colorIsRed boolean
if (colorIsRed == true) {
fill (redColor);
}
else {
fill (blueColor);
}
//draw the ellipse
ellipseMode (CENTER);
ellipse (width/2, height/2, 50, 50);
}
void mousePressed () {
colorIsRed = !colorIsRed; //make colorIsRed equal to whatever colorIsRed is NOT
println ("colorIsRed is: " + colorIsRed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment