42 lines
1.7 KiB
JavaScript
42 lines
1.7 KiB
JavaScript
import { Vector, isPointInside } from "tsparticles-engine";
|
|
export class NoneOutMode {
|
|
constructor(container) {
|
|
this.container = container;
|
|
this.modes = ["none"];
|
|
}
|
|
update(particle, direction, delta, outMode) {
|
|
if (!this.modes.includes(outMode)) {
|
|
return;
|
|
}
|
|
if ((particle.options.move.distance.horizontal &&
|
|
(direction === "left" || direction === "right")) ||
|
|
(particle.options.move.distance.vertical &&
|
|
(direction === "top" || direction === "bottom"))) {
|
|
return;
|
|
}
|
|
const gravityOptions = particle.options.move.gravity, container = this.container;
|
|
const canvasSize = container.canvas.size;
|
|
const pRadius = particle.getRadius();
|
|
if (!gravityOptions.enable) {
|
|
if ((particle.velocity.y > 0 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
(particle.velocity.y < 0 && particle.position.y >= -pRadius) ||
|
|
(particle.velocity.x > 0 && particle.position.x <= canvasSize.width + pRadius) ||
|
|
(particle.velocity.x < 0 && particle.position.x >= -pRadius)) {
|
|
return;
|
|
}
|
|
if (!isPointInside(particle.position, container.canvas.size, Vector.origin, pRadius, direction)) {
|
|
container.particles.remove(particle);
|
|
}
|
|
}
|
|
else {
|
|
const position = particle.position;
|
|
if ((!gravityOptions.inverse &&
|
|
position.y > canvasSize.height + pRadius &&
|
|
direction === "bottom") ||
|
|
(gravityOptions.inverse && position.y < -pRadius && direction === "top")) {
|
|
container.particles.remove(particle);
|
|
}
|
|
}
|
|
}
|
|
}
|