xxxxxxxxxx
60
// particles falling randomly from the top?
let particles;
let numTotalParticles, numParticlesOnline;
class Particle {
constructor(x,y) {
this.position = createVector(x, y);
this.velocity = createVector(0, random(0.5,2));
}
update() {
// noStroke()
// fill(0);
// circle(this.position.x, this.position.y,2);
this.position.x += this.velocity.x;
this.position.y += this.velocity.y;
}
draw() {
stroke(255);
point(this.position.x, this.position.y);
}
}
function setup() {
numTotalParticles = 10000;
numParticlesOnline = 1000;
particles = [];
createCanvas(400, 400);
background(0);
for (let i = 0; i < numParticlesOnline; i++) {
particles.push(new Particle(random(1,width-1), random(-height,0)));
}
numTotalParticles -= numParticlesOnline;
}
function draw() {
background(0);
loadPixels();
for (let i = particles.length-1; i >= 0; i--) {
particles[i].update();
particles[i].draw();
if (particles[i].position.x < 0 || particles[i].position.x > width || particles[i].position.y > height) {
particles.splice(i, 1);
particles.push(new Particle(random(1,width-1), random(-height,0)));
numTotalParticles--;
}
}
if (numTotalParticles <= 0) {
console.log("done");
noLoop();
}
//background(220);
}