xxxxxxxxxx
28
let isOn = false; //default to be off
let hover = true; //mouse to hover over rectangle
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
//condition for mouse to be over rectangle
if(mouseX>width/2){
if(hover){
hover = false;
isOn = !isOn;
}
} else {
hover = true;
}
if (isOn){
fill ('red')
} else {
fill ('black')
}
rect(width/2,0,width/2,height)
}