xxxxxxxxxx
20
function setup(){
createCanvas(600, 400);
background(0);
}
function draw(){
rectMode(CENTER);
let distance = dist(mouseX, mouseY, 300, 200); // Calculate distance
// Set color based on the distance
if (distance < 25) {
fill('blue'); // Inside the rectangle, turn blue
} else {
fill('green'); // Outside the rectangle, turn green
}
rect(300, 200, 50, 50); // Draw the rectangle
}