xxxxxxxxxx
64
function rose(theta, n=5, d=8)
{
let k = n/d
let r = cos(k*theta)
let x = r*cos(theta)
let y = r*sin(theta)
return createVector(x, y)
}
// Daniel Shiffman
// http://codingtra.in
// https://youtu.be/CKeyIbT3vXI
class Particle {
constructor(x, y, hu, firework, index, n, d) {
this.pos = createVector(x, y);
this.firework = firework;
this.lifespan = 255;
this.hu = hu;
this.acc = createVector(0, 0);
if (this.firework) {
this.vel = createVector(0, random(-18, -8));
} else {
this.vel = rose(map(index, 0, 719, 0, TWO_PI*d), n, d);
this.vel.mult(10);
}
}
applyForce(force) {
this.acc.add(force);
}
update() {
if (!this.firework) {
this.vel.mult(0.9);
this.lifespan -= 4;
}
this.vel.add(this.acc);
this.pos.add(this.vel);
this.acc.mult(0);
}
done() {
if (this.lifespan < 0) {
return true;
} else {
return false;
}
}
show() {
colorMode(HSB);
if (!this.firework) {
strokeWeight(2);
stroke(this.hu, 255, 255, this.lifespan);
} else {
strokeWeight(4);
stroke(this.hu, 255, 255);
}
point(this.pos.x, this.pos.y);
}
}