xxxxxxxxxx
48
// Based off of:
// Particle Systems with Image Textures (Image Texture)
// The Nature of Code
// The Coding Train / Daniel Shiffman
// https://youtu.be/pUhv2CA0omA
// https://thecodingtrain.com/learning/nature-of-code/4.4-image-textures.html
class Particle {
constructor(x, y) {
this.pos = createVector(x, y);
this.vel = p5.Vector.random2D();
this.vel.mult(random(0.5, 2));
this.acc = createVector(0, 0);
this.r = 64;
this.lifetime = 255;
let ran = random(1);
if (ran < 0.75) this.col = 0;
else if (ran < 0.80) this.col = 1;
else this.col = 2
}
finished() {
return this.lifetime < 0;
}
applyForce(force) {
this.acc.add(force);
}
update() {
this.vel.add(this.acc);
this.pos.add(this.vel);
this.acc.set(0, 0);
this.lifetime -= 5;
}
show() {
// tint(150, 40, 80, this.lifetime);
imageMode(CENTER);
let idx = 255-this.lifetime;
if (idx < 0) idx = 0;
image(m_textures[this.col][idx], this.pos.x, this.pos.y, this.r, this.r);
}
}