custom-pixi-particles 5.1.1 → 7.0.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.
- package/README.md +118 -82
- package/dist/index.d.ts +5 -1
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/Particle.d.ts +35 -1
- package/dist/lib/Particle.js +66 -1
- package/dist/lib/Particle.js.map +1 -1
- package/dist/lib/ParticlePool.js +2 -1
- package/dist/lib/ParticlePool.js.map +1 -1
- package/dist/lib/behaviour/AngularVelocityBehaviour.d.ts +10 -6
- package/dist/lib/behaviour/AngularVelocityBehaviour.js +45 -14
- package/dist/lib/behaviour/AngularVelocityBehaviour.js.map +1 -1
- package/dist/lib/behaviour/AttractionRepulsionBehaviour.d.ts +42 -0
- package/dist/lib/behaviour/AttractionRepulsionBehaviour.js +78 -0
- package/dist/lib/behaviour/AttractionRepulsionBehaviour.js.map +1 -0
- package/dist/lib/behaviour/BehaviourNames.d.ts +13 -2
- package/dist/lib/behaviour/BehaviourNames.js +13 -1
- package/dist/lib/behaviour/BehaviourNames.js.map +1 -1
- package/dist/lib/behaviour/CollisionBehaviour.d.ts +86 -0
- package/dist/lib/behaviour/CollisionBehaviour.js +140 -0
- package/dist/lib/behaviour/CollisionBehaviour.js.map +1 -0
- package/dist/lib/behaviour/ColorBehaviour.d.ts +22 -0
- package/dist/lib/behaviour/ColorBehaviour.js +134 -18
- package/dist/lib/behaviour/ColorBehaviour.js.map +1 -1
- package/dist/lib/behaviour/EmitDirectionBehaviour.d.ts +14 -8
- package/dist/lib/behaviour/EmitDirectionBehaviour.js +53 -12
- package/dist/lib/behaviour/EmitDirectionBehaviour.js.map +1 -1
- package/dist/lib/behaviour/EmitterBehaviours.d.ts +6 -0
- package/dist/lib/behaviour/EmitterBehaviours.js +11 -0
- package/dist/lib/behaviour/EmitterBehaviours.js.map +1 -1
- package/dist/lib/behaviour/ForceFieldsBehaviour.d.ts +53 -0
- package/dist/lib/behaviour/ForceFieldsBehaviour.js +80 -0
- package/dist/lib/behaviour/ForceFieldsBehaviour.js.map +1 -0
- package/dist/lib/behaviour/GroupingBehaviour.d.ts +57 -0
- package/dist/lib/behaviour/GroupingBehaviour.js +143 -0
- package/dist/lib/behaviour/GroupingBehaviour.js.map +1 -0
- package/dist/lib/behaviour/LifeBehaviour.d.ts +0 -20
- package/dist/lib/behaviour/LifeBehaviour.js +0 -20
- package/dist/lib/behaviour/LifeBehaviour.js.map +1 -1
- package/dist/lib/behaviour/LightEffectBehaviour.d.ts +59 -0
- package/dist/lib/behaviour/LightEffectBehaviour.js +94 -0
- package/dist/lib/behaviour/LightEffectBehaviour.js.map +1 -0
- package/dist/lib/behaviour/NoiseBasedMotionBehaviour.d.ts +35 -0
- package/dist/lib/behaviour/NoiseBasedMotionBehaviour.js +93 -0
- package/dist/lib/behaviour/NoiseBasedMotionBehaviour.js.map +1 -0
- package/dist/lib/behaviour/PositionBehaviour.d.ts +62 -9
- package/dist/lib/behaviour/PositionBehaviour.js +352 -88
- package/dist/lib/behaviour/PositionBehaviour.js.map +1 -1
- package/dist/lib/behaviour/RotationBehaviour.d.ts +20 -12
- package/dist/lib/behaviour/RotationBehaviour.js +50 -16
- package/dist/lib/behaviour/RotationBehaviour.js.map +1 -1
- package/dist/lib/behaviour/SizeBehaviour.d.ts +33 -3
- package/dist/lib/behaviour/SizeBehaviour.js +107 -22
- package/dist/lib/behaviour/SizeBehaviour.js.map +1 -1
- package/dist/lib/behaviour/SoundReactiveBehaviour.d.ts +58 -0
- package/dist/lib/behaviour/SoundReactiveBehaviour.js +132 -0
- package/dist/lib/behaviour/SoundReactiveBehaviour.js.map +1 -0
- package/dist/lib/behaviour/SpawnBehaviour.d.ts +89 -0
- package/dist/lib/behaviour/SpawnBehaviour.js +705 -0
- package/dist/lib/behaviour/SpawnBehaviour.js.map +1 -0
- package/dist/lib/behaviour/StretchBehaviour.d.ts +30 -0
- package/dist/lib/behaviour/StretchBehaviour.js +59 -0
- package/dist/lib/behaviour/StretchBehaviour.js.map +1 -0
- package/dist/lib/behaviour/TemperatureBehaviour.d.ts +47 -0
- package/dist/lib/behaviour/TemperatureBehaviour.js +64 -0
- package/dist/lib/behaviour/TemperatureBehaviour.js.map +1 -0
- package/dist/lib/behaviour/TimelineBehaviour.d.ts +73 -0
- package/dist/lib/behaviour/TimelineBehaviour.js +100 -0
- package/dist/lib/behaviour/TimelineBehaviour.js.map +1 -0
- package/dist/lib/behaviour/TurbulenceBehaviour.d.ts +2 -1
- package/dist/lib/behaviour/TurbulenceBehaviour.js +18 -13
- package/dist/lib/behaviour/TurbulenceBehaviour.js.map +1 -1
- package/dist/lib/behaviour/index.d.ts +12 -1
- package/dist/lib/behaviour/index.js +12 -1
- package/dist/lib/behaviour/index.js.map +1 -1
- package/dist/lib/customPixiParticlesSettingsInterface.d.ts +1 -0
- package/dist/lib/emission/RandomEmission.js.map +1 -1
- package/dist/lib/emission/StandardEmission.js.map +1 -1
- package/dist/lib/emission/UniformEmission.js.map +1 -1
- package/dist/lib/emitter/Emitter.d.ts +4 -1
- package/dist/lib/emitter/Emitter.js +42 -2
- package/dist/lib/emitter/Emitter.js.map +1 -1
- package/dist/lib/parser/BehaviourParser.js +38 -2
- package/dist/lib/parser/BehaviourParser.js.map +1 -1
- package/dist/lib/parser/CompatibilityHelper.js +2 -1
- package/dist/lib/parser/CompatibilityHelper.js.map +1 -1
- package/dist/lib/parser/EmitControllerParser.js.map +1 -1
- package/dist/lib/parser/EmitterParser.js.map +1 -1
- package/dist/lib/pixi/Renderer.d.ts +14 -5
- package/dist/lib/pixi/Renderer.js +128 -70
- package/dist/lib/pixi/Renderer.js.map +1 -1
- package/dist/lib/pixi/TestRenderer.d.ts +125 -0
- package/dist/lib/pixi/TestRenderer.js +560 -0
- package/dist/lib/pixi/TestRenderer.js.map +1 -0
- package/dist/lib/util/List.js.map +1 -1
- package/dist/lib/util/MinMax.d.ts +34 -0
- package/dist/lib/util/MinMax.js +46 -0
- package/dist/lib/util/MinMax.js.map +1 -0
- package/dist/lib/util/Point.js +2 -2
- package/dist/lib/util/Point.js.map +1 -1
- package/dist/lib/util/Random.js +2 -1
- package/dist/lib/util/Random.js.map +1 -1
- package/dist/lib/util/ThereBack.d.ts +14 -0
- package/dist/lib/util/ThereBack.js +23 -0
- package/dist/lib/util/ThereBack.js.map +1 -0
- package/package.json +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AngularVelocityBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/AngularVelocityBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,IAAI,MAAM,eAAe,CAAA;AAChC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAG7C
|
|
1
|
+
{"version":3,"file":"AngularVelocityBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/AngularVelocityBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,IAAI,MAAM,eAAe,CAAA;AAChC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAG7C,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,SAAS;IAA/D;;QACY,aAAQ,GAAW,GAAG,CAAA;QACxB,YAAO,GAAY,KAAK,CAAA;QACxB,YAAO,GAAW,CAAC,CAAA;QACnB,oBAAe,GAAW,CAAC,CAAA;QAC3B,cAAS,GAAW,CAAC,CAAA;QACrB,sBAAiB,GAAW,CAAC,CAAA;QAC7B,cAAS,GAAW,CAAC,CAAA;QACrB,sBAAiB,GAAW,CAAC,CAAA;QAC7B,cAAS,GAAY,KAAK,CAAA,CAAC,6BAA6B;QACxD,qBAAgB,GAAW,CAAC,CAAA,CAAC,uBAAuB;QACpD,yBAAoB,GAAW,EAAE,CAAA,CAAC,sCAAsC;QACxE,0BAAqB,GAAY,IAAI,CAAA,CAAC,yCAAyC;QAC/E,kBAAa,GAAY,KAAK,CAAA,CAA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SAAS,CAAA;QACxB,CAAC,CAAA;IAoCH,CAAC;IAlCC;;;;;OAKG;IACH,OAAO;QACL,OAAO,cAAc,CAAC,iBAAiB,CAAA;IACzC,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QACN,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Behaviour } from './index';
|
|
2
|
+
import Particle from '../Particle';
|
|
3
|
+
/**
|
|
4
|
+
* AttractionRepulsionBehaviour applies attraction or repulsion forces to particles
|
|
5
|
+
* without overriding other position-related behaviors.
|
|
6
|
+
* @extends Behaviour
|
|
7
|
+
*/
|
|
8
|
+
export default class AttractionRepulsionBehaviour extends Behaviour {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
priority: number;
|
|
11
|
+
/**
|
|
12
|
+
* List of influence points affecting particles.
|
|
13
|
+
* Each point: { point: Point, strength: number, range: number }
|
|
14
|
+
*/
|
|
15
|
+
influencePoints: never[];
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the particle, but does not modify position directly.
|
|
18
|
+
* @param {Particle} particle - The particle to initialize.
|
|
19
|
+
*/
|
|
20
|
+
init: (particle: Particle) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Applies attraction or repulsion forces to the particle additively.
|
|
23
|
+
* @param {Particle} particle - The particle to apply the behavior to.
|
|
24
|
+
* @param {number} deltaTime - Time elapsed since the last frame.
|
|
25
|
+
*/
|
|
26
|
+
apply: (particle: Particle, deltaTime: number) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the name of the behavior.
|
|
29
|
+
* @returns {string} - The name of the behavior.
|
|
30
|
+
*/
|
|
31
|
+
getName(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the properties of the behavior.
|
|
34
|
+
* @returns {object} - The properties of the behavior.
|
|
35
|
+
*/
|
|
36
|
+
getProps(): {
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
priority: number;
|
|
39
|
+
influencePoints: never[];
|
|
40
|
+
name: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Behaviour, BehaviourNames } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* AttractionRepulsionBehaviour applies attraction or repulsion forces to particles
|
|
4
|
+
* without overriding other position-related behaviors.
|
|
5
|
+
* @extends Behaviour
|
|
6
|
+
*/
|
|
7
|
+
export default class AttractionRepulsionBehaviour extends Behaviour {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.enabled = true;
|
|
11
|
+
this.priority = 200; // Ensure this runs after PositionBehaviour if needed
|
|
12
|
+
/**
|
|
13
|
+
* List of influence points affecting particles.
|
|
14
|
+
* Each point: { point: Point, strength: number, range: number }
|
|
15
|
+
*/
|
|
16
|
+
this.influencePoints = [];
|
|
17
|
+
/**
|
|
18
|
+
* Initializes the particle, but does not modify position directly.
|
|
19
|
+
* @param {Particle} particle - The particle to initialize.
|
|
20
|
+
*/
|
|
21
|
+
this.init = (particle) => {
|
|
22
|
+
// Initialization logic if needed.
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Applies attraction or repulsion forces to the particle additively.
|
|
26
|
+
* @param {Particle} particle - The particle to apply the behavior to.
|
|
27
|
+
* @param {number} deltaTime - Time elapsed since the last frame.
|
|
28
|
+
*/
|
|
29
|
+
this.apply = (particle, deltaTime) => {
|
|
30
|
+
if (!this.enabled || particle.skipPositionBehaviour || particle.skipAttractionRepulsionBehaviour)
|
|
31
|
+
return;
|
|
32
|
+
// Accumulate influence forces
|
|
33
|
+
let totalForceX = 0;
|
|
34
|
+
let totalForceY = 0;
|
|
35
|
+
this.influencePoints.forEach(({ point, strength, range }) => {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
const dx = point.x - particle.x;
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const dy = point.y - particle.y;
|
|
40
|
+
const distanceSquared = dx * dx + dy * dy;
|
|
41
|
+
if (distanceSquared > range * range || distanceSquared === 0)
|
|
42
|
+
return;
|
|
43
|
+
const distance = Math.sqrt(distanceSquared);
|
|
44
|
+
const force = strength * (1 - distance / range) * deltaTime;
|
|
45
|
+
const normalizedDx = dx / distance;
|
|
46
|
+
const normalizedDy = dy / distance;
|
|
47
|
+
totalForceX += normalizedDx * force;
|
|
48
|
+
totalForceY += normalizedDy * force;
|
|
49
|
+
});
|
|
50
|
+
// Add forces to particle velocity (or acceleration for smoother effects)
|
|
51
|
+
particle.velocity.x += totalForceX;
|
|
52
|
+
particle.velocity.y += totalForceY;
|
|
53
|
+
// Apply updated velocity to position additively
|
|
54
|
+
particle.x += particle.velocity.x * deltaTime;
|
|
55
|
+
particle.y += particle.velocity.y * deltaTime;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets the name of the behavior.
|
|
60
|
+
* @returns {string} - The name of the behavior.
|
|
61
|
+
*/
|
|
62
|
+
getName() {
|
|
63
|
+
return BehaviourNames.ATTRACTION_REPULSION_BEHAVIOUR;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the properties of the behavior.
|
|
67
|
+
* @returns {object} - The properties of the behavior.
|
|
68
|
+
*/
|
|
69
|
+
getProps() {
|
|
70
|
+
return {
|
|
71
|
+
enabled: this.enabled,
|
|
72
|
+
priority: this.priority,
|
|
73
|
+
influencePoints: this.influencePoints,
|
|
74
|
+
name: this.getName(),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=AttractionRepulsionBehaviour.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttractionRepulsionBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/AttractionRepulsionBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAGnD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,4BAA6B,SAAQ,SAAS;IAAnE;;QACE,YAAO,GAAG,IAAI,CAAA;QACd,aAAQ,GAAG,GAAG,CAAA,CAAC,qDAAqD;QAEpE;;;WAGG;QACH,oBAAe,GAAG,EAAE,CAAA;QAEpB;;;WAGG;QACH,SAAI,GAAG,CAAC,QAAkB,EAAE,EAAE;YAC5B,kCAAkC;QACpC,CAAC,CAAA;QAED;;;;WAIG;QACH,UAAK,GAAG,CAAC,QAAkB,EAAE,SAAiB,EAAE,EAAE;YAChD,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC,qBAAqB,IAAI,QAAQ,CAAC,gCAAgC;gBAAE,OAAM;YAExG,8BAA8B;YAC9B,IAAI,WAAW,GAAG,CAAC,CAAA;YACnB,IAAI,WAAW,GAAG,CAAC,CAAA;YAEnB,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE;gBAC1D,aAAa;gBACb,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAA;gBAC/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AA;IACH,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const
|
|
1
|
+
declare const behaviourNames: {
|
|
2
2
|
ANGULAR_BEHAVIOUR: string;
|
|
3
3
|
LIFE_BEHAVIOUR: string;
|
|
4
4
|
COLOR_BEHAVIOUR: string;
|
|
@@ -7,5 +7,16 @@ declare const _default: {
|
|
|
7
7
|
EMIT_DIRECTION: string;
|
|
8
8
|
ROTATION_BEHAVIOUR: string;
|
|
9
9
|
TURBULENCE_BEHAVIOUR: string;
|
|
10
|
+
COLLISION_BEHAVIOUR: string;
|
|
11
|
+
ATTRACTION_REPULSION_BEHAVIOUR: string;
|
|
12
|
+
NOISE_BASED_MOTION_BEHAVIOUR: string;
|
|
13
|
+
FORCE_FIELDS_BEHAVIOUR: string;
|
|
14
|
+
SPAWN_BEHAVIOUR: string;
|
|
15
|
+
TIMELINE_BEHAVIOUR: string;
|
|
16
|
+
GROUPING_BEHAVIOUR: string;
|
|
17
|
+
SOUND_REACTIVE_BEHAVIOUR: string;
|
|
18
|
+
LIGHT_EFFECT_BEHAVIOUR: string;
|
|
19
|
+
STRETCH_BEHAVIOUR: string;
|
|
20
|
+
TEMPERATURE_BEHAVIOUR: string;
|
|
10
21
|
};
|
|
11
|
-
export default
|
|
22
|
+
export default behaviourNames;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const behaviourNames = {
|
|
2
2
|
ANGULAR_BEHAVIOUR: 'AngularVelocityBehaviour',
|
|
3
3
|
LIFE_BEHAVIOUR: 'LifeBehaviour',
|
|
4
4
|
COLOR_BEHAVIOUR: 'ColorBehaviour',
|
|
@@ -7,5 +7,17 @@ export default {
|
|
|
7
7
|
EMIT_DIRECTION: 'EmitDirectionBehaviour',
|
|
8
8
|
ROTATION_BEHAVIOUR: 'RotationBehaviour',
|
|
9
9
|
TURBULENCE_BEHAVIOUR: 'TurbulenceBehaviour',
|
|
10
|
+
COLLISION_BEHAVIOUR: 'CollisionBehaviour',
|
|
11
|
+
ATTRACTION_REPULSION_BEHAVIOUR: 'AttractionRepulsionBehaviour',
|
|
12
|
+
NOISE_BASED_MOTION_BEHAVIOUR: 'NoiseBasedMotionBehaviour',
|
|
13
|
+
FORCE_FIELDS_BEHAVIOUR: 'ForceFieldsBehaviour',
|
|
14
|
+
SPAWN_BEHAVIOUR: 'SpawnBehaviour',
|
|
15
|
+
TIMELINE_BEHAVIOUR: 'TimelineBehaviour',
|
|
16
|
+
GROUPING_BEHAVIOUR: 'GroupingBehaviour',
|
|
17
|
+
SOUND_REACTIVE_BEHAVIOUR: 'SoundReactiveBehaviour',
|
|
18
|
+
LIGHT_EFFECT_BEHAVIOUR: 'LightEffectBehaviour',
|
|
19
|
+
STRETCH_BEHAVIOUR: 'StretchBehaviour',
|
|
20
|
+
TEMPERATURE_BEHAVIOUR: 'TemperatureBehaviour',
|
|
10
21
|
};
|
|
22
|
+
export default behaviourNames;
|
|
11
23
|
//# sourceMappingURL=BehaviourNames.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BehaviourNames.js","sourceRoot":"","sources":["../../../src/lib/behaviour/BehaviourNames.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"BehaviourNames.js","sourceRoot":"","sources":["../../../src/lib/behaviour/BehaviourNames.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG;IACrB,iBAAiB,EAAE,0BAA0B;IAC7C,cAAc,EAAE,eAAe;IAC/B,eAAe,EAAE,gBAAgB;IACjC,kBAAkB,EAAE,mBAAmB;IACvC,cAAc,EAAE,eAAe;IAC/B,cAAc,EAAE,wBAAwB;IACxC,kBAAkB,EAAE,mBAAmB;IACvC,oBAAoB,EAAE,qBAAqB;IAC3C,mBAAmB,EAAE,oBAAoB;IACzC,8BAA8B,EAAE,8BAA8B;IAC9D,4BAA4B,EAAE,2BAA2B;IACzD,sBAAsB,EAAE,sBAAsB;IAC9C,eAAe,EAAE,gBAAgB;IACjC,kBAAkB,EAAE,mBAAmB;IACvC,kBAAkB,EAAE,mBAAmB;IACvC,wBAAwB,EAAE,wBAAwB;IAClD,sBAAsB,EAAE,sBAAsB;IAC9C,iBAAiB,EAAE,kBAAkB;IACrC,qBAAqB,EAAE,sBAAsB;CAC9C,CAAA;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Behaviour } from './index';
|
|
2
|
+
import Particle from '../Particle';
|
|
3
|
+
import Model from '../Model';
|
|
4
|
+
export default class CollisionBehaviour extends Behaviour {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
skipPositionBehaviourOnCollision: boolean;
|
|
7
|
+
skipAngularVelocityBehaviourOnCollision: boolean;
|
|
8
|
+
skipColorBehaviourOnCollision: boolean;
|
|
9
|
+
skipAttractionRepulsionBehaviourOnCollision: boolean;
|
|
10
|
+
skipEmitDirectionBehaviourOnCollision: boolean;
|
|
11
|
+
skipRotationBehaviourOnCollision: boolean;
|
|
12
|
+
skipSizeBehaviourOnCollision: boolean;
|
|
13
|
+
priority: number;
|
|
14
|
+
distance: number;
|
|
15
|
+
lines: {
|
|
16
|
+
point1: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
point2: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
};
|
|
24
|
+
}[];
|
|
25
|
+
/**
|
|
26
|
+
* Function that initializes a particle
|
|
27
|
+
* @param {Particle} particle - The particle to be initialized
|
|
28
|
+
* @param {Model} model - The model of the particle
|
|
29
|
+
*/
|
|
30
|
+
init: (particle: Particle, model: Model) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Applies the particle's velocity and acceleration to move it and calculate its size, rotation, and position.
|
|
33
|
+
* @param {Particle} particle - The particle to be moved
|
|
34
|
+
* @param {number} deltaTime - The time delta for the movement calculation
|
|
35
|
+
* @param {Model} model - The model containing information about the particle's movement
|
|
36
|
+
*/
|
|
37
|
+
apply: (particle: Particle, deltaTime: number, model: Model) => void;
|
|
38
|
+
reflectVelocity: (particle: Particle, normal: {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
}) => void;
|
|
42
|
+
checkCollisionAndReflect: (particle: Particle) => boolean;
|
|
43
|
+
calculateNormal: (point1: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
}, point2: {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
}) => {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
};
|
|
53
|
+
pointToLineDistance: (x: number, y: number, x1: number, y1: number, x2: number, y2: number) => number;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the name of the behaviour
|
|
56
|
+
* @return {BehaviourNames} The name of the behaviour
|
|
57
|
+
*/
|
|
58
|
+
getName(): string;
|
|
59
|
+
/**
|
|
60
|
+
* @description Retrieves the properties of the object.
|
|
61
|
+
* @returns {Object} The properties of the object.
|
|
62
|
+
*/
|
|
63
|
+
getProps(): {
|
|
64
|
+
enabled: boolean;
|
|
65
|
+
skipPositionBehaviourOnCollision: boolean;
|
|
66
|
+
skipAngularVelocityBehaviourOnCollision: boolean;
|
|
67
|
+
skipColorBehaviourOnCollision: boolean;
|
|
68
|
+
skipAttractionRepulsionBehaviourOnCollision: boolean;
|
|
69
|
+
skipEmitDirectionBehaviourOnCollision: boolean;
|
|
70
|
+
skipRotationBehaviourOnCollision: boolean;
|
|
71
|
+
skipSizeBehaviourOnCollision: boolean;
|
|
72
|
+
priority: number;
|
|
73
|
+
lines: {
|
|
74
|
+
point1: {
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
};
|
|
78
|
+
point2: {
|
|
79
|
+
x: number;
|
|
80
|
+
y: number;
|
|
81
|
+
};
|
|
82
|
+
}[];
|
|
83
|
+
distance: number;
|
|
84
|
+
name: string;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Behaviour, BehaviourNames } from './index';
|
|
2
|
+
export default class CollisionBehaviour extends Behaviour {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.enabled = false;
|
|
6
|
+
this.skipPositionBehaviourOnCollision = false;
|
|
7
|
+
this.skipAngularVelocityBehaviourOnCollision = false;
|
|
8
|
+
this.skipColorBehaviourOnCollision = false;
|
|
9
|
+
this.skipAttractionRepulsionBehaviourOnCollision = false;
|
|
10
|
+
this.skipEmitDirectionBehaviourOnCollision = false;
|
|
11
|
+
this.skipRotationBehaviourOnCollision = false;
|
|
12
|
+
this.skipSizeBehaviourOnCollision = false;
|
|
13
|
+
this.priority = 10000;
|
|
14
|
+
this.distance = 10;
|
|
15
|
+
this.lines = [
|
|
16
|
+
{ point1: { x: 0, y: 0 }, point2: { x: 0, y: 0 } },
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Function that initializes a particle
|
|
20
|
+
* @param {Particle} particle - The particle to be initialized
|
|
21
|
+
* @param {Model} model - The model of the particle
|
|
22
|
+
*/
|
|
23
|
+
this.init = (particle, model) => {
|
|
24
|
+
// do nothing
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Applies the particle's velocity and acceleration to move it and calculate its size, rotation, and position.
|
|
28
|
+
* @param {Particle} particle - The particle to be moved
|
|
29
|
+
* @param {number} deltaTime - The time delta for the movement calculation
|
|
30
|
+
* @param {Model} model - The model containing information about the particle's movement
|
|
31
|
+
*/
|
|
32
|
+
this.apply = (particle, deltaTime, model) => {
|
|
33
|
+
if (!this.enabled)
|
|
34
|
+
return;
|
|
35
|
+
this.checkCollisionAndReflect(particle);
|
|
36
|
+
};
|
|
37
|
+
this.reflectVelocity = (particle, normal) => {
|
|
38
|
+
const dotProduct = particle.velocity.x * normal.x + particle.velocity.y * normal.y;
|
|
39
|
+
particle.velocity.x = particle.velocity.x - 2 * dotProduct * normal.x;
|
|
40
|
+
particle.velocity.y = particle.velocity.y - 2 * dotProduct * normal.y;
|
|
41
|
+
if (this.skipPositionBehaviourOnCollision) {
|
|
42
|
+
particle.skipPositionBehaviour = true;
|
|
43
|
+
}
|
|
44
|
+
if (this.skipAngularVelocityBehaviourOnCollision) {
|
|
45
|
+
particle.skipAngularVelocityBehaviour = true;
|
|
46
|
+
}
|
|
47
|
+
if (this.skipColorBehaviourOnCollision) {
|
|
48
|
+
particle.skipColorBehaviour = true;
|
|
49
|
+
}
|
|
50
|
+
if (this.skipAttractionRepulsionBehaviourOnCollision) {
|
|
51
|
+
particle.skipAttractionRepulsionBehaviour = true;
|
|
52
|
+
}
|
|
53
|
+
if (this.skipEmitDirectionBehaviourOnCollision) {
|
|
54
|
+
particle.skipEmitDirectionBehaviour = true;
|
|
55
|
+
}
|
|
56
|
+
if (this.skipRotationBehaviourOnCollision) {
|
|
57
|
+
particle.skipRotationBehaviour = true;
|
|
58
|
+
}
|
|
59
|
+
if (this.skipSizeBehaviourOnCollision) {
|
|
60
|
+
particle.skipSizeBehaviour = true;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
this.checkCollisionAndReflect = (particle) => {
|
|
64
|
+
if (this.lines.length === 0)
|
|
65
|
+
return false; // No lines to check collision
|
|
66
|
+
for (const line of this.lines) {
|
|
67
|
+
const { point1, point2 } = line;
|
|
68
|
+
// Check if the particle is near the line segment (using point-line distance)
|
|
69
|
+
const dist = this.pointToLineDistance(particle.x, particle.y, point1.x, point1.y, point2.x, point2.y);
|
|
70
|
+
if (dist <= this.distance) {
|
|
71
|
+
// Reflect velocity based on the line's normal
|
|
72
|
+
const normal = this.calculateNormal(point1, point2);
|
|
73
|
+
this.reflectVelocity(particle, normal);
|
|
74
|
+
return true; // Stop further checks after first collision
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
79
|
+
this.calculateNormal = (point1, point2) => {
|
|
80
|
+
const dx = point2.x - point1.x;
|
|
81
|
+
const dy = point2.y - point1.y;
|
|
82
|
+
const length = Math.sqrt(dx * dx + dy * dy);
|
|
83
|
+
return { x: -dy / length, y: dx / length }; // Perpendicular vector (normalized)
|
|
84
|
+
};
|
|
85
|
+
this.pointToLineDistance = (x, y, x1, y1, x2, y2) => {
|
|
86
|
+
const A = x - x1;
|
|
87
|
+
const B = y - y1;
|
|
88
|
+
const C = x2 - x1;
|
|
89
|
+
const D = y2 - y1;
|
|
90
|
+
const dot = A * C + B * D;
|
|
91
|
+
const lenSq = C * C + D * D;
|
|
92
|
+
const param = lenSq !== 0 ? dot / lenSq : -1;
|
|
93
|
+
let xx;
|
|
94
|
+
let yy;
|
|
95
|
+
if (param < 0) {
|
|
96
|
+
xx = x1;
|
|
97
|
+
yy = y1;
|
|
98
|
+
}
|
|
99
|
+
else if (param > 1) {
|
|
100
|
+
xx = x2;
|
|
101
|
+
yy = y2;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
xx = x1 + param * C;
|
|
105
|
+
yy = y1 + param * D;
|
|
106
|
+
}
|
|
107
|
+
const dx = x - xx;
|
|
108
|
+
const dy = y - yy;
|
|
109
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets the name of the behaviour
|
|
114
|
+
* @return {BehaviourNames} The name of the behaviour
|
|
115
|
+
*/
|
|
116
|
+
getName() {
|
|
117
|
+
return BehaviourNames.COLLISION_BEHAVIOUR;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @description Retrieves the properties of the object.
|
|
121
|
+
* @returns {Object} The properties of the object.
|
|
122
|
+
*/
|
|
123
|
+
getProps() {
|
|
124
|
+
return {
|
|
125
|
+
enabled: this.enabled,
|
|
126
|
+
skipPositionBehaviourOnCollision: this.skipPositionBehaviourOnCollision,
|
|
127
|
+
skipAngularVelocityBehaviourOnCollision: this.skipAngularVelocityBehaviourOnCollision,
|
|
128
|
+
skipColorBehaviourOnCollision: this.skipColorBehaviourOnCollision,
|
|
129
|
+
skipAttractionRepulsionBehaviourOnCollision: this.skipAttractionRepulsionBehaviourOnCollision,
|
|
130
|
+
skipEmitDirectionBehaviourOnCollision: this.skipEmitDirectionBehaviourOnCollision,
|
|
131
|
+
skipRotationBehaviourOnCollision: this.skipRotationBehaviourOnCollision,
|
|
132
|
+
skipSizeBehaviourOnCollision: this.skipSizeBehaviourOnCollision,
|
|
133
|
+
priority: this.priority,
|
|
134
|
+
lines: this.lines,
|
|
135
|
+
distance: this.distance,
|
|
136
|
+
name: this.getName(),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=CollisionBehaviour.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollisionBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/CollisionBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAInD,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,SAAS;IAAzD;;QACE,YAAO,GAAG,KAAK,CAAA;QACf,qCAAgC,GAAY,KAAK,CAAA;QACjD,4CAAuC,GAAY,KAAK,CAAA;QACxD,kCAA6B,GAAY,KAAK,CAAA;QAC9C,gDAA2C,GAAY,KAAK,CAAA;QAC5D,0CAAqC,GAAY,KAAK,CAAA;QACtD,qCAAgC,GAAY,KAAK,CAAA;QACjD,iCAA4B,GAAY,KAAK,CAAA;QAC7C,aAAQ,GAAG,KAAK,CAAA;QAChB,aAAQ,GAAG,EAAE,CAAA;QACb,UAAK,GAA6E;YAChF,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;SACnD,CAAA;QAED;;;;WAIG;QACH,SAAI,GAAG,CAAC,QAAkB,EAA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AAG,CAAC,GAAG,EAAE,CAAA;YACjB,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,CAAA;YACjB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAA;QACrC,CAAC,CAAA;IA8BH,CAAC;IA5BC;;;OAGG;IACH,OAAO;QACL,OAAO,cAAc,CAAC,mBAAmB,CAAA;IAC3C,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,gCAAgC,EAAE,IAAI,CAAC,gCAAgC;YACvE,uCAAuC,EAAE,IAAI,CAAC,uCAAuC;YACrF,6BAA6B,EAAE,IAAI,CAAC,6BAA6B;YACjE,2CAA2C,EAAE,IAAI,CAAC,2CAA2C;YAC7F,qCAAqC,EAAE,IAAI,CAAC,qCAAqC;YACjF,gCAAgC,EAAE,IAAI,CAAC,gCAAgC;YACvE,4BAA4B,EAAE,IAAI,CAAC,4BAA4B;YAC/D,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -9,8 +9,22 @@ export default class ColorBehaviour extends Behaviour {
|
|
|
9
9
|
startVariance: Color;
|
|
10
10
|
endVariance: Color;
|
|
11
11
|
sinus: boolean;
|
|
12
|
+
colorStops: Color[];
|
|
13
|
+
usePerlin: boolean;
|
|
14
|
+
pulseSpeed: number;
|
|
15
|
+
pulseIntensity: number;
|
|
16
|
+
mirrorTransition: boolean;
|
|
17
|
+
fadeToGray: boolean;
|
|
18
|
+
fadeToTransparent: boolean;
|
|
19
|
+
flickerIntensity: number;
|
|
12
20
|
init: (particle: Particle) => void;
|
|
13
21
|
apply: (particle: Particle) => void;
|
|
22
|
+
applyColorStops: (particle: Particle, lifeProgress: number) => void;
|
|
23
|
+
pseudoRandomNoise(seed: number): number;
|
|
24
|
+
applyPerlinColor: (particle: Particle, lifeProgress: number) => void;
|
|
25
|
+
applyPulseEffect: (particle: Particle, lifeProgress: number) => void;
|
|
26
|
+
applyFadeToGray: (particle: Particle) => void;
|
|
27
|
+
applyFlickering: (particle: Particle) => void;
|
|
14
28
|
getName(): string;
|
|
15
29
|
getProps(): {
|
|
16
30
|
enabled: boolean;
|
|
@@ -40,6 +54,14 @@ export default class ColorBehaviour extends Behaviour {
|
|
|
40
54
|
_alpha: number;
|
|
41
55
|
};
|
|
42
56
|
sinus: boolean;
|
|
57
|
+
colorStops: Color[];
|
|
58
|
+
usePerlin: boolean;
|
|
59
|
+
pulseSpeed: number;
|
|
60
|
+
pulseIntensity: number;
|
|
61
|
+
mirrorTransition: boolean;
|
|
62
|
+
fadeToGray: boolean;
|
|
63
|
+
fadeToTransparent: boolean;
|
|
64
|
+
flickerIntensity: number;
|
|
43
65
|
name: string;
|
|
44
66
|
};
|
|
45
67
|
}
|
|
@@ -11,7 +11,18 @@ export default class ColorBehaviour extends Behaviour {
|
|
|
11
11
|
this.startVariance = new Color(0, 0, 0, 0);
|
|
12
12
|
this.endVariance = new Color(0, 0, 0, 0);
|
|
13
13
|
this.sinus = false;
|
|
14
|
+
// New properties
|
|
15
|
+
this.colorStops = []; // Multi-gradient stops
|
|
16
|
+
this.usePerlin = false; // Enable Perlin noise-based color changes
|
|
17
|
+
this.pulseSpeed = 0; // Speed of the pulse effect
|
|
18
|
+
this.pulseIntensity = 0; // Intensity of the pulse effect
|
|
19
|
+
this.mirrorTransition = false; // Mirror the color transition midway
|
|
20
|
+
this.fadeToGray = false; // Desaturate color over time
|
|
21
|
+
this.fadeToTransparent = false; // Fade alpha over time
|
|
22
|
+
this.flickerIntensity = 0; // Intensity of random flickering
|
|
14
23
|
this.init = (particle) => {
|
|
24
|
+
if (!this.enabled)
|
|
25
|
+
return;
|
|
15
26
|
particle.colorStart.copyFrom(this.start);
|
|
16
27
|
particle.colorStart.r += this.varianceFrom(this.startVariance.r);
|
|
17
28
|
particle.colorStart.g += this.varianceFrom(this.startVariance.g);
|
|
@@ -25,18 +36,115 @@ export default class ColorBehaviour extends Behaviour {
|
|
|
25
36
|
particle.color.copyFrom(particle.colorStart);
|
|
26
37
|
};
|
|
27
38
|
this.apply = (particle) => {
|
|
28
|
-
|
|
39
|
+
if (!this.enabled)
|
|
40
|
+
return;
|
|
41
|
+
if (particle.skipColorBehaviour)
|
|
42
|
+
return;
|
|
43
|
+
const { lifeProgress } = particle;
|
|
44
|
+
// Multi-gradient color transitions
|
|
45
|
+
if (this.colorStops.length > 0) {
|
|
46
|
+
this.applyColorStops(particle, lifeProgress);
|
|
47
|
+
if (this.sinus) {
|
|
48
|
+
particle.color.alpha = Math.sin(lifeProgress * 3.1);
|
|
49
|
+
}
|
|
50
|
+
else if (this.fadeToTransparent) {
|
|
51
|
+
particle.color.alpha = (1 - lifeProgress) * this.start.alpha;
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Perlin noise color changes
|
|
56
|
+
if (this.usePerlin) {
|
|
57
|
+
this.applyPerlinColor(particle, lifeProgress);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Default linear gradient behavior
|
|
61
|
+
const { colorStart, colorEnd } = particle;
|
|
62
|
+
let effectiveProgress = lifeProgress;
|
|
63
|
+
// Mirror transition if enabled
|
|
64
|
+
if (this.mirrorTransition) {
|
|
65
|
+
effectiveProgress = lifeProgress < 0.5 ? lifeProgress * 2 : (1 - lifeProgress) * 2;
|
|
66
|
+
}
|
|
29
67
|
particle.color.copyFrom(colorStart);
|
|
30
|
-
particle.color.r += (colorEnd.r - colorStart.r) *
|
|
31
|
-
particle.color.g += (colorEnd.g - colorStart.g) *
|
|
32
|
-
particle.color.b += (colorEnd.b - colorStart.b) *
|
|
68
|
+
particle.color.r += (colorEnd.r - colorStart.r) * effectiveProgress;
|
|
69
|
+
particle.color.g += (colorEnd.g - colorStart.g) * effectiveProgress;
|
|
70
|
+
particle.color.b += (colorEnd.b - colorStart.b) * effectiveProgress;
|
|
33
71
|
if (!this.sinus) {
|
|
34
|
-
particle.color.alpha += (colorEnd.alpha - colorStart.alpha) *
|
|
72
|
+
particle.color.alpha += (colorEnd.alpha - colorStart.alpha) * effectiveProgress;
|
|
35
73
|
}
|
|
36
74
|
else {
|
|
37
|
-
|
|
75
|
+
if (!this.fadeToTransparent) {
|
|
76
|
+
particle.color.alpha = Math.sin(effectiveProgress * 3.1);
|
|
77
|
+
if (particle.color.alpha > particle.superColorAlphaEnd) {
|
|
78
|
+
particle.color.alpha = particle.superColorAlphaEnd;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Apply pulse effect if enabled
|
|
83
|
+
if (this.pulseIntensity > 0) {
|
|
84
|
+
this.applyPulseEffect(particle, lifeProgress);
|
|
85
|
+
}
|
|
86
|
+
// Desaturation (fade to gray)
|
|
87
|
+
if (this.fadeToGray) {
|
|
88
|
+
this.applyFadeToGray(particle);
|
|
89
|
+
}
|
|
90
|
+
// Alpha fading (fade to transparent)
|
|
91
|
+
if (this.fadeToTransparent && !this.sinus) {
|
|
92
|
+
particle.color.alpha = (1 - lifeProgress) * this.start.alpha;
|
|
93
|
+
}
|
|
94
|
+
// Flickering effect
|
|
95
|
+
if (this.flickerIntensity) {
|
|
96
|
+
this.applyFlickering(particle);
|
|
38
97
|
}
|
|
39
98
|
};
|
|
99
|
+
this.applyColorStops = (particle, lifeProgress) => {
|
|
100
|
+
const { colorStops } = this;
|
|
101
|
+
// Ensure at least two color stops exist
|
|
102
|
+
if (colorStops.length < 2) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// Clamp segment to valid range
|
|
106
|
+
const segment = Math.floor(lifeProgress * (colorStops.length - 1));
|
|
107
|
+
const nextSegment = Math.min(segment + 1, colorStops.length - 1); // Prevent out-of-bounds access
|
|
108
|
+
const t = lifeProgress * (colorStops.length - 1) - segment;
|
|
109
|
+
const startColor = colorStops[segment];
|
|
110
|
+
const endColor = colorStops[nextSegment]; // Safely access the next color stop
|
|
111
|
+
particle.color.r = startColor.r + (endColor.r - startColor.r) * t;
|
|
112
|
+
particle.color.g = startColor.g + (endColor.g - startColor.g) * t;
|
|
113
|
+
particle.color.b = startColor.b + (endColor.b - startColor.b) * t;
|
|
114
|
+
particle.color.alpha = startColor.alpha + (endColor.alpha - startColor.alpha) * t;
|
|
115
|
+
};
|
|
116
|
+
this.applyPerlinColor = (particle, lifeProgress) => {
|
|
117
|
+
const time = lifeProgress * 10; // Scale time
|
|
118
|
+
particle.color.r = this.pseudoRandomNoise(time) * 255;
|
|
119
|
+
particle.color.g = this.pseudoRandomNoise(time + 1) * 255;
|
|
120
|
+
particle.color.b = this.pseudoRandomNoise(time + 2) * 255;
|
|
121
|
+
particle.color.alpha = this.pseudoRandomNoise(time + 3);
|
|
122
|
+
};
|
|
123
|
+
this.applyPulseEffect = (particle, lifeProgress) => {
|
|
124
|
+
// Compute pulse value based on life progress, speed, and intensity
|
|
125
|
+
const pulse = 1 + Math.sin(lifeProgress * this.pulseSpeed * Math.PI * 2) * this.pulseIntensity;
|
|
126
|
+
// Apply pulse effect to the color
|
|
127
|
+
particle.color.r = Math.max(0, Math.min(255, particle.color.r * pulse));
|
|
128
|
+
particle.color.g = Math.max(0, Math.min(255, particle.color.g * pulse));
|
|
129
|
+
particle.color.b = Math.max(0, Math.min(255, particle.color.b * pulse));
|
|
130
|
+
};
|
|
131
|
+
this.applyFadeToGray = (particle) => {
|
|
132
|
+
const { color } = particle;
|
|
133
|
+
const gray = (color.r + color.g + color.b) / 3;
|
|
134
|
+
particle.color.r = gray;
|
|
135
|
+
particle.color.g = gray;
|
|
136
|
+
particle.color.b = gray;
|
|
137
|
+
};
|
|
138
|
+
this.applyFlickering = (particle) => {
|
|
139
|
+
const flickerAmount = (Math.random() - 0.5) * this.flickerIntensity * 255;
|
|
140
|
+
particle.color.r = Math.max(0, Math.min(255, particle.color.r + flickerAmount));
|
|
141
|
+
particle.color.g = Math.max(0, Math.min(255, particle.color.g + flickerAmount));
|
|
142
|
+
particle.color.b = Math.max(0, Math.min(255, particle.color.b + flickerAmount));
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
pseudoRandomNoise(seed) {
|
|
146
|
+
const x = Math.sin(seed) * 10000;
|
|
147
|
+
return x - Math.floor(x); // Returns a value between 0 and 1
|
|
40
148
|
}
|
|
41
149
|
getName() {
|
|
42
150
|
return BehaviourNames.COLOR_BEHAVIOUR;
|
|
@@ -52,24 +160,32 @@ export default class ColorBehaviour extends Behaviour {
|
|
|
52
160
|
_alpha: this.start.alpha,
|
|
53
161
|
},
|
|
54
162
|
end: {
|
|
55
|
-
_r: this.
|
|
56
|
-
_g: this.
|
|
57
|
-
_b: this.
|
|
58
|
-
_alpha: this.
|
|
163
|
+
_r: this.end.r,
|
|
164
|
+
_g: this.end.g,
|
|
165
|
+
_b: this.end.b,
|
|
166
|
+
_alpha: this.end.alpha,
|
|
59
167
|
},
|
|
60
168
|
startVariance: {
|
|
61
|
-
_r: this.
|
|
62
|
-
_g: this.
|
|
63
|
-
_b: this.
|
|
64
|
-
_alpha: this.
|
|
169
|
+
_r: this.startVariance.r,
|
|
170
|
+
_g: this.startVariance.g,
|
|
171
|
+
_b: this.startVariance.b,
|
|
172
|
+
_alpha: this.startVariance.alpha,
|
|
65
173
|
},
|
|
66
174
|
endVariance: {
|
|
67
|
-
_r: this.
|
|
68
|
-
_g: this.
|
|
69
|
-
_b: this.
|
|
70
|
-
_alpha: this.
|
|
175
|
+
_r: this.endVariance.r,
|
|
176
|
+
_g: this.endVariance.g,
|
|
177
|
+
_b: this.endVariance.b,
|
|
178
|
+
_alpha: this.endVariance.alpha,
|
|
71
179
|
},
|
|
72
180
|
sinus: this.sinus,
|
|
181
|
+
colorStops: this.colorStops,
|
|
182
|
+
usePerlin: this.usePerlin,
|
|
183
|
+
pulseSpeed: this.pulseSpeed,
|
|
184
|
+
pulseIntensity: this.pulseIntensity,
|
|
185
|
+
mirrorTransition: this.mirrorTransition,
|
|
186
|
+
fadeToGray: this.fadeToGray,
|
|
187
|
+
fadeToTransparent: this.fadeToTransparent,
|
|
188
|
+
flickerIntensity: this.flickerIntensity,
|
|
73
189
|
name: this.getName(),
|
|
74
190
|
};
|
|
75
191
|
}
|