37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
import { calculateBounds } from "tsparticles-engine";
|
|
import { bounceHorizontal, bounceVertical } from "./Utils";
|
|
export class BounceOutMode {
|
|
constructor(container) {
|
|
this.container = container;
|
|
this.modes = [
|
|
"bounce",
|
|
"bounce-vertical",
|
|
"bounce-horizontal",
|
|
"bounceVertical",
|
|
"bounceHorizontal",
|
|
"split",
|
|
];
|
|
}
|
|
update(particle, direction, delta, outMode) {
|
|
if (!this.modes.includes(outMode)) {
|
|
return;
|
|
}
|
|
const container = this.container;
|
|
let handled = false;
|
|
for (const [, plugin] of container.plugins) {
|
|
if (plugin.particleBounce !== undefined) {
|
|
handled = plugin.particleBounce(particle, delta, direction);
|
|
}
|
|
if (handled) {
|
|
break;
|
|
}
|
|
}
|
|
if (handled) {
|
|
return;
|
|
}
|
|
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
}
|
|
}
|