let circles = [];
let nCircles = 7000;
function setup() {
cnv = createCanvas(windowWidth, windowHeight);
circles = [];
rectMode(CENTER);
nRot = int(random(1, 10));
if (nRot === 4) {
nRot = 3;
}
r = random(50, 100);
g = random(50, 100);
b = random(50, 100);
noStroke();
circles[0] = { r: random(width / 10, width / 8), x: 0, y: 0, pr: 0, pa: 0 };
background(r, g, b);
angleMode(DEGREES);
cnt = 0;
for (let j = 0; j < nCircles; j++) {
x1 = random(-width / 2, width / 2);
y1 = random(-height / 2, height / 2);
minD = 10000000;
n = -1000;
inCirc = false;
for (let i = 0; i < circles.length; i++) {
d = dist(x1, y1, circles[i].x, circles[i].y);
if (d > circles[i].r && minD > d - circles[i].r) {
n = i;
minD = d - circles[i].r;
}
if (d <= circles[i].r) {
inCirc = true;
}
}
if (!inCirc && n >= 0) {
circles[cnt] = {
r: min(minD, width / 5),
x: x1,
y: y1,
pr: 0,
pa: random(0, 360)
};
cnt++;
}
}
fill(r + 100, g + 100, b + 100);
}
function draw() {
translate(width / 2, height / 2);
for (let i = 0; i < circles.length; i++) {
if (
dist(
circles[i].x + circles[i].pr * cos(circles[i].pa),
circles[i].y + circles[i].pr * sin(circles[i].pa),
circles[i].x,
circles[i].y
) < circles[i].r
)
circles[i].pr += randomGaussian(0.05, 0.1);
circles[i].pa += random(-1, 2);
push();
translate(circles[i].x, circles[i].y);
for (let k = 0; k < nRot; k++) {
circle(
circles[i].pr * cos(circles[i].pa + (k * 360) / nRot),
circles[i].pr * sin(circles[i].pa + (k * 360) / nRot),
random(0.1, 1)
);
}
pop();
}
}
function mousePressed() {
frameCount = 0;
setup();
draw();
}
function keyPressed() {
save(cnv, "packed", "png");
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}