xxxxxxxxxx
43
let xPos = [];
let yPos = [];
let count = 10;
function setup() {
createCanvas(500, 500);
for (let i = 0; i < count; i++) {
append(xPos, random(0, width));
append(yPos, random(0, width));
}
}
function draw() {
background(220);
noStroke();
for (let i = 0; i < xPos.length; i++) {
if (dist(mouseX, mouseY, xPos[i], yPos[i]) < 62.5) {
fill(255, 0, 0);
} else {
fill(0);
}
circle(xPos[i], yPos[i], 25);
}
noFill();
stroke(150);
circle(mouseX,mouseY,100);
}
function mousePressed() {
xPos = [];
yPos = [];
for (let i = 0; i < count; i++) {
append(xPos, random(0, width));
append(yPos, random(0, width));
}
}