xxxxxxxxxx
32
let rectW = 100;
let rectH = 100;
let lightSwitch = false;
function setup() {
createCanvas(400, 400);
rectMode(CENTER);
}
function draw() {
background(220);
noStroke();
if (!lightSwitch){
fill(0);
} else if (lightSwitch) {
background(0, 255, 0);
fill(255, 0, 0); // red
ellipse(width/7,height/2, 100, 100); // place red ellipse on left if lightSwitch is on
fill(255, 255, 0);
}
rect(width/2, height/2, rectW, rectH);
console.log(mouseX, mouseY);
}
function mousePressed(){
if(mouseX>0 && mouseX<width && mouseY>0 && mouseY<height){ // if mouse is on canvas
lightSwitch = !lightSwitch; // flip the boolean
}
}