xxxxxxxxxx
61
class Particle {
constructor(x, y, firework, monocolorFirework, red, green, blue, multicolorFirework) {
this.pos = createVector(x, y);
this.size = 2.4;
this.gravity = createVector(0, 0.2);
this.firework = firework;
this.lifespan = 255;
if(!this.firework) {
this.vel = createVector(0, random(-11, -15));
this.gravity = createVector(0, 0.2);
this.red = random(255);
this.green = random(255);
this.blue = random(255);
} else {
this.randomAngle = random(1, 361);
this.randomRadius = random(11);
this.vel = createVector(cos(this.randomAngle) * this.randomRadius, sin(this.randomAngle) * this.randomRadius);
this.gravity = createVector(0, 0.27);
if(monocolorFirework || !multicolorFirework) {
this.red = red;
this.green = green;
this.blue = blue;
} else {
this.red = random(255);
this.blue = random(255);
this.green = random(255);
}
}
this.accel = createVector(0, 0);
}
applyForce(force) {
this.accel.add(force);
}
update() {
if(this.firework) {
this.lifespan -= 3.8;
}
this.pos.add(this.vel);
this.vel.add(this.accel);
this.accel.mult(0);
}
render() {
strokeWeight(this.size);
if(!this.firework) {
stroke(this.red, this.green, this.blue);
} else {
stroke(this.red, this.green, this.blue, this.lifespan);
}
point(this.pos.x, this.pos.y);
}
}