xxxxxxxxxx
40
let oDiam = 80;
let mDiam = 40;
let x = [];
let y = [];
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 < 8; i++) {
let mx = random(width);
let my = random(height);
x.push(mx);
y.push(my);
}
}
function draw() {
background(220, 10, 120);
for (let i = 0; i < x.length; i++) {
let mOverlap = ellipseOverlap(mouseX, mouseY, mDiam, x[i], y[i], oDiam);
if (mOverlap) {
fill(255, 190, 90);
} else {
fill(255);
}
ellipse(x[i], y[i], oDiam);
}
fill(255);
ellipse(mouseX, mouseY, mDiam);
}