34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
import { Vector, getDistances, isPointInside } from "tsparticles-engine";
|
|
export class DestroyOutMode {
|
|
constructor(container) {
|
|
this.container = container;
|
|
this.modes = ["destroy"];
|
|
}
|
|
update(particle, direction, delta, outMode) {
|
|
if (!this.modes.includes(outMode)) {
|
|
return;
|
|
}
|
|
const container = this.container;
|
|
switch (particle.outType) {
|
|
case "normal":
|
|
case "outside":
|
|
if (isPointInside(particle.position, container.canvas.size, Vector.origin, particle.getRadius(), direction)) {
|
|
return;
|
|
}
|
|
break;
|
|
case "inside": {
|
|
const { dx, dy } = getDistances(particle.position, particle.moveCenter);
|
|
const { x: vx, y: vy } = particle.velocity;
|
|
if ((vx < 0 && dx > particle.moveCenter.radius) ||
|
|
(vy < 0 && dy > particle.moveCenter.radius) ||
|
|
(vx >= 0 && dx < -particle.moveCenter.radius) ||
|
|
(vy >= 0 && dy < -particle.moveCenter.radius)) {
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
container.particles.remove(particle, undefined, true);
|
|
}
|
|
}
|