xxxxxxxxxx
/*
Falling Lines
Particles fall and are slown down by air drag that is being driven from a noise field.
jasonlabbe3d.com
twitter.com/russetPotato
*/
var spawnCount = 4;
var noiseScale = 0.01;
var noiseSpeed = 1;
var allParticles = [];
var globalHue = 0;
function setup() {
createCanvas(600, 600);
rectMode(CENTER);
colorMode(HSB, 255);
noStroke();
background(0);
}
function draw() {
background(0, 200);
for (let i = 0; i < spawnCount; i++) {
allParticles.push(new Particle(random(width), -100));
}
for (let i = allParticles.length - 1; i > -1; i--) {
let p = allParticles[i];
p.acc.add(new p5.Vector(0, p.fallRate));
let n = noise(
(frameCount * (noiseSpeed * 2) + p.pos.x) * noiseScale,
(frameCount * noiseSpeed + p.pos.y) * noiseScale);
if (n > 0.5) {
p.vel.mult(p.resistance);
}
p.vel.add(p.acc);
p.pos.add(p.vel);
p.acc.mult(0);
p.angle += p.vel.mag();
fill(p.hue, 200, 255, max(0, 255 - p.vel.mag() * 30));
push();
translate(p.pos.x, p.pos.y);
rotate(radians(p.angle));
rect(0, 0, p.width, max(0, p.height - p.vel.mag() * 10));
pop();
if (p.pos.y > height) {
allParticles.splice(i, 1);
}
}
}