xxxxxxxxxx
46
let rectX = 20;
let rectY = 150;
let rectWidth = 250;
let rectHeight = 50;
let rightEdge = rectX + rectWidth;
let bottomEdge = rectY + rectHeight;
let ellipseDiam = 100;
let ellipseRadius = ellipseDiam / 2;
let oRectX = rectX - ellipseRadius;
let oRectY = rectY - ellipseRadius;
let oRightEdge = rightEdge + ellipseRadius;
let oBottomEdge = bottomEdge + ellipseRadius;
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(220, 10, 120);
noStroke();
let overlap =
mouseX > oRectX &&
mouseX < oRightEdge &&
mouseY > oRectY &&
mouseY < oBottomEdge;
if (overlap) {
fill(0, 190, 255);
} else {
fill(255);
}
rect(rectX, rectY, rectWidth, rectHeight);
if (overlap) {
fill(255, 190, 0);
stroke(0);
} else {
fill(255);
noStroke();
}
ellipse(mouseX, mouseY, ellipseDiam, ellipseDiam);
}