let r, n;
let playB = true;
let Carray = [];
let c = true;
let t = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
r = min(width, height) / 1.2;
Carray[0] = [];
Carray[1] = [];
Carray[2] = [];
}
function draw() {
translate(width / 2, height / 2);
rotate(width);
n = int(width / 3);
if (playB) {
background(0);
for (let i = 0; i < 40; i++) {
push();
Carray[2][i] = randomGaussian(-1, 1);
g = min(width / 3, height / 3);
translate((sin(Carray[2][i]) * g) / 5, (cos(Carray[2][i]) * g) / 5);
plight(i);
pop();
}
}
playB = false;
if (c) {
t += 0.001;
gmove();
}
}
function plight(z) {
Carray[0][z] = [];
Carray[1][z] = [];
for (let i = 0; i < n; i++) {
Carray[0][z][i] = randomGaussian(0.8, 0.9);
Carray[1][z][i] = randomGaussian(0, 0.2);
stroke(cos(Carray[1][i]) * 255);
point(
r * sin(Carray[0][z][i]) * sin(Carray[1][z][i]),
r * cos(Carray[0][z][i]) * sin(Carray[1][z][i])
);
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
playB = true;
}
function mousePressed() {
c = !c;
}
function gmove() {
background(0);
for (let z = 0; z < 40; z++) {
push();
g = min(width / 3, height / 3);
translate((sin(Carray[2][z] + t) * g) / 5, (cos(Carray[2][z] + t) * g) / 5);
for (let i = 0; i < n; i++) {
stroke(abs(cos(Carray[1][z][i])) * 255);
point(
r * sin(Carray[0][z][i] + t) * sin(Carray[1][z][i] + t),
r * cos(Carray[0][z][i] + t) * sin(Carray[1][z][i] + t)
);
}
pop();
}
}