xxxxxxxxxx
67
// based on https://www.youtube.com/watch?v=sZBfLgfsvSk&t=543s&ab_channel=BarneyCodes
let points = [];
const totalPoints = 5000;
let inc = 0.001;
let noiseMultiplier = 0.02;
let direction = "left";
let count = 0;
function setup() {
createCanvas(800, 500);
for (let i = 0; i < totalPoints; i++) {
points.push(createVector(random(width), random(height)));
}
setInterval(otherWay, random(5000, 15000));
}
function draw() {
stroke(255);
background(10, 10, 50, 3);
for (let i = 0; i < totalPoints; i++) {
let p = points[i];
stroke(255);
point(p.x, p.y);
noStroke();
fill(255, 50);
fill(p.x, p.y, p.z * 55);
circle(p.x, p.y, p.z);
let n = noise(p.x * noiseMultiplier, p.y * noiseMultiplier);
let angle = TWO_PI * n;
if (direction === "left") {
p.x += cos(angle)*(cos(angle)*1.5)-inc;
p.y += sin(angle)*(sin(angle))-inc;
p.z += 0.01;
} else if (direction === "right") {
p.x -= cos(angle)*cos(angle)+inc;
p.y -= sin(angle)*(sin(angle)*1.5)+inc;
p.z -= 0.01;
}
if (outOfCanvas(p)) {
p.x = random(width);
p.y = random(height);
}
}
inc += 0.0001;
}
function otherWay() {
count+=0.001;
inc = 0.001;
direction = direction === "left" ? "right" : "left";
noiseSeed(count)
return direction;
}
function outOfCanvas(item) {
return item.x < 0 || item.y < 0 || item.y > height || item.x > width;
}
function mousePressed(){
noiseSeed(random(5000,10000))
}