xxxxxxxxxx
37
let buttonDown = false;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
rect(150, 150, 100, 100);
if (mouseX > 150 && mouseX < 250 && mouseY > 150 && mouseY < 250)
{
fill(120)
}else{
fill(250)
}
}
function mousePressed() {
if (
mouseX > 150 &&
mouseX < 250 &&
mouseY > 150 &&
mouseY < 250 &&
buttonDown == true
) {
fill(225);
buttonDown = false;
} else if (
mouseX > 150 &&
mouseX < 250 &&
mouseY > 150 &&
mouseY < 250 &&
buttonDown == false
) {
fill(0);
buttonDown = true;
}
}