@tsparticles/updater-out-modes
Version:
tsParticles particles out modes updater
33 lines (32 loc) • 1.23 kB
JavaScript
import { OutMode, ParticleOutType, getDistances, } from "@tsparticles/engine";
const minVelocity = 0;
export class DestroyOutMode {
modes;
constructor(_container) {
this.modes = [OutMode.destroy];
}
update(particle, direction, _delta, outMode) {
if (!this.modes.includes(outMode)) {
return;
}
switch (particle.outType) {
case ParticleOutType.normal:
case ParticleOutType.outside:
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
return;
}
break;
case ParticleOutType.inside: {
const { dx, dy } = getDistances(particle.position, particle.moveCenter), { x: vx, y: vy } = particle.velocity;
if ((vx < minVelocity && dx > particle.moveCenter.radius) ||
(vy < minVelocity && dy > particle.moveCenter.radius) ||
(vx >= minVelocity && dx < -particle.moveCenter.radius) ||
(vy >= minVelocity && dy < -particle.moveCenter.radius)) {
return;
}
break;
}
}
particle.destroy(true);
}
}