p5(sketch => {
let lightIsOn = 0;
function testIsInside(x, y) {
const answer = x > 250 && x < 350 && y > 150 && y < 250;
return answer;
}
sketch.setup = function() {
sketch.createCanvas(600, 400);
};
sketch.draw = function() {
lightIsOn ? sketch.background(0, 255, 0) : sketch.background(0);
sketch.noStroke();
sketch.fill(255);
if (testIsInside(sketch.mouseX, sketch.mouseY)) {
sketch.fill(255, 0, 200);
}
sketch.rectMode(sketch.CENTER);
sketch.rect(300, 200, 100);
};
sketch.mousePressed = function() {
if (testIsInside(sketch.mouseX, sketch.mouseY)) {
lightIsOn = !lightIsOn;
}
};
})