xxxxxxxxxx
45
///// Note from Melody: We will go over this again and extend on Thursday
///// Want to get ahead study the *finished* sketch we will do together?
///// Go here: https://editor.p5js.org/melodyloveless/sketches/1XtoPisbf
var lightSwitch = false;
/// we define this variable/state at the top of our sketch (vs within setup())
/// bc we want this variable to be global and accessible in the other part of our sketch
/// the light switch is on when we first start our sketch...
/// we want the lightbulb to turn "off" the next time we press our mouse
function setup() {
createCanvas(400, 400);
background(255,0,0); // red background when first open
fill(255,255,0); // yellow
ellipse(width/2,height/2,100);
console.log("light switch is currently on");
console.log("next state = " + lightSwitch);
}
function draw(){
if (lightSwitch === true) { // if the light is currently on...
background(255,0,0);// red
fill(255,255,0); // yellow
ellipse(width/2,height/2,100);
}// lightbulb
else{
background(0); // black
}
}
function mousePressed() {
// if (lightSwitch === true) { // if the light is currently on...
// print("light switch is currently on");
// lightSwitch = false; // next time we click, we want the light to turn off
// }
// else {
// ////////////////// light bulb is off
// console.log("light switch is currently off");
// lightSwitch = true; // next time we click, we want the light to turn on
// }
// console.log("next state = " + lightSwitch);
lightSwitch = !lightSwitch;
}