custom-pixi-particles 7.1.1 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/dist/index.d.ts +15 -0
  2. package/dist/index.js +45 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/lib/Model.d.ts +32 -0
  5. package/dist/lib/Model.js +44 -0
  6. package/dist/lib/Model.js.map +1 -0
  7. package/dist/lib/Particle.d.ts +234 -0
  8. package/dist/lib/Particle.js +201 -0
  9. package/dist/lib/Particle.js.map +1 -0
  10. package/dist/lib/ParticlePool.d.ts +37 -0
  11. package/dist/lib/ParticlePool.js +56 -0
  12. package/dist/lib/ParticlePool.js.map +1 -0
  13. package/dist/lib/behaviour/AngularVelocityBehaviour.d.ts +61 -0
  14. package/dist/lib/behaviour/AngularVelocityBehaviour.js +118 -0
  15. package/dist/lib/behaviour/AngularVelocityBehaviour.js.map +1 -0
  16. package/dist/lib/behaviour/AttractionRepulsionBehaviour.d.ts +42 -0
  17. package/dist/lib/behaviour/AttractionRepulsionBehaviour.js +78 -0
  18. package/dist/lib/behaviour/AttractionRepulsionBehaviour.js.map +1 -0
  19. package/dist/lib/behaviour/Behaviour.d.ts +33 -0
  20. package/dist/lib/behaviour/Behaviour.js +45 -0
  21. package/dist/lib/behaviour/Behaviour.js.map +1 -0
  22. package/dist/lib/behaviour/BehaviourNames.d.ts +22 -0
  23. package/dist/lib/behaviour/BehaviourNames.js +23 -0
  24. package/dist/lib/behaviour/BehaviourNames.js.map +1 -0
  25. package/dist/lib/behaviour/CollisionBehaviour.d.ts +81 -0
  26. package/dist/lib/behaviour/CollisionBehaviour.js +136 -0
  27. package/dist/lib/behaviour/CollisionBehaviour.js.map +1 -0
  28. package/dist/lib/behaviour/ColorBehaviour.d.ts +67 -0
  29. package/dist/lib/behaviour/ColorBehaviour.js +209 -0
  30. package/dist/lib/behaviour/ColorBehaviour.js.map +1 -0
  31. package/dist/lib/behaviour/EmitDirectionBehaviour.d.ts +52 -0
  32. package/dist/lib/behaviour/EmitDirectionBehaviour.js +105 -0
  33. package/dist/lib/behaviour/EmitDirectionBehaviour.js.map +1 -0
  34. package/dist/lib/behaviour/EmitterBehaviours.d.ts +69 -0
  35. package/dist/lib/behaviour/EmitterBehaviours.js +116 -0
  36. package/dist/lib/behaviour/EmitterBehaviours.js.map +1 -0
  37. package/dist/lib/behaviour/ForceFieldsBehaviour.d.ts +53 -0
  38. package/dist/lib/behaviour/ForceFieldsBehaviour.js +80 -0
  39. package/dist/lib/behaviour/ForceFieldsBehaviour.js.map +1 -0
  40. package/dist/lib/behaviour/GroupingBehaviour.d.ts +57 -0
  41. package/dist/lib/behaviour/GroupingBehaviour.js +143 -0
  42. package/dist/lib/behaviour/GroupingBehaviour.js.map +1 -0
  43. package/dist/lib/behaviour/LifeBehaviour.d.ts +47 -0
  44. package/dist/lib/behaviour/LifeBehaviour.js +65 -0
  45. package/dist/lib/behaviour/LifeBehaviour.js.map +1 -0
  46. package/dist/lib/behaviour/LightEffectBehaviour.d.ts +59 -0
  47. package/dist/lib/behaviour/LightEffectBehaviour.js +94 -0
  48. package/dist/lib/behaviour/LightEffectBehaviour.js.map +1 -0
  49. package/dist/lib/behaviour/NoiseBasedMotionBehaviour.d.ts +28 -0
  50. package/dist/lib/behaviour/NoiseBasedMotionBehaviour.js +50 -0
  51. package/dist/lib/behaviour/NoiseBasedMotionBehaviour.js.map +1 -0
  52. package/dist/lib/behaviour/PositionBehaviour.d.ts +164 -0
  53. package/dist/lib/behaviour/PositionBehaviour.js +484 -0
  54. package/dist/lib/behaviour/PositionBehaviour.js.map +1 -0
  55. package/dist/lib/behaviour/RotationBehaviour.d.ts +59 -0
  56. package/dist/lib/behaviour/RotationBehaviour.js +100 -0
  57. package/dist/lib/behaviour/RotationBehaviour.js.map +1 -0
  58. package/dist/lib/behaviour/SizeBehaviour.d.ts +61 -0
  59. package/dist/lib/behaviour/SizeBehaviour.js +156 -0
  60. package/dist/lib/behaviour/SizeBehaviour.js.map +1 -0
  61. package/dist/lib/behaviour/SoundReactiveBehaviour.d.ts +58 -0
  62. package/dist/lib/behaviour/SoundReactiveBehaviour.js +132 -0
  63. package/dist/lib/behaviour/SoundReactiveBehaviour.js.map +1 -0
  64. package/dist/lib/behaviour/SpawnBehaviour.d.ts +89 -0
  65. package/dist/lib/behaviour/SpawnBehaviour.js +705 -0
  66. package/dist/lib/behaviour/SpawnBehaviour.js.map +1 -0
  67. package/dist/lib/behaviour/StretchBehaviour.d.ts +30 -0
  68. package/dist/lib/behaviour/StretchBehaviour.js +59 -0
  69. package/dist/lib/behaviour/StretchBehaviour.js.map +1 -0
  70. package/dist/lib/behaviour/TemperatureBehaviour.d.ts +47 -0
  71. package/dist/lib/behaviour/TemperatureBehaviour.js +64 -0
  72. package/dist/lib/behaviour/TemperatureBehaviour.js.map +1 -0
  73. package/dist/lib/behaviour/TimelineBehaviour.d.ts +73 -0
  74. package/dist/lib/behaviour/TimelineBehaviour.js +100 -0
  75. package/dist/lib/behaviour/TimelineBehaviour.js.map +1 -0
  76. package/dist/lib/behaviour/TurbulenceBehaviour.d.ts +73 -0
  77. package/dist/lib/behaviour/TurbulenceBehaviour.js +133 -0
  78. package/dist/lib/behaviour/TurbulenceBehaviour.js.map +1 -0
  79. package/dist/lib/behaviour/index.d.ts +23 -0
  80. package/dist/lib/behaviour/index.js +24 -0
  81. package/dist/lib/behaviour/index.js.map +1 -0
  82. package/dist/lib/customPixiParticlesSettingsInterface.d.ts +19 -0
  83. package/dist/lib/customPixiParticlesSettingsInterface.js +2 -0
  84. package/dist/lib/customPixiParticlesSettingsInterface.js.map +1 -0
  85. package/dist/lib/emission/AbstractEmission.d.ts +30 -0
  86. package/dist/lib/emission/AbstractEmission.js +39 -0
  87. package/dist/lib/emission/AbstractEmission.js.map +1 -0
  88. package/dist/lib/emission/EmissionTypes.d.ts +6 -0
  89. package/dist/lib/emission/EmissionTypes.js +6 -0
  90. package/dist/lib/emission/EmissionTypes.js.map +1 -0
  91. package/dist/lib/emission/RandomEmission.d.ts +44 -0
  92. package/dist/lib/emission/RandomEmission.js +66 -0
  93. package/dist/lib/emission/RandomEmission.js.map +1 -0
  94. package/dist/lib/emission/StandardEmission.d.ts +62 -0
  95. package/dist/lib/emission/StandardEmission.js +87 -0
  96. package/dist/lib/emission/StandardEmission.js.map +1 -0
  97. package/dist/lib/emission/UniformEmission.d.ts +56 -0
  98. package/dist/lib/emission/UniformEmission.js +83 -0
  99. package/dist/lib/emission/UniformEmission.js.map +1 -0
  100. package/dist/lib/emission/index.d.ts +6 -0
  101. package/dist/lib/emission/index.js +7 -0
  102. package/dist/lib/emission/index.js.map +1 -0
  103. package/dist/lib/emitter/Duration.d.ts +27 -0
  104. package/dist/lib/emitter/Duration.js +41 -0
  105. package/dist/lib/emitter/Duration.js.map +1 -0
  106. package/dist/lib/emitter/Emitter.d.ts +116 -0
  107. package/dist/lib/emitter/Emitter.js +240 -0
  108. package/dist/lib/emitter/Emitter.js.map +1 -0
  109. package/dist/lib/emitter/index.d.ts +3 -0
  110. package/dist/lib/emitter/index.js +4 -0
  111. package/dist/lib/emitter/index.js.map +1 -0
  112. package/dist/lib/index.d.ts +20 -0
  113. package/dist/lib/index.js +21 -0
  114. package/dist/lib/index.js.map +1 -0
  115. package/dist/lib/parser/BehaviourParser.d.ts +21 -0
  116. package/dist/lib/parser/BehaviourParser.js +72 -0
  117. package/dist/lib/parser/BehaviourParser.js.map +1 -0
  118. package/dist/lib/parser/CompatibilityHelper.d.ts +12 -0
  119. package/dist/lib/parser/CompatibilityHelper.js +19 -0
  120. package/dist/lib/parser/CompatibilityHelper.js.map +1 -0
  121. package/dist/lib/parser/EmitControllerParser.d.ts +27 -0
  122. package/dist/lib/parser/EmitControllerParser.js +39 -0
  123. package/dist/lib/parser/EmitControllerParser.js.map +1 -0
  124. package/dist/lib/parser/EmitterParser.d.ts +67 -0
  125. package/dist/lib/parser/EmitterParser.js +168 -0
  126. package/dist/lib/parser/EmitterParser.js.map +1 -0
  127. package/dist/lib/parser/index.d.ts +5 -0
  128. package/dist/lib/parser/index.js +6 -0
  129. package/dist/lib/parser/index.js.map +1 -0
  130. package/dist/lib/pixi/Renderer.d.ts +125 -0
  131. package/dist/lib/pixi/Renderer.js +566 -0
  132. package/dist/lib/pixi/Renderer.js.map +1 -0
  133. package/dist/lib/pixi/TestRenderer.d.ts +125 -0
  134. package/dist/lib/pixi/TestRenderer.js +560 -0
  135. package/dist/lib/pixi/TestRenderer.js.map +1 -0
  136. package/dist/lib/util/Color.d.ts +133 -0
  137. package/dist/lib/util/Color.js +173 -0
  138. package/dist/lib/util/Color.js.map +1 -0
  139. package/dist/lib/util/List.d.ts +49 -0
  140. package/dist/lib/util/List.js +87 -0
  141. package/dist/lib/util/List.js.map +1 -0
  142. package/dist/lib/util/MinMax.d.ts +34 -0
  143. package/dist/lib/util/MinMax.js +46 -0
  144. package/dist/lib/util/MinMax.js.map +1 -0
  145. package/dist/lib/util/Point.d.ts +34 -0
  146. package/dist/lib/util/Point.js +46 -0
  147. package/dist/lib/util/Point.js.map +1 -0
  148. package/dist/lib/util/Random.d.ts +24 -0
  149. package/dist/lib/util/Random.js +30 -0
  150. package/dist/lib/util/Random.js.map +1 -0
  151. package/dist/lib/util/ThereBack.d.ts +14 -0
  152. package/dist/lib/util/ThereBack.js +23 -0
  153. package/dist/lib/util/ThereBack.js.map +1 -0
  154. package/dist/lib/util/index.d.ts +5 -0
  155. package/dist/lib/util/index.js +6 -0
  156. package/dist/lib/util/index.js.map +1 -0
  157. package/dist/lib/util/maths.d.ts +10 -0
  158. package/dist/lib/util/maths.js +13 -0
  159. package/dist/lib/util/maths.js.map +1 -0
  160. package/dist/lib/util/turbulencePool.d.ts +4 -0
  161. package/dist/lib/util/turbulencePool.js +7 -0
  162. package/dist/lib/util/turbulencePool.js.map +1 -0
  163. package/package.json +1 -1
@@ -0,0 +1,53 @@
1
+ import { Behaviour } from './index';
2
+ import Particle from '../Particle';
3
+ import { Point } from '../util';
4
+ /**
5
+ * ForceFieldsBehaviour applies region-based forces (wind, gravity, turbulence) to particles.
6
+ * @extends Behaviour
7
+ */
8
+ export default class ForceFieldsBehaviour extends Behaviour {
9
+ enabled: boolean;
10
+ priority: number;
11
+ /**
12
+ * List of force fields
13
+ */
14
+ fields: {
15
+ position: Point;
16
+ radius: number;
17
+ strength: number;
18
+ type: 'wind' | 'gravity' | 'turbulence';
19
+ direction?: Point;
20
+ }[];
21
+ /**
22
+ * Initializes the particle, but does not modify position directly.
23
+ * @param {Particle} particle - The particle to initialize.
24
+ */
25
+ init: (particle: Particle) => void;
26
+ /**
27
+ * Applies the force field behavior to particles.
28
+ * @param {Particle} particle - The particle to apply the behavior to.
29
+ * @param {number} deltaTime - Time elapsed since the last frame.
30
+ */
31
+ apply: (particle: Particle, deltaTime: number) => void;
32
+ /**
33
+ * Gets the name of the behaviour.
34
+ * @returns {string} - The name of the behaviour.
35
+ */
36
+ getName(): string;
37
+ /**
38
+ * Gets the properties of the behaviour.
39
+ * @returns {object} - The properties of the behaviour.
40
+ */
41
+ getProps(): {
42
+ enabled: boolean;
43
+ priority: number;
44
+ fields: {
45
+ position: Point;
46
+ radius: number;
47
+ strength: number;
48
+ type: "wind" | "gravity" | "turbulence";
49
+ direction?: Point;
50
+ }[];
51
+ name: string;
52
+ };
53
+ }
@@ -0,0 +1,80 @@
1
+ import { Behaviour, BehaviourNames } from './index';
2
+ /**
3
+ * ForceFieldsBehaviour applies region-based forces (wind, gravity, turbulence) to particles.
4
+ * @extends Behaviour
5
+ */
6
+ export default class ForceFieldsBehaviour extends Behaviour {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.enabled = true;
10
+ this.priority = 300; // Executes after initial movement behaviors
11
+ /**
12
+ * List of force fields
13
+ */
14
+ this.fields = [];
15
+ /**
16
+ * Initializes the particle, but does not modify position directly.
17
+ * @param {Particle} particle - The particle to initialize.
18
+ */
19
+ this.init = (particle) => {
20
+ // Initialization logic if needed.
21
+ };
22
+ /**
23
+ * Applies the force field behavior to particles.
24
+ * @param {Particle} particle - The particle to apply the behavior to.
25
+ * @param {number} deltaTime - Time elapsed since the last frame.
26
+ */
27
+ this.apply = (particle, deltaTime) => {
28
+ if (!this.enabled || particle.skipPositionBehaviour)
29
+ return;
30
+ this.fields.forEach((field) => {
31
+ const distance = Math.sqrt(Math.pow((particle.x - field.position.x), 2) + Math.pow((particle.y - field.position.y), 2));
32
+ // Check if the particle is within the field's radius
33
+ if (distance <= field.radius) {
34
+ const influence = (field.radius - distance) / field.radius; // Influence factor (closer = stronger)
35
+ switch (field.type) {
36
+ case 'wind':
37
+ if (field.direction) {
38
+ particle.movement.x += field.direction.x * field.strength * influence * deltaTime;
39
+ particle.movement.y += field.direction.y * field.strength * influence * deltaTime;
40
+ }
41
+ break;
42
+ case 'gravity':
43
+ const dx = field.position.x - particle.x;
44
+ const dy = field.position.y - particle.y;
45
+ const angle = Math.atan2(dy, dx);
46
+ particle.movement.x += Math.cos(angle) * field.strength * influence * deltaTime;
47
+ particle.movement.y += Math.sin(angle) * field.strength * influence * deltaTime;
48
+ break;
49
+ case 'turbulence':
50
+ const randomForceX = (Math.random() - 0.5) * 2 * field.strength * influence;
51
+ const randomForceY = (Math.random() - 0.5) * 2 * field.strength * influence;
52
+ particle.movement.x += randomForceX * deltaTime;
53
+ particle.movement.y += randomForceY * deltaTime;
54
+ break;
55
+ }
56
+ }
57
+ });
58
+ };
59
+ }
60
+ /**
61
+ * Gets the name of the behaviour.
62
+ * @returns {string} - The name of the behaviour.
63
+ */
64
+ getName() {
65
+ return BehaviourNames.FORCE_FIELDS_BEHAVIOUR;
66
+ }
67
+ /**
68
+ * Gets the properties of the behaviour.
69
+ * @returns {object} - The properties of the behaviour.
70
+ */
71
+ getProps() {
72
+ return {
73
+ enabled: this.enabled,
74
+ priority: this.priority,
75
+ fields: this.fields,
76
+ name: this.getName(),
77
+ };
78
+ }
79
+ }
80
+ //# sourceMappingURL=ForceFieldsBehaviour.js.map
@@ -0,0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AAG,SAAS,CAAA;4BAC/C,MAAK;oBACT,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAA;IAsBH,CAAC;IApBC;;;OAGG;IACH,OAAO;QACL,OAAO,cAAc,CAAC,sBAAsB,CAAA;IAC9C,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,57 @@
1
+ import { Point } from '../util';
2
+ import { Behaviour } from './index';
3
+ import Particle from '../Particle';
4
+ export default class GroupingBehaviour extends Behaviour {
5
+ enabled: boolean;
6
+ priority: number;
7
+ groupCenter: Point;
8
+ groupRadius: number;
9
+ attractionStrength: number;
10
+ repulsionStrength: number;
11
+ orbitSpeed: number;
12
+ randomness: number;
13
+ boundaryEnforcement: boolean;
14
+ dynamicRadiusSpeed: number;
15
+ maxRadius: number;
16
+ minRadius: number;
17
+ clusterPoints: Point[];
18
+ private particleAngles;
19
+ init(particle: Particle): void;
20
+ apply(particle: Particle, deltaTime: number): void;
21
+ /**
22
+ * Adjusts the group radius dynamically over time
23
+ */
24
+ adjustDynamicRadius(deltaTime: number): void;
25
+ /**
26
+ * Applies repulsion forces to keep particles apart
27
+ */
28
+ applyRepulsion(particle: Particle): void;
29
+ /**
30
+ * Enforces boundary limits to keep particles within the group radius
31
+ */
32
+ enforceBoundary(particle: Particle): void;
33
+ /**
34
+ * Finds the nearest cluster point to a given position
35
+ */
36
+ getNearestClusterPoint(position: Point): Point;
37
+ getName(): string;
38
+ getProps(): {
39
+ enabled: boolean;
40
+ priority: number;
41
+ groupCenter: {
42
+ x: number;
43
+ y: number;
44
+ };
45
+ groupRadius: number;
46
+ attractionStrength: number;
47
+ repulsionStrength: number;
48
+ orbitSpeed: number;
49
+ randomness: number;
50
+ boundaryEnforcement: boolean;
51
+ dynamicRadiusSpeed: number;
52
+ maxRadius: number;
53
+ minRadius: number;
54
+ clusterPoints: Point[];
55
+ name: string;
56
+ };
57
+ }
@@ -0,0 +1,143 @@
1
+ import { Point } from '../util';
2
+ import { Behaviour, BehaviourNames } from './index';
3
+ export default class GroupingBehaviour extends Behaviour {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.enabled = true;
7
+ this.priority = 0;
8
+ this.groupCenter = new Point(0, 0); // Shared center for the group
9
+ this.groupRadius = 100; // Radius of the group
10
+ this.attractionStrength = 0.1; // Strength of attraction toward the group center
11
+ this.repulsionStrength = 0; // Strength of repulsion between particles
12
+ this.orbitSpeed = 0; // Speed of orbiting (0 for no orbit)
13
+ this.randomness = 0.2; // Adds randomness to particle movement
14
+ this.boundaryEnforcement = false; // Enforce group boundary limits
15
+ this.dynamicRadiusSpeed = 0; // Speed for dynamic radius scaling
16
+ this.maxRadius = 150; // Maximum radius for dynamic scaling
17
+ this.minRadius = 50; // Minimum radius for dynamic scaling
18
+ this.clusterPoints = []; // Additional cluster points
19
+ this.particleAngles = new Map(); // Store unique angles for each particle
20
+ }
21
+ init(particle) {
22
+ if (!this.enabled)
23
+ return;
24
+ // Assign each particle an initial random angle within the group
25
+ const initialAngle = Math.random() * Math.PI * 2;
26
+ this.particleAngles.set(particle.uid, initialAngle);
27
+ }
28
+ apply(particle, deltaTime) {
29
+ if (!this.enabled)
30
+ return;
31
+ const angle = this.particleAngles.get(particle.uid) || 0;
32
+ // Calculate vector toward the group center or nearest cluster point
33
+ const targetPoint = this.getNearestClusterPoint(particle.movement);
34
+ const dx = targetPoint.x - particle.movement.x;
35
+ const dy = targetPoint.y - particle.movement.y;
36
+ const distance = Math.sqrt(dx * dx + dy * dy);
37
+ // Apply attraction toward the target point
38
+ particle.movement.x += dx * this.attractionStrength * deltaTime;
39
+ particle.movement.y += dy * this.attractionStrength * deltaTime;
40
+ // Apply orbiting behavior if enabled
41
+ if (this.orbitSpeed !== 0) {
42
+ const currentAngle = angle + this.orbitSpeed * deltaTime;
43
+ this.particleAngles.set(particle.uid, currentAngle);
44
+ particle.movement.x = targetPoint.x + Math.cos(currentAngle) * Math.min(distance, this.groupRadius);
45
+ particle.movement.y = targetPoint.y + Math.sin(currentAngle) * Math.min(distance, this.groupRadius);
46
+ }
47
+ // Apply repulsion from other particles
48
+ this.applyRepulsion(particle);
49
+ // Add randomness for natural movement
50
+ particle.movement.x += (Math.random() - 0.5) * this.randomness;
51
+ particle.movement.y += (Math.random() - 0.5) * this.randomness;
52
+ // Enforce group boundary limits if enabled
53
+ if (this.boundaryEnforcement) {
54
+ this.enforceBoundary(particle);
55
+ }
56
+ // Dynamically adjust the group radius
57
+ this.adjustDynamicRadius(deltaTime);
58
+ }
59
+ /**
60
+ * Adjusts the group radius dynamically over time
61
+ */
62
+ adjustDynamicRadius(deltaTime) {
63
+ if (this.dynamicRadiusSpeed !== 0) {
64
+ this.groupRadius += this.dynamicRadiusSpeed * deltaTime;
65
+ if (this.groupRadius > this.maxRadius || this.groupRadius < this.minRadius) {
66
+ this.dynamicRadiusSpeed *= -1; // Reverse direction
67
+ }
68
+ this.groupRadius = Math.max(this.minRadius, Math.min(this.groupRadius, this.maxRadius));
69
+ }
70
+ }
71
+ /**
72
+ * Applies repulsion forces to keep particles apart
73
+ */
74
+ applyRepulsion(particle) {
75
+ if (this.repulsionStrength === 0)
76
+ return;
77
+ this.clusterPoints.forEach((point) => {
78
+ const dx = point.x - particle.movement.x;
79
+ const dy = point.y - particle.movement.y;
80
+ const distance = Math.sqrt(dx * dx + dy * dy);
81
+ if (distance > 0 && distance < this.groupRadius) {
82
+ const force = Math.pow((this.repulsionStrength / distance), 2);
83
+ particle.movement.x -= dx * force;
84
+ particle.movement.y -= dy * force;
85
+ }
86
+ });
87
+ }
88
+ /**
89
+ * Enforces boundary limits to keep particles within the group radius
90
+ */
91
+ enforceBoundary(particle) {
92
+ const dx = particle.movement.x - this.groupCenter.x;
93
+ const dy = particle.movement.y - this.groupCenter.y;
94
+ const distance = Math.sqrt(dx * dx + dy * dy);
95
+ if (distance > this.groupRadius) {
96
+ const angle = Math.atan2(dy, dx);
97
+ particle.movement.x = this.groupCenter.x + Math.cos(angle) * this.groupRadius;
98
+ particle.movement.y = this.groupCenter.y + Math.sin(angle) * this.groupRadius;
99
+ }
100
+ }
101
+ /**
102
+ * Finds the nearest cluster point to a given position
103
+ */
104
+ getNearestClusterPoint(position) {
105
+ if (this.clusterPoints.length === 0) {
106
+ return this.groupCenter;
107
+ }
108
+ let nearest = this.groupCenter;
109
+ let minDistance = Infinity;
110
+ for (const point of this.clusterPoints) {
111
+ const dx = point.x - position.x;
112
+ const dy = point.y - position.y;
113
+ const distance = Math.sqrt(dx * dx + dy * dy);
114
+ if (distance < minDistance) {
115
+ minDistance = distance;
116
+ nearest = point;
117
+ }
118
+ }
119
+ return nearest;
120
+ }
121
+ getName() {
122
+ return BehaviourNames.GROUPING_BEHAVIOUR;
123
+ }
124
+ getProps() {
125
+ return {
126
+ enabled: this.enabled,
127
+ priority: this.priority,
128
+ groupCenter: { x: this.groupCenter.x, y: this.groupCenter.y },
129
+ groupRadius: this.groupRadius,
130
+ attractionStrength: this.attractionStrength,
131
+ repulsionStrength: this.repulsionStrength,
132
+ orbitSpeed: this.orbitSpeed,
133
+ randomness: this.randomness,
134
+ boundaryEnforcement: this.boundaryEnforcement,
135
+ dynamicRadiusSpeed: this.dynamicRadiusSpeed,
136
+ maxRadius: this.maxRadius,
137
+ minRadius: this.minRadius,
138
+ clusterPoints: this.clusterPoints,
139
+ name: this.getName(),
140
+ };
141
+ }
142
+ }
143
+ //# sourceMappingURL=GroupingBehaviour.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GroupingBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/GroupingBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AA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,EAAE,IAAI,CAAC,kBAAkB;YAC3C,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;YAC7C,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ import { Behaviour } from './index';
2
+ import Particle from '../Particle';
3
+ /**
4
+ * This class is responsible for managing the lifetimes of particles.
5
+ * It sets the maximum lifetime of the particle and updates its progress.
6
+ *
7
+ * @extends Behaviour
8
+ */
9
+ export default class LifeBehaviour extends Behaviour {
10
+ enabled: boolean;
11
+ priority: number;
12
+ maxLifeTime: number;
13
+ timeVariance: number;
14
+ /**
15
+ * Sets the particle's life time and maximum life time.
16
+ *
17
+ * @param {Particle} particle - The particle to set the life time of.
18
+ * @returns {void}
19
+ */
20
+ init: (particle: Particle) => void;
21
+ /**
22
+ * Updates the particle's life time and progress.
23
+ *
24
+ * @param {Particle} particle - The particle to update.
25
+ * @param {number} deltaTime - The time since the last update.
26
+ * @returns {void}
27
+ */
28
+ apply: (particle: Particle, deltaTime: number) => void;
29
+ /**
30
+ * Returns the name of this behaviour.
31
+ *
32
+ * @returns {string} - The name of the behaviour.
33
+ */
34
+ getName(): string;
35
+ /**
36
+ * Returns the properties of the behaviour.
37
+ *
38
+ * @returns {Object} - The properties of the behaviour.
39
+ */
40
+ getProps(): {
41
+ enabled: boolean;
42
+ priority: number;
43
+ maxLifeTime: number;
44
+ timeVariance: number;
45
+ name: string;
46
+ };
47
+ }
@@ -0,0 +1,65 @@
1
+ import { Behaviour, BehaviourNames } from './index';
2
+ /**
3
+ * This class is responsible for managing the lifetimes of particles.
4
+ * It sets the maximum lifetime of the particle and updates its progress.
5
+ *
6
+ * @extends Behaviour
7
+ */
8
+ export default class LifeBehaviour extends Behaviour {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.enabled = true;
12
+ this.priority = 10000;
13
+ this.maxLifeTime = 0;
14
+ this.timeVariance = 0;
15
+ /**
16
+ * Sets the particle's life time and maximum life time.
17
+ *
18
+ * @param {Particle} particle - The particle to set the life time of.
19
+ * @returns {void}
20
+ */
21
+ this.init = (particle) => {
22
+ particle.lifeTime = 0;
23
+ particle.lifeProgress = 0;
24
+ particle.maxLifeTime = Math.max(this.maxLifeTime + this.varianceFrom(this.timeVariance), 0.0);
25
+ };
26
+ /**
27
+ * Updates the particle's life time and progress.
28
+ *
29
+ * @param {Particle} particle - The particle to update.
30
+ * @param {number} deltaTime - The time since the last update.
31
+ * @returns {void}
32
+ */
33
+ this.apply = (particle, deltaTime) => {
34
+ const { maxLifeTime } = particle;
35
+ const lifeTime = particle.lifeTime + deltaTime;
36
+ particle.lifeTime = lifeTime;
37
+ if (maxLifeTime > 0) {
38
+ particle.lifeProgress = Math.min(1.0, lifeTime / maxLifeTime);
39
+ }
40
+ };
41
+ }
42
+ /**
43
+ * Returns the name of this behaviour.
44
+ *
45
+ * @returns {string} - The name of the behaviour.
46
+ */
47
+ getName() {
48
+ return BehaviourNames.LIFE_BEHAVIOUR;
49
+ }
50
+ /**
51
+ * Returns the properties of the behaviour.
52
+ *
53
+ * @returns {Object} - The properties of the behaviour.
54
+ */
55
+ getProps() {
56
+ return {
57
+ enabled: this.enabled,
58
+ priority: this.priority,
59
+ maxLifeTime: this.maxLifeTime,
60
+ timeVariance: this.timeVariance,
61
+ name: this.getName(),
62
+ };
63
+ }
64
+ }
65
+ //# sourceMappingURL=LifeBehaviour.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LifeBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/LifeBeha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AW;YAC7B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,59 @@
1
+ import { Point } from '../util';
2
+ import { Behaviour } from './index';
3
+ import Particle from '../Particle';
4
+ export default class LightEffectBehaviour extends Behaviour {
5
+ enabled: boolean;
6
+ priority: number;
7
+ lightSource: Point;
8
+ lightIntensity: number;
9
+ lightColor: {
10
+ r: number;
11
+ g: number;
12
+ b: number;
13
+ };
14
+ attenuationFactor: number;
15
+ ambientLight: number;
16
+ directionalLight: boolean;
17
+ direction: Point;
18
+ spreadAngle: number;
19
+ volumetricLight: boolean;
20
+ volumetricIntensity: number;
21
+ fogDensity: number;
22
+ init: () => void;
23
+ apply: (particle: Particle, deltaTime: number) => void;
24
+ /**
25
+ * Gets the name of the behaviour
26
+ * @return {string} The name of the behaviour
27
+ */
28
+ getName(): string;
29
+ /**
30
+ * @description Retrieves the properties of the object.
31
+ * @returns {Object} The properties of the object.
32
+ */
33
+ getProps(): {
34
+ enabled: boolean;
35
+ priority: number;
36
+ lightSource: {
37
+ x: number;
38
+ y: number;
39
+ };
40
+ lightIntensity: number;
41
+ lightColor: {
42
+ r: number;
43
+ g: number;
44
+ b: number;
45
+ };
46
+ attenuationFactor: number;
47
+ ambientLight: number;
48
+ directionalLight: boolean;
49
+ direction: {
50
+ x: number;
51
+ y: number;
52
+ };
53
+ spreadAngle: number;
54
+ volumetricLight: boolean;
55
+ volumetricIntensity: number;
56
+ fogDensity: number;
57
+ name: string;
58
+ };
59
+ }
@@ -0,0 +1,94 @@
1
+ import { Point } from '../util';
2
+ import { Behaviour, BehaviourNames } from './index';
3
+ export default class LightEffectBehaviour extends Behaviour {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.enabled = true;
7
+ this.priority = 100;
8
+ this.lightSource = new Point(0, 0); // Position of the light source
9
+ this.lightIntensity = 1.0; // Maximum intensity of the light
10
+ this.lightColor = { r: 255, g: 255, b: 255 }; // Light color (white)
11
+ this.attenuationFactor = 0.002; // Controls light falloff with distance
12
+ this.ambientLight = 0.2; // Minimum light level
13
+ this.directionalLight = false; // Enable directional light
14
+ this.direction = new Point(0, 1); // Directional light angle (normalized)
15
+ this.spreadAngle = Math.PI / 4; // Spread angle for the directional light (in radians)
16
+ this.volumetricLight = false; // Enable volumetric light
17
+ this.volumetricIntensity = 0.3; // Intensity of volumetric light (glow)
18
+ this.fogDensity = 0.01; // Fog density for scattering effect
19
+ this.init = () => {
20
+ //
21
+ };
22
+ this.apply = (particle, deltaTime) => {
23
+ if (!this.enabled)
24
+ return;
25
+ const dx = particle.movement.x - this.lightSource.x;
26
+ const dy = particle.movement.y - this.lightSource.y;
27
+ const distanceSquared = dx * dx + dy * dy;
28
+ // Distance-based intensity (inverse square law with attenuation)
29
+ const intensity = this.lightIntensity / (1 + this.attenuationFactor * distanceSquared);
30
+ // Directional light effect
31
+ let directionalFactor = 1;
32
+ if (this.directionalLight) {
33
+ const normalizedDX = dx / Math.sqrt(distanceSquared);
34
+ const normalizedDY = dy / Math.sqrt(distanceSquared);
35
+ const dotProduct = normalizedDX * this.direction.x + normalizedDY * this.direction.y;
36
+ const angle = Math.acos(dotProduct);
37
+ // Apply spread angle
38
+ if (angle > this.spreadAngle) {
39
+ directionalFactor = 0; // Outside the spread
40
+ }
41
+ else {
42
+ directionalFactor = 1 - angle / this.spreadAngle; // Gradual falloff
43
+ }
44
+ }
45
+ // Combine intensity and directional factor
46
+ const effectiveIntensity = Math.max(this.ambientLight, Math.min(intensity * directionalFactor, this.lightIntensity));
47
+ // Blend particle color with light color
48
+ particle.color.r = Math.min(255, particle.color.r * effectiveIntensity * (this.lightColor.r / 255));
49
+ particle.color.g = Math.min(255, particle.color.g * effectiveIntensity * (this.lightColor.g / 255));
50
+ particle.color.b = Math.min(255, particle.color.b * effectiveIntensity * (this.lightColor.b / 255));
51
+ // Adjust alpha for glow
52
+ particle.color.alpha = Math.min(1, particle.color.alpha * effectiveIntensity);
53
+ // Volumetric light effect
54
+ if (this.volumetricLight) {
55
+ const fogEffect = Math.exp(-this.fogDensity * Math.sqrt(distanceSquared));
56
+ const volumetricFactor = this.volumetricIntensity * fogEffect;
57
+ particle.color.r = Math.min(255, particle.color.r + volumetricFactor * this.lightColor.r);
58
+ particle.color.g = Math.min(255, particle.color.g + volumetricFactor * this.lightColor.g);
59
+ particle.color.b = Math.min(255, particle.color.b + volumetricFactor * this.lightColor.b);
60
+ particle.color.alpha = Math.min(1, particle.color.alpha + volumetricFactor);
61
+ }
62
+ };
63
+ }
64
+ /**
65
+ * Gets the name of the behaviour
66
+ * @return {string} The name of the behaviour
67
+ */
68
+ getName() {
69
+ return BehaviourNames.LIGHT_EFFECT_BEHAVIOUR;
70
+ }
71
+ /**
72
+ * @description Retrieves the properties of the object.
73
+ * @returns {Object} The properties of the object.
74
+ */
75
+ getProps() {
76
+ return {
77
+ enabled: this.enabled,
78
+ priority: this.priority,
79
+ lightSource: { x: this.lightSource.x, y: this.lightSource.y },
80
+ lightIntensity: this.lightIntensity,
81
+ lightColor: this.lightColor,
82
+ attenuationFactor: this.attenuationFactor,
83
+ ambientLight: this.ambientLight,
84
+ directionalLight: this.directionalLight,
85
+ direction: { x: this.direction.x, y: this.direction.y },
86
+ spreadAngle: this.spreadAngle,
87
+ volumetricLight: this.volumetricLight,
88
+ volumetricIntensity: this.volumetricIntensity,
89
+ fogDensity: this.fogDensity,
90
+ name: this.getName(),
91
+ };
92
+ }
93
+ }
94
+ //# sourceMappingURL=LightEffectBehaviour.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LightEffectBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/LightEffectBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAGnD,MAAM,CAAC,OAAO,OAAO,oBA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AAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;gBACzF,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG,gBAAgB,CAAC,CAAA;YAC7E,CAAC;QACH,CAAC,CAAA;IAgCH,CAAC;IA9BC;;;OAGG;IACH,OAAO;QACL,OAAO,cAAc,CAAC,sBAAsB,CAAA;IAC9C,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE;YAC7D,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,SAAS,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE;YACvD,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;YAC7C,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ import Particle from '../Particle';
2
+ import { Point } from '../util';
3
+ import Behaviour from './Behaviour';
4
+ export default class NoiseBasedMotionBehaviour extends Behaviour {
5
+ enabled: boolean;
6
+ priority: number;
7
+ noiseScale: number;
8
+ noiseIntensity: number;
9
+ noiseSpeed: number;
10
+ noiseDirection: Point;
11
+ noise2D: any;
12
+ constructor();
13
+ init: (particle: Particle) => void;
14
+ apply: (particle: Particle, deltaTime: number) => void;
15
+ getName(): string;
16
+ getProps(): {
17
+ enabled: boolean;
18
+ priority: number;
19
+ noiseScale: number;
20
+ noiseIntensity: number;
21
+ noiseSpeed: number;
22
+ noiseDirection: {
23
+ x: number;
24
+ y: number;
25
+ };
26
+ name: string;
27
+ };
28
+ }