let a, b, c, d;
let oldx, oldy;
let dA = [];
let n = 1500;
let t = 0;
let playBool = true;
function setup() {
dA = [];
createCanvas(500, 500);
background(20);
oldx = random(50);
oldy = random(50);
a = random(-5, 5);
b = random(-3, 3);
c = random(-5, 5);
d = random(-3, 3);
background(0);
strokeWeight(1);
angleMode(DEGREES);
noStroke();
for (let i = 0; i < n; i++) {
dA.push(new Points(oldx, oldy));
oldx = dA[i].x + random(-5, 5);
oldy = dA[i].y + random(-5, 5);
}
}
function draw() {
if (!playBool) {
frameCount--;
}
t = frameCount / 2;
background(0, 0, 0, 10);
translate(width / 2, height / 2);
rotate(t / 2);
for (let i = 0; i < n; i++) {
dA[i].display();
}
}
function mousePressed() {
setup();
draw();
}
class Points {
constructor(oldx, oldy) {
this.x =
(width / 8) * sin(a * oldx) * sin(b * oldy + 90) +
(width / 8) * sin(d * oldx + 90) * sin(a * oldy);
this.y = (height / 4) * sin(oldy) * cos(oldx);
this.oldx = oldx;
this.oldy = oldy;
this.ts = random(0.9, 1);
this.c = color(100 + 105 * abs(sin(this.x)));
this.c.setAlpha(100);
}
display() {
let th = this.ts * t;
this.x =
(width / 8) * sin(a * this.oldx) * sin(b * this.oldy + 90 + th) +
(width / 8) * sin(d * this.oldx + 90 + th) * sin(a * this.oldy + th);
this.y = (height / 4) * sin(this.oldy + th) * cos(this.oldx + th);
this.c = color(
100 + 105 * sin(this.x + this.x * this.y * sin(t / 2) + this.y)
);
this.c.setAlpha(100);
stroke(this.c);
point(-width / 4 + this.x, -height / 4 + this.y);
this.c.setAlpha(50 * sin(th));
stroke(this.c);
push();
scale(0.5);
point(this.x, this.y);
pop();
push();
this.c.setAlpha(100);
stroke(this.c);
scale(-1, 1);
point(-width / 4 + this.x, -height / 4 + this.y);
this.c.setAlpha(50 * sin(th));
stroke(this.c);
push();
scale(0.5);
point(this.x, this.y);
pop();
pop();
push();
this.c.setAlpha(100);
stroke(this.c);
scale(-1, -1);
point(-width / 4 + this.x, -height / 4 + this.y);
this.c.setAlpha(50 * sin(th));
stroke(this.c);
push();
scale(0.5);
point(this.x, this.y);
pop();
pop();
push();
this.c.setAlpha(100);
stroke(this.c);
scale(1, -1);
point(-width / 4 + this.x, -height / 4 + this.y);
this.c.setAlpha(50 * sin(th));
stroke(this.c);
push();
scale(0.5);
point(this.x, this.y);
pop();
pop();
}
}
function keyPressed() {
playBool = !playBool;
}