xxxxxxxxxx
let particles=[];
let amount=800; // will be calculated in setup()
let noiseScale=0.005;
function setup() {
createCanvas(windowWidth, windowHeight);
amount = ~~((width + height) / 2);
background("tan");
noStroke();
fill(32, 32);
for (let i=0;i<amount;i++){
let pos =createVector(random(width),random(height));
particles.push(pos);
}
}
function draw() {
for (let k = 0; k < 5; k++) {
for(let i = particles.length-1; i>=0 ; i--){
let p = particles[i];
circle(p.x, p.y, 1);
let n = noise(p.x*noiseScale, p.y*noiseScale, frameCount/noiseScale);
let a = 2*PI*n;
p.x += sin(a*random(1,1.2));
p.y += cos(a)*map(sin(a/10), -1,1, -0.5,0.5);
//p.y+=cos(a)*0.2
if (!onScreen(p)) {
// particles.splice(i, 1)
p.x = random(width);
p.y = random(height);
}
} // process particles
} // repeat n-times
}
function onScreen(p) {
return p.x < width && p.y < height && p.x > 0 && p.y > 0
}