xxxxxxxxxx
47
let debris = [];
function setup() {
createCanvas(1000, 1000);
stroke(0);
strokeWeight(5);
for (let i = 0; i < 100; i++) {
debris.push(new Debris());
}
}
function draw() {
background(220);
for (let i = 0; i < 100; i++) {
debris[i].show();
debris[i].update();
}
}
function Debris() {
this.pos = createVector(500, 300);
this.vel = p5.Vector.random2D();
this.vel.mult(random(0, 4));
this.acc = createVector(0, 0.15);
this.lifespan = 255
this.show = function() {
stroke(0, this.lifespan);
point(this.pos.x, this.pos.y);
}
this.update = function() {
this.pos.add(this.vel);
this.vel.add(this.acc);
this.lifespan -= 4;
}
}