xxxxxxxxxx
47
let isOn= false;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
if (mouseX <= width / 3 && mouseY > 0 && mouseY < height) {
fill("blue");
rect(0, 0, width / 3, height);
}
else if (mouseX <= width / 3 * 2 && mouseY > 0 && mouseY < height) {
fill("green");
rect(width / 3, 0, width / 3, height);
//third column
} else if (mouseX <= width && mouseY > 0 && mouseY < height) {
//only toggle the light switch when I leave the column
fill("red");
rect(2 * width / 3, 0, width / 3, height);
isOn= !isOn;
}
// if(isOn === true); {
// isOn= false
// }
// }
// //if the light is on, drawn a blue rectangle
// if (isOn) {
// fill("red");
// rect(width / 3 * 2, 0, width / 3, height);
// }
}