custom-pixi-particles 4.7.0 → 4.9.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 (32) hide show
  1. package/dist/lib/Particle.d.ts +1 -0
  2. package/dist/lib/Particle.js +2 -0
  3. package/dist/lib/Particle.js.map +1 -1
  4. package/dist/lib/behaviour/BehaviourNames.d.ts +7 -2
  5. package/dist/lib/behaviour/BehaviourNames.js +7 -1
  6. package/dist/lib/behaviour/BehaviourNames.js.map +1 -1
  7. package/dist/lib/behaviour/ForceFieldsBehaviour.d.ts +53 -0
  8. package/dist/lib/behaviour/ForceFieldsBehaviour.js +80 -0
  9. package/dist/lib/behaviour/ForceFieldsBehaviour.js.map +1 -0
  10. package/dist/lib/behaviour/GroupingBehaviour.d.ts +57 -0
  11. package/dist/lib/behaviour/GroupingBehaviour.js +141 -0
  12. package/dist/lib/behaviour/GroupingBehaviour.js.map +1 -0
  13. package/dist/lib/behaviour/PositionBehaviour.d.ts +0 -8
  14. package/dist/lib/behaviour/PositionBehaviour.js +0 -45
  15. package/dist/lib/behaviour/PositionBehaviour.js.map +1 -1
  16. package/dist/lib/behaviour/SoundReactiveBehaviour.d.ts +35 -0
  17. package/dist/lib/behaviour/SoundReactiveBehaviour.js +89 -0
  18. package/dist/lib/behaviour/SoundReactiveBehaviour.js.map +1 -0
  19. package/dist/lib/behaviour/SpawnBehaviour.d.ts +113 -0
  20. package/dist/lib/behaviour/SpawnBehaviour.js +254 -0
  21. package/dist/lib/behaviour/SpawnBehaviour.js.map +1 -0
  22. package/dist/lib/behaviour/TimelineBehaviour.d.ts +73 -0
  23. package/dist/lib/behaviour/TimelineBehaviour.js +98 -0
  24. package/dist/lib/behaviour/TimelineBehaviour.js.map +1 -0
  25. package/dist/lib/behaviour/index.d.ts +6 -1
  26. package/dist/lib/behaviour/index.js +6 -1
  27. package/dist/lib/behaviour/index.js.map +1 -1
  28. package/dist/lib/pixi/Renderer.js +14 -6
  29. package/dist/lib/pixi/Renderer.js.map +1 -1
  30. package/dist/lib/pixi/TestRenderer.js +15 -7
  31. package/dist/lib/pixi/TestRenderer.js.map +1 -1
  32. package/package.json +1 -1
@@ -0,0 +1,35 @@
1
+ import { Behaviour } from './index';
2
+ import Particle from '../Particle';
3
+ export default class SoundReactiveBehaviour extends Behaviour {
4
+ enabled: boolean;
5
+ priority: number;
6
+ audioContext: AudioContext | null;
7
+ analyser: AnalyserNode | null;
8
+ frequencyData: Uint8Array | null;
9
+ amplitudeFactor: number;
10
+ frequencyFactor: number;
11
+ beatSensitivity: number;
12
+ init(): void;
13
+ apply(particle: Particle, deltaTime: number): void;
14
+ /**
15
+ * Computes the amplitude (average volume level) from the frequency data.
16
+ */
17
+ getAmplitude(): number;
18
+ /**
19
+ * Finds the dominant frequency (frequency with the highest amplitude).
20
+ */
21
+ getDominantFrequency(): number;
22
+ /**
23
+ * Detects a beat based on amplitude and sensitivity.
24
+ */
25
+ isBeatDetected(amplitude: number): boolean;
26
+ getName(): string;
27
+ getProps(): {
28
+ enabled: boolean;
29
+ priority: number;
30
+ amplitudeFactor: number;
31
+ frequencyFactor: number;
32
+ beatSensitivity: number;
33
+ name: string;
34
+ };
35
+ }
@@ -0,0 +1,89 @@
1
+ import { Behaviour, BehaviourNames } from './index';
2
+ export default class SoundReactiveBehaviour extends Behaviour {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.enabled = true;
6
+ this.priority = 0;
7
+ this.audioContext = null; // Audio context for analysis
8
+ this.analyser = null; // Audio analyser node
9
+ this.frequencyData = null; // Frequency data array
10
+ this.amplitudeFactor = 0.1; // Scale factor for amplitude effects
11
+ this.frequencyFactor = 1; // Scale factor for frequency effects
12
+ this.beatSensitivity = 1; // Sensitivity to detect beats
13
+ }
14
+ init() {
15
+ //
16
+ }
17
+ apply(particle, deltaTime) {
18
+ if (!this.enabled || !this.analyser || !this.frequencyData)
19
+ return;
20
+ // Update frequency data
21
+ this.analyser.getByteFrequencyData(this.frequencyData);
22
+ // Compute amplitude and frequency effects
23
+ const amplitude = this.getAmplitude();
24
+ const dominantFrequency = this.getDominantFrequency();
25
+ // Apply amplitude effect to size
26
+ particle.size.x += amplitude * this.amplitudeFactor * deltaTime;
27
+ particle.size.y += amplitude * this.amplitudeFactor * deltaTime;
28
+ // Apply frequency effect to velocity or position
29
+ particle.velocity.x += dominantFrequency * this.frequencyFactor * deltaTime;
30
+ particle.velocity.y += dominantFrequency * this.frequencyFactor * deltaTime;
31
+ // Add beat reaction if sensitivity is high enough
32
+ if (this.isBeatDetected(amplitude)) {
33
+ particle.color.r = 255; // Flash red on beat
34
+ particle.color.g = 0;
35
+ particle.color.b = 0;
36
+ }
37
+ else {
38
+ particle.color.r = Math.max(0, particle.color.r - 5); // Fade back to normal
39
+ particle.color.g = Math.max(0, particle.color.g - 5);
40
+ particle.color.b = Math.max(0, particle.color.b - 5);
41
+ }
42
+ }
43
+ /**
44
+ * Computes the amplitude (average volume level) from the frequency data.
45
+ */
46
+ getAmplitude() {
47
+ if (!this.frequencyData)
48
+ return 0;
49
+ const sum = this.frequencyData.reduce((a, b) => a + b, 0);
50
+ return sum / this.frequencyData.length;
51
+ }
52
+ /**
53
+ * Finds the dominant frequency (frequency with the highest amplitude).
54
+ */
55
+ getDominantFrequency() {
56
+ var _a, _b, _c, _d;
57
+ if (!this.frequencyData)
58
+ return 0;
59
+ let maxAmplitude = 0;
60
+ let dominantIndex = 0;
61
+ for (let i = 0; i < this.frequencyData.length; i++) {
62
+ if (this.frequencyData[i] > maxAmplitude) {
63
+ maxAmplitude = this.frequencyData[i];
64
+ dominantIndex = i;
65
+ }
66
+ }
67
+ return (dominantIndex * ((_b = (_a = this.analyser) === null || _a === void 0 ? void 0 : _a.context.sampleRate) !== null && _b !== void 0 ? _b : 0)) / ((_d = (_c = this.analyser) === null || _c === void 0 ? void 0 : _c.fftSize) !== null && _d !== void 0 ? _d : 1);
68
+ }
69
+ /**
70
+ * Detects a beat based on amplitude and sensitivity.
71
+ */
72
+ isBeatDetected(amplitude) {
73
+ return amplitude > this.beatSensitivity * 128; // Threshold for beat detection
74
+ }
75
+ getName() {
76
+ return BehaviourNames.SOUND_REACTIVE_BEHAVIOUR;
77
+ }
78
+ getProps() {
79
+ return {
80
+ enabled: this.enabled,
81
+ priority: this.priority,
82
+ amplitudeFactor: this.amplitudeFactor,
83
+ frequencyFactor: this.frequencyFactor,
84
+ beatSensitivity: this.beatSensitivity,
85
+ name: this.getName(),
86
+ };
87
+ }
88
+ }
89
+ //# sourceMappingURL=SoundReactiveBehaviour.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SoundReactiveBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/SoundReactiveBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAGnD,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,SAAS;IAA7D;;QACE,YAAO,GAAG,IAAI,CAAA;QACd,aAAQ,GAAG,CAAC,CAAA;QAEZ,iBAAY,GAAwB,IAAI,CAAA,CAAC,6BAA6B;QACtE,aAAQ,GAAwB,IAAI,CAAA,CAAC,sBAAsB;QAC3D,kBAAa,GAAsB,IAAI,CAAA,CAAC,uBAAuB;QAC/D,oBAAe,GAAG,GAAG,CAAA,CAAC,qCAAqC;QAC3D,oBAAe,GAAG,CAAC,CAAA,CAAC,qCAAqC;QACzD,oBAAe,GAAG,CAAC,CAAA,CAAC,8BAA8B;IAqFpD,CAAC;IAnFC,IAAI;QACF,EAAE;IACJ,CAAC;IAED,KAAK,CAAC,QAAkB,EAAE,SAAiB;QACzC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,aAAa;YAAE,OAAM;QAElE,wBAAwB;QACxB,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;QAEtD,0CAA0C;QAC1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,EAAE,IAAI,CAAC,QAAQ;YACvB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,113 @@
1
+ import { Point } from '../util';
2
+ import { Behaviour } from './index';
3
+ import Particle from '../Particle';
4
+ import Model from '../Model';
5
+ export default class SpawnBehaviour extends Behaviour {
6
+ enabled: boolean;
7
+ priority: number;
8
+ spawnType: string;
9
+ word: string;
10
+ lastWord: string;
11
+ fontSize: number;
12
+ fontSpacing: number;
13
+ particleDensity: number;
14
+ fontMaxWidth: number;
15
+ fontMaxHeight: number;
16
+ textAlign: 'center' | 'end' | 'left' | 'right' | 'start';
17
+ textBaseline: 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top';
18
+ radius: number;
19
+ radiusX: number;
20
+ radiusY: number;
21
+ starPoints: number;
22
+ rows: number;
23
+ columns: number;
24
+ cellSize: number;
25
+ center: {
26
+ x: number;
27
+ y: number;
28
+ z: number;
29
+ };
30
+ apex: {
31
+ x: number;
32
+ y: number;
33
+ z: number;
34
+ };
35
+ spread: number;
36
+ baseRadius: number;
37
+ coneDirection: number;
38
+ height: number;
39
+ coneAngle: number;
40
+ position: Point;
41
+ positionVariance: Point;
42
+ perspective: number;
43
+ maxZ: number;
44
+ /**
45
+ * Initialize particle position based on spawn type
46
+ * @param {Particle} particle - The particle to initialize
47
+ */
48
+ init: (particle: Particle) => void;
49
+ calculateCtx: () => void;
50
+ apply: (particle: Particle, deltaTime: number, model: Model) => void;
51
+ /**
52
+ * Adds a random variance to the given value
53
+ * @param {number} value - The value to calculate
54
+ * @param {number} variance - The random variance to add
55
+ * @returns {number} The calculated value
56
+ */
57
+ calculate: (value: number, variance: number) => number;
58
+ /**
59
+ * Gets the name of the behaviour
60
+ * @return {string} The name of the behaviour
61
+ */
62
+ getName(): string;
63
+ /**
64
+ * @description Retrieves the properties of the object.
65
+ * @returns {Object} The properties of the object.
66
+ */
67
+ getProps(): {
68
+ enabled: boolean;
69
+ priority: number;
70
+ position: {
71
+ x: number;
72
+ y: number;
73
+ };
74
+ positionVariance: {
75
+ x: number;
76
+ y: number;
77
+ };
78
+ spawnType: string;
79
+ word: string;
80
+ fontSize: number;
81
+ fontSpacing: number;
82
+ particleDensity: number;
83
+ fontMaxWidth: number;
84
+ fontMaxHeight: number;
85
+ textAlign: "center" | "end" | "left" | "right" | "start";
86
+ textBaseline: "alphabetic" | "bottom" | "hanging" | "ideographic" | "middle" | "top";
87
+ radius: number;
88
+ radiusX: number;
89
+ radiusY: number;
90
+ starPoints: number;
91
+ rows: number;
92
+ columns: number;
93
+ cellSize: number;
94
+ center: {
95
+ x: number;
96
+ y: number;
97
+ z: number;
98
+ };
99
+ apex: {
100
+ x: number;
101
+ y: number;
102
+ z: number;
103
+ };
104
+ spread: number;
105
+ baseRadius: number;
106
+ coneDirection: number;
107
+ height: number;
108
+ coneAngle: number;
109
+ perspective: number;
110
+ maxZ: number;
111
+ name: string;
112
+ };
113
+ }
@@ -0,0 +1,254 @@
1
+ import { Point } from '../util';
2
+ import { Behaviour, BehaviourNames } from './index';
3
+ let canvas = null;
4
+ let imageData = null;
5
+ let particleCount = 0;
6
+ let pixelPositions = [];
7
+ export default class SpawnBehaviour extends Behaviour {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.enabled = true;
11
+ this.priority = 0;
12
+ this.spawnType = 'Rectangle';
13
+ this.word = 'Hello';
14
+ this.lastWord = '';
15
+ this.fontSize = 50;
16
+ this.fontSpacing = 5;
17
+ this.particleDensity = 1;
18
+ this.fontMaxWidth = 1334;
19
+ this.fontMaxHeight = 750;
20
+ this.textAlign = 'center';
21
+ this.textBaseline = 'middle';
22
+ this.radius = 0;
23
+ this.radiusX = 0;
24
+ this.radiusY = 0;
25
+ this.starPoints = 5;
26
+ this.rows = 10;
27
+ this.columns = 10;
28
+ this.cellSize = 20;
29
+ this.center = { x: 0, y: 0, z: 0 };
30
+ this.apex = { x: 0, y: 0, z: 0 };
31
+ this.spread = 360;
32
+ this.baseRadius = 0;
33
+ this.coneDirection = 0;
34
+ this.height = 0;
35
+ this.coneAngle = 45;
36
+ this.position = new Point();
37
+ this.positionVariance = new Point();
38
+ // Perspective parameters
39
+ this.perspective = 0; // Distance for perspective
40
+ this.maxZ = 0; // Maximum z distance for effects
41
+ /**
42
+ * Initialize particle position based on spawn type
43
+ * @param {Particle} particle - The particle to initialize
44
+ */
45
+ this.init = (particle) => {
46
+ // Reset particles if the word has changed
47
+ if (this.spawnType === 'Word' && this.lastWord !== this.word) {
48
+ this.lastWord = this.word;
49
+ this.calculateCtx();
50
+ particle.reset(); // Reset the particle's position and movement
51
+ }
52
+ // Assign a random z-coordinate within a range
53
+ particle.z = Math.random() * this.maxZ;
54
+ if (this.spawnType === 'Rectangle') {
55
+ particle.movement.x = this.calculate(this.position.x, this.positionVariance.x);
56
+ particle.movement.y = this.calculate(this.position.y, this.positionVariance.y);
57
+ }
58
+ else if (this.spawnType === 'Ring') {
59
+ const angle = Math.random() * Math.PI * 2;
60
+ particle.movement.x = this.calculate(this.position.x, this.positionVariance.x) + Math.cos(angle) * this.radius;
61
+ particle.movement.y = this.calculate(this.position.y, this.positionVariance.y) + Math.sin(angle) * this.radius;
62
+ }
63
+ else if (this.spawnType === 'Star') {
64
+ const points = this.starPoints; // Configurable number of star points
65
+ const angle = (Math.PI * 2 * particle.uid) / points;
66
+ const radius = particle.uid % 2 === 0 ? this.radius : this.radius / 2;
67
+ particle.movement.x = this.calculate(this.position.x, this.positionVariance.x) + Math.cos(angle) * radius;
68
+ particle.movement.y = this.calculate(this.position.y, this.positionVariance.y) + Math.sin(angle) * radius;
69
+ }
70
+ else if (this.spawnType === 'FrameRectangle') {
71
+ const w = this.radiusX;
72
+ const h = this.radiusY;
73
+ if (Math.random() < w / (w + h)) {
74
+ particle.movement.x = Math.random() * w + particle.movement.x;
75
+ particle.movement.y = Math.random() < 0.5 ? particle.movement.y : particle.movement.y + h - 1;
76
+ }
77
+ else {
78
+ particle.movement.y = Math.random() * h + particle.movement.y;
79
+ particle.movement.x = Math.random() < 0.5 ? particle.movement.x : particle.movement.x + w - 1;
80
+ }
81
+ particle.movement.x += this.calculate(this.position.x, this.positionVariance.x);
82
+ particle.movement.y += this.calculate(this.position.y, this.positionVariance.y);
83
+ }
84
+ else if (this.spawnType === 'Frame') {
85
+ const w = this.radius;
86
+ const h = this.radius;
87
+ if (Math.random() < w / (w + h)) {
88
+ particle.movement.x = Math.random() * w + particle.movement.x;
89
+ particle.movement.y = Math.random() < 0.5 ? particle.movement.y : particle.movement.y + h - 1;
90
+ }
91
+ else {
92
+ particle.movement.y = Math.random() * h + particle.movement.y;
93
+ particle.movement.x = Math.random() < 0.5 ? particle.movement.x : particle.movement.x + w - 1;
94
+ }
95
+ particle.movement.x += this.calculate(this.position.x, this.positionVariance.x);
96
+ particle.movement.y += this.calculate(this.position.y, this.positionVariance.y);
97
+ }
98
+ else if (this.spawnType === 'Sphere') {
99
+ const phi = Math.random() * Math.PI * 2; // Random azimuthal angle
100
+ const theta = Math.random() * (this.spread / 180) * Math.PI; // Random polar angle
101
+ particle.movement.x =
102
+ this.calculate(this.position.x, this.positionVariance.x) +
103
+ this.center.x +
104
+ this.radius * Math.sin(theta) * Math.cos(phi);
105
+ particle.movement.y =
106
+ this.calculate(this.position.y, this.positionVariance.y) +
107
+ this.center.y +
108
+ this.radius * Math.sin(theta) * Math.sin(phi);
109
+ particle.z = this.center.z + this.radius * Math.cos(theta);
110
+ }
111
+ else if (this.spawnType === 'Cone') {
112
+ const angle = (Math.random() * this.coneAngle - this.coneAngle / 2) * (Math.PI / 180);
113
+ const distance = Math.random() * this.baseRadius; // Random distance from apex
114
+ const localX = Math.cos(angle) * distance; // Local x position within cone
115
+ const localY = Math.sin(angle) * distance; // Local y position within cone
116
+ // Convert coneDirection to radians
117
+ const coneDirectionRad = (this.coneDirection || 0) * (Math.PI / 180);
118
+ // Apply rotation to align the cone to the specified direction
119
+ particle.movement.x =
120
+ this.calculate(this.position.x, this.positionVariance.x) +
121
+ this.apex.x +
122
+ Math.cos(coneDirectionRad) * localX -
123
+ Math.sin(coneDirectionRad) * localY;
124
+ particle.movement.y =
125
+ this.calculate(this.position.y, this.positionVariance.y) +
126
+ this.apex.y +
127
+ Math.sin(coneDirectionRad) * localX +
128
+ Math.cos(coneDirectionRad) * localY;
129
+ particle.z = this.apex.z + Math.random() * this.height;
130
+ }
131
+ else if (this.spawnType === 'Grid') {
132
+ const row = Math.floor(Math.random() * this.rows);
133
+ const column = Math.floor(Math.random() * this.columns);
134
+ particle.movement.x = this.position.x + column * this.cellSize;
135
+ particle.movement.y = this.position.y + row * this.cellSize;
136
+ }
137
+ else if (this.spawnType === 'Word') {
138
+ if (particleCount > 0 && pixelPositions.length > 0) {
139
+ const selectedPixel = pixelPositions[Math.floor(Math.random() * particleCount)];
140
+ particle.movement.x = this.position.x + selectedPixel.x - canvas.width / 2;
141
+ particle.movement.y = this.position.y + selectedPixel.y - canvas.height / 2;
142
+ // Add a bit of random jitter to make the word more dynamic
143
+ particle.movement.x += Math.random() * this.positionVariance.x - this.positionVariance.x / 2;
144
+ particle.movement.y += Math.random() * this.positionVariance.y - this.positionVariance.y / 2;
145
+ }
146
+ }
147
+ if (this.perspective && this.maxZ) {
148
+ // Apply perspective scaling based on z
149
+ const scale = this.perspective / (this.perspective + particle.z);
150
+ particle.movement.x *= scale;
151
+ particle.movement.y *= scale;
152
+ // Adjust particle opacity based on z
153
+ particle.color.alpha = 1 - particle.z / this.maxZ;
154
+ }
155
+ };
156
+ this.calculateCtx = () => {
157
+ const text = this.word; // The word to render
158
+ const fontSize = this.fontSize; // Font size for rendering
159
+ if (!canvas) {
160
+ canvas = document.createElement('canvas');
161
+ canvas.width = this.fontMaxWidth;
162
+ canvas.height = this.fontMaxHeight;
163
+ }
164
+ const ctx = canvas.getContext('2d');
165
+ ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear the canvas
166
+ ctx.font = `${fontSize}px Arial`;
167
+ ctx.textAlign = this.textAlign;
168
+ ctx.textBaseline = this.textBaseline;
169
+ ctx.fillText(text, canvas.width / 2, canvas.height / 2);
170
+ // Get pixel data
171
+ imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
172
+ const { data, width, height } = imageData;
173
+ const spacing = this.fontSpacing; // Spacing between pixels
174
+ // Find all non-transparent pixels
175
+ pixelPositions = [];
176
+ for (let y = 0; y < height; y += spacing) {
177
+ for (let x = 0; x < width; x += spacing) {
178
+ const index = (y * width + x) * 4;
179
+ if (data[index + 3] > 128) {
180
+ // Alpha channel > 128 means this pixel is part of the text
181
+ pixelPositions.push(new Point(x, y));
182
+ }
183
+ }
184
+ }
185
+ pixelPositions = pixelPositions.sort(() => Math.random() - 0.5);
186
+ // Use particleDensity to limit the number of particles
187
+ particleCount = Math.floor(pixelPositions.length * this.particleDensity);
188
+ };
189
+ this.apply = (particle, deltaTime, model) => {
190
+ // No updates here for now
191
+ };
192
+ /**
193
+ * Adds a random variance to the given value
194
+ * @param {number} value - The value to calculate
195
+ * @param {number} variance - The random variance to add
196
+ * @returns {number} The calculated value
197
+ */
198
+ this.calculate = (value, variance) => {
199
+ return value + this.varianceFrom(variance);
200
+ };
201
+ }
202
+ /**
203
+ * Gets the name of the behaviour
204
+ * @return {string} The name of the behaviour
205
+ */
206
+ getName() {
207
+ return BehaviourNames.SPAWN_BEHAVIOUR;
208
+ }
209
+ /**
210
+ * @description Retrieves the properties of the object.
211
+ * @returns {Object} The properties of the object.
212
+ */
213
+ getProps() {
214
+ return {
215
+ enabled: this.enabled,
216
+ priority: this.priority,
217
+ position: {
218
+ x: this.position.x,
219
+ y: this.position.y,
220
+ },
221
+ positionVariance: {
222
+ x: this.positionVariance.x,
223
+ y: this.positionVariance.y,
224
+ },
225
+ spawnType: this.spawnType,
226
+ word: this.word,
227
+ fontSize: this.fontSize,
228
+ fontSpacing: this.fontSpacing,
229
+ particleDensity: this.particleDensity,
230
+ fontMaxWidth: this.fontMaxWidth,
231
+ fontMaxHeight: this.fontMaxHeight,
232
+ textAlign: this.textAlign,
233
+ textBaseline: this.textBaseline,
234
+ radius: this.radius,
235
+ radiusX: this.radiusX,
236
+ radiusY: this.radiusY,
237
+ starPoints: this.starPoints,
238
+ rows: this.rows,
239
+ columns: this.columns,
240
+ cellSize: this.cellSize,
241
+ center: this.center,
242
+ apex: this.apex,
243
+ spread: this.spread,
244
+ baseRadius: this.baseRadius,
245
+ coneDirection: this.coneDirection,
246
+ height: this.height,
247
+ coneAngle: this.coneAngle,
248
+ perspective: this.perspective,
249
+ maxZ: this.maxZ,
250
+ name: this.getName(),
251
+ };
252
+ }
253
+ }
254
+ //# sourceMappingURL=SpawnBehaviour.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpawnBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/SpawnBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAInD,IAAI,MAAM,GAAQ,IAAI,CAAA;AACtB,IAAI,SAAS,GAAQ,IAAI,CAAA;AACzB,IAAI,aAAa,GAAQ,CAAC,CAAA;AAC1B,IAAI,cAAc,GAAY,EAAE,CAAA;AAEhC,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,SAAS;IAArD;;QACE,YAAO,GAAY,IAAI,CAAA;QACvB,aAAQ,GAAG,CAAC,CAAA;QACZ,cAAS,GAAW,WAAW,CAAA;QAC/B,SAAI,GAAW,OAAO,CAAA;QACtB,aAAQ,GAAW,EAAE,CAAA;QACrB,aAAQ,GAAG,EAAE,CAAA;QACb,gBAAW,GAAG,CAAC,CAAA;QACf,oBAAe,GAAG,CAAC,CAAA;QACnB,iBAAY,GAAG,IAAI,CAAA;Q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IAAI;YACf,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,73 @@
1
+ import Particle from '../Particle';
2
+ import Behaviour from './Behaviour';
3
+ export default class TimelineBehaviour extends Behaviour {
4
+ enabled: boolean;
5
+ priority: number;
6
+ timeline: {
7
+ time: number;
8
+ properties: {
9
+ size?: number;
10
+ color?: {
11
+ r: number;
12
+ g: number;
13
+ b: number;
14
+ alpha: number;
15
+ };
16
+ rotation?: number;
17
+ };
18
+ }[];
19
+ init(particle: Particle): void;
20
+ apply(particle: Particle, deltaTime: number): void;
21
+ interpolateProperties(particle: Particle, before: {
22
+ size?: number;
23
+ color?: {
24
+ r: number;
25
+ g: number;
26
+ b: number;
27
+ alpha: number;
28
+ };
29
+ rotation?: number;
30
+ }, after: {
31
+ size?: number;
32
+ color?: {
33
+ r: number;
34
+ g: number;
35
+ b: number;
36
+ alpha: number;
37
+ };
38
+ rotation?: number;
39
+ }, progress: number): void;
40
+ setProperties(particle: Particle, properties: {
41
+ size?: number;
42
+ color?: {
43
+ r: number;
44
+ g: number;
45
+ b: number;
46
+ alpha: number;
47
+ };
48
+ rotation?: number;
49
+ }): void;
50
+ /**
51
+ * Linear interpolation (lerp) function
52
+ */
53
+ lerp(start: number, end: number, t: number): number;
54
+ getName(): string;
55
+ getProps(): {
56
+ enabled: boolean;
57
+ priority: number;
58
+ timeline: {
59
+ time: number;
60
+ properties: {
61
+ size?: number;
62
+ color?: {
63
+ r: number;
64
+ g: number;
65
+ b: number;
66
+ alpha: number;
67
+ };
68
+ rotation?: number;
69
+ };
70
+ }[];
71
+ name: string;
72
+ };
73
+ }