xxxxxxxxxx
39
let oDiam = 80;
let mDiam = 40;
let x = [80, 210, 355, 45, 380, 240, 170, 320, 80];
let y = [115, 240, 55, 340, 380, 100, 350, 200, 220];
let diameter = [];
function ellipseOverlap(x0, y0, diam0, x1, y1, diam1) {
let d = sqrt((x1 - x0) ** 2 + (y1 - y0) ** 2);
return d < diam0 / 2 + diam1 / 2;
}
function setup() {
createCanvas(windowWidth, windowHeight);
for (let i = 0; i < x.length; i += 1) {
let md = random(oDiam / 2, oDiam);
diameter.push(md);
}
}
function draw() {
background(220, 10, 120);
for (let i = 0; i < x.length; i++) {
let mOverlap = ellipseOverlap(mouseX, mouseY, mDiam, x[i], y[i], diameter[i]);
if (mOverlap) {
fill(255, 190, 90);
} else {
fill(255);
}
ellipse(x[i], y[i], diameter[i]);
}
fill(255);
ellipse(mouseX, mouseY, mDiam);
}