xxxxxxxxxx
26
function setup() {
createCanvas(400, 400);
background(50);
}
function draw() {
// note that the mouse should move in Preview, not the text editing area.
if (checkOutofCanvas(mouseX, mouseY) == true) {
// if mouse position is out of the canvas,
background(50);
} else {
// if mouse position is in the canvas,
background(255, 255, 0);
}
}
function checkOutofCanvas(x, y) {
let value = false;
if (x < 0 || x > width) {
value = true;
}
if (y < 0 || y > height) {
value = true;
}
return value;
}