Created
February 25, 2020 21:46
-
-
Save slambert/c9053d4123975e3f2a2d15a2e18fb4af to your computer and use it in GitHub Desktop.
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
| // 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