let n = 500;
let nf = 0.1;
let nf2 = 4000;
let d;
let nArray = [];
let cArray = [];
let t = 0;
let cnt;
let cBool = true;
function setup() {
nf = random(0.0001, 5);
nf2 = random(1, 2000);
console.log(nf, nf2);
cnt = 0;
cnv = createCanvas(windowWidth, windowHeight);
cArray[0] = [];
cArray[1] = [];
cArray[2] = [];
background(0);
d = min(width, height) * 0.9;
i = 0;
while (cnt <= n) {
addCircle(i);
i++;
}
}
function draw() {
translate(width / 2, height / 2);
for (let i = 0; i <= n; i++) {
for (let j = 0; j < 2; j++) {
nArray[i].move();
}
}
if (frameCount > 800) {
noLoop();
}
}
function addCircle(s) {
x = random(-d / 2, d / 2);
y = random(-d / 2, d / 2);
c = 0;
a = dist(x, y, 0, 0);
b = 10000000;
if (a <= d / 2) {
b = (d / 2 - a) * 2;
if (cnt === 0) {
cBool = true;
} else {
for (let i = 0; i < cnt; i++) {
cR = cArray[2][i] / 2;
k = dist(cArray[0][i], cArray[1][i], x, y);
c = 2 * (k - cArray[2][i] / 2);
b = min(b, c);
if (k - cR < 0) {
cBool = false;
}
}
}
} else if (a > d / 2) {
cBool = false;
}
if (cBool) {
cArray[0][cnt] = x;
cArray[1][cnt] = y;
cArray[2][cnt] = b;
nArray.push(new noiseCircle(b / 2, x, y));
cnt++;
}
cBool = true;
}
class noiseCircle {
constructor(r, x, y) {
this.x = x;
this.y = y;
this.p = [];
this.r = r;
this.n = 0;
this.t = 0;
this.np = int(r * 2);
for (let i = 0; i < this.np; i++) {
let theta = random(0, TWO_PI);
this.p[i] = createVector(this.r * sin(theta), this.r * cos(theta));
}
}
move() {
strokeWeight(this.r / 300);
push();
translate(this.x, this.y);
stroke(
100 * sin(this.t / 80),
250 * sin(this.t / 80),
200 * sin(this.t / 80)
);
this.t++;
for (let i = 0; i < this.np; i++) {
this.n = noise(nf * this.p[i].x, nf * this.p[i].y) * nf2;
this.p[i].add(
cos(this.n) * sin(this.n / 2),
sin(this.n) * cos(this.n / 2)
);
point(this.p[i].x, this.p[i].y);
}
pop();
}
}
function keyPressed() {
if (keyCode === 32) {
cArray = [];
nArray = [];
t = 0;
cnt = 0;
cBool = true;
frameCount = 0;
setup();
loop();
draw();
}
}