class BurnParticle {
constructor(p5, position) {
this.p5 = p5;
this.acceleration = this.p5.createVector(0, 0.03);
this.velocity = this.p5.createVector(this.p5.random(-1, 1), this.p5.random(-5, -5));
this.position = position.copy();
this.lifespan = 255 * 0.6;
let cycleBurnRate = fetchCycleBurnRateForImage.valueNow;
let cycleBurnTrillion = cycleBurnRate / 1000000000000;
let icpBurn = cycleBurnTrillion / icpXdrRate;
if (toggleIcp) {
this.particleInterval = 1000 / icpBurn;
} else {
this.particleInterval = 1000 / cycleBurnTrillion;
}
this.lastParticleTime = 0;
}
run() {
this.update();
this.display();
this.generateParticles();
}
generateParticles() {
let currentTime = this.p5.millis();
if (currentTime - this.lastParticleTime > this.particleInterval) {
this.lastParticleTime = currentTime;
return new BurnParticle(this.p5, this.position);
}
return null;
}
update() {
this.velocity.add(this.acceleration);
this.position.add(this.velocity);
this.lifespan -= 1;
}
display() {
this.p5.stroke(200, this.lifespan);
this.p5.strokeWeight(2);
this.p5.fill(225,25,25, this.lifespan);
this.p5.ellipse(this.position.x, this.position.y, 16, 16);
}
isDead() {
return this.lifespan < 0;
}
}