-
-
Notifications
You must be signed in to change notification settings - Fork 799
/
NoneOutMode.ts
71 lines (62 loc) · 2.33 KB
/
NoneOutMode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
type Container,
type IDelta,
OutMode,
OutModeDirection,
type Particle,
Vector,
isPointInside,
} from "@tsparticles/engine";
import type { IOutModeManager } from "./IOutModeManager.js";
const minVelocity = 0;
export class NoneOutMode implements IOutModeManager {
modes: (OutMode | keyof typeof OutMode)[];
constructor(private readonly container: Container) {
this.modes = [OutMode.none];
}
update(
particle: Particle,
direction: OutModeDirection,
delta: IDelta,
outMode: OutMode | keyof typeof OutMode,
): void {
if (!this.modes.includes(outMode)) {
return;
}
if (
(particle.options.move.distance.horizontal &&
(direction === OutModeDirection.left || direction === OutModeDirection.right)) ??
(particle.options.move.distance.vertical &&
(direction === OutModeDirection.top || direction === OutModeDirection.bottom))
) {
return;
}
const gravityOptions = particle.options.move.gravity,
container = this.container,
canvasSize = container.canvas.size,
pRadius = particle.getRadius();
if (!gravityOptions.enable) {
if (
(particle.velocity.y > minVelocity && particle.position.y <= canvasSize.height + pRadius) ||
(particle.velocity.y < minVelocity && particle.position.y >= -pRadius) ||
(particle.velocity.x > minVelocity && particle.position.x <= canvasSize.width + pRadius) ||
(particle.velocity.x < minVelocity && 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 === OutModeDirection.bottom) ||
(gravityOptions.inverse && position.y < -pRadius && direction === OutModeDirection.top)
) {
container.particles.remove(particle);
}
}
}
}