Skip to content

Instantly share code, notes, and snippets.

@slambert
Created February 25, 2020 21:46
Show Gist options
  • Save slambert/c9053d4123975e3f2a2d15a2e18fb4af to your computer and use it in GitHub Desktop.
Save slambert/c9053d4123975e3f2a2d15a2e18fb4af to your computer and use it in GitHub Desktop.
// Keypressed switch example
// Made by Steve Lambert February 25, 2020
color bgColor = color(255, 0, 0); // for bg color
boolean bgSwitch = false; // remembers the state of our switch
void setup() {
size(480, 480);
// done with setup
}
void draw() {
background(bgColor); // make the background whatever color the variable is
println(bgSwitch); // tell me what's happening in the console
}
void keyPressed() {
if (bgSwitch == true) {
bgColor = color(0, 0, 255); // change variable to blue
} else {
bgColor = color(255, 0, 255); // change variable to magenta
}
bgSwitch = !bgSwitch; // if true, make is false and vice versa
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment