xxxxxxxxxx
43
let minDiameter;
let maxDiameter;
let myCircles = [];
let maxNumCircles = 100;
function setup() {
createCanvas(400, 400);
maxDiameter = width / 10;
minDiameter = maxDiameter / 3;
}
function drawCircle(aCircle) {
ellipse(aCircle.x, aCircle.y, aCircle.d, aCircle.d);
}
function draw() {
background(220, 20, 100);
myCircles.forEach(drawCircle);
}
function addCircle() {
let newCircle = {
x: random(width),
y: random(height),
d: random(minDiameter, maxDiameter),
};
myCircles.push(newCircle);
}
function mouseClicked() {
// if more than maxCircles, then clear array
if (myCircles.length >= maxNumCircles) {
myCircles = [];
} else {
let circlesToAdd = random(8, 16);
for (let c = 0; c < circlesToAdd; c++) {
addCircle();
}
}
}