@tsparticles/plugin-emitters 3.0.0-alpha.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/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/EmitterContainer.js +1 -0
- package/browser/EmitterInstance.js +257 -0
- package/browser/Emitters.js +119 -0
- package/browser/EmittersEngine.js +1 -0
- package/browser/Enums/EmitterClickMode.js +1 -0
- package/browser/Enums/EmitterShapeType.js +1 -0
- package/browser/IEmitterShape.js +1 -0
- package/browser/Options/Classes/Emitter.js +62 -0
- package/browser/Options/Classes/EmitterLife.js +22 -0
- package/browser/Options/Classes/EmitterRate.js +18 -0
- package/browser/Options/Classes/EmitterSize.js +21 -0
- package/browser/Options/Interfaces/IEmitter.js +1 -0
- package/browser/Options/Interfaces/IEmitterLife.js +1 -0
- package/browser/Options/Interfaces/IEmitterRate.js +1 -0
- package/browser/Options/Interfaces/IEmitterSize.js +1 -0
- package/browser/ShapeManager.js +17 -0
- package/browser/Shapes/Circle/CircleShape.js +24 -0
- package/browser/Shapes/Square/SquareShape.js +40 -0
- package/browser/index.js +113 -0
- package/browser/types.js +1 -0
- package/cjs/EmitterContainer.js +2 -0
- package/cjs/EmitterInstance.js +261 -0
- package/cjs/Emitters.js +134 -0
- package/cjs/EmittersEngine.js +2 -0
- package/cjs/Enums/EmitterClickMode.js +2 -0
- package/cjs/Enums/EmitterShapeType.js +2 -0
- package/cjs/IEmitterShape.js +2 -0
- package/cjs/Options/Classes/Emitter.js +66 -0
- package/cjs/Options/Classes/EmitterLife.js +26 -0
- package/cjs/Options/Classes/EmitterRate.js +22 -0
- package/cjs/Options/Classes/EmitterSize.js +25 -0
- package/cjs/Options/Interfaces/IEmitter.js +2 -0
- package/cjs/Options/Interfaces/IEmitterLife.js +2 -0
- package/cjs/Options/Interfaces/IEmitterRate.js +2 -0
- package/cjs/Options/Interfaces/IEmitterSize.js +2 -0
- package/cjs/ShapeManager.js +21 -0
- package/cjs/Shapes/Circle/CircleShape.js +28 -0
- package/cjs/Shapes/Square/SquareShape.js +44 -0
- package/cjs/index.js +142 -0
- package/cjs/types.js +2 -0
- package/esm/EmitterContainer.js +1 -0
- package/esm/EmitterInstance.js +257 -0
- package/esm/Emitters.js +119 -0
- package/esm/EmittersEngine.js +1 -0
- package/esm/Enums/EmitterClickMode.js +1 -0
- package/esm/Enums/EmitterShapeType.js +1 -0
- package/esm/IEmitterShape.js +1 -0
- package/esm/Options/Classes/Emitter.js +62 -0
- package/esm/Options/Classes/EmitterLife.js +22 -0
- package/esm/Options/Classes/EmitterRate.js +18 -0
- package/esm/Options/Classes/EmitterSize.js +21 -0
- package/esm/Options/Interfaces/IEmitter.js +1 -0
- package/esm/Options/Interfaces/IEmitterLife.js +1 -0
- package/esm/Options/Interfaces/IEmitterRate.js +1 -0
- package/esm/Options/Interfaces/IEmitterSize.js +1 -0
- package/esm/ShapeManager.js +17 -0
- package/esm/Shapes/Circle/CircleShape.js +24 -0
- package/esm/Shapes/Square/SquareShape.js +40 -0
- package/esm/index.js +113 -0
- package/esm/types.js +1 -0
- package/package.json +81 -0
- package/report.html +39 -0
- package/tsparticles.plugin.emitters.js +794 -0
- package/tsparticles.plugin.emitters.min.js +2 -0
- package/tsparticles.plugin.emitters.min.js.LICENSE.txt +8 -0
- package/types/EmitterContainer.d.ts +12 -0
- package/types/EmitterInstance.d.ts +46 -0
- package/types/Emitters.d.ts +24 -0
- package/types/EmittersEngine.d.ts +7 -0
- package/types/Enums/EmitterClickMode.d.ts +3 -0
- package/types/Enums/EmitterShapeType.d.ts +4 -0
- package/types/IEmitterShape.d.ts +4 -0
- package/types/Options/Classes/Emitter.d.ts +24 -0
- package/types/Options/Classes/EmitterLife.d.ts +10 -0
- package/types/Options/Classes/EmitterRate.d.ts +8 -0
- package/types/Options/Classes/EmitterSize.d.ts +10 -0
- package/types/Options/Interfaces/IEmitter.d.ts +20 -0
- package/types/Options/Interfaces/IEmitterLife.d.ts +6 -0
- package/types/Options/Interfaces/IEmitterRate.d.ts +5 -0
- package/types/Options/Interfaces/IEmitterSize.d.ts +4 -0
- package/types/ShapeManager.d.ts +9 -0
- package/types/Shapes/Circle/CircleShape.d.ts +5 -0
- package/types/Shapes/Square/SquareShape.d.ts +5 -0
- package/types/index.d.ts +6 -0
- package/types/types.d.ts +31 -0
- package/umd/EmitterContainer.js +12 -0
- package/umd/EmitterInstance.js +271 -0
- package/umd/Emitters.js +133 -0
- package/umd/EmittersEngine.js +12 -0
- package/umd/Enums/EmitterClickMode.js +12 -0
- package/umd/Enums/EmitterShapeType.js +12 -0
- package/umd/IEmitterShape.js +12 -0
- package/umd/Options/Classes/Emitter.js +76 -0
- package/umd/Options/Classes/EmitterLife.js +36 -0
- package/umd/Options/Classes/EmitterRate.js +32 -0
- package/umd/Options/Classes/EmitterSize.js +35 -0
- package/umd/Options/Interfaces/IEmitter.js +12 -0
- package/umd/Options/Interfaces/IEmitterLife.js +12 -0
- package/umd/Options/Interfaces/IEmitterRate.js +12 -0
- package/umd/Options/Interfaces/IEmitterSize.js +12 -0
- package/umd/ShapeManager.js +31 -0
- package/umd/Shapes/Circle/CircleShape.js +38 -0
- package/umd/Shapes/Square/SquareShape.js +54 -0
- package/umd/index.js +141 -0
- package/umd/types.js +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Emitters Plugin
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/tsparticles-plugin-emitters)
|
|
6
|
+
[](https://www.npmjs.com/package/tsparticles-plugin-emitters)
|
|
7
|
+
[](https://www.npmjs.com/package/tsparticles-plugin-emitters) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) plugin for particles emitters.
|
|
10
|
+
|
|
11
|
+
## How to use it
|
|
12
|
+
|
|
13
|
+
### CDN / Vanilla JS / jQuery
|
|
14
|
+
|
|
15
|
+
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
16
|
+
|
|
17
|
+
Including the `tsparticles.plugin.emitters.min.js` file will export the function to load the plugin:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
loadEmittersPlugin;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the plugin like this:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadEmittersPlugin(tsParticles);
|
|
30
|
+
|
|
31
|
+
await tsParticles.load({
|
|
32
|
+
id: "tsparticles",
|
|
33
|
+
options: {
|
|
34
|
+
/* options */
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
})();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### ESM / CommonJS
|
|
41
|
+
|
|
42
|
+
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
$ npm install tsparticles-plugin-emitters
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add tsparticles-plugin-emitters
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then you need to import it in the app, like this:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const { tsParticles } = require("tsparticles-engine");
|
|
58
|
+
const { loadEmittersPlugin } = require("tsparticles-plugin-emitters");
|
|
59
|
+
|
|
60
|
+
loadEmittersPlugin(tsParticles);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { tsParticles } from "tsparticles-engine";
|
|
67
|
+
import { loadEmittersPlugin } from "tsparticles-plugin-emitters";
|
|
68
|
+
|
|
69
|
+
loadEmittersPlugin(tsParticles);
|
|
70
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
|
+
import { Emitter } from "./Options/Classes/Emitter";
|
|
3
|
+
import { EmitterSize } from "./Options/Classes/EmitterSize";
|
|
4
|
+
export class EmitterInstance {
|
|
5
|
+
constructor(engine, emitters, container, options, position) {
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
7
|
+
var _h;
|
|
8
|
+
this.emitters = emitters;
|
|
9
|
+
this.container = container;
|
|
10
|
+
this._engine = engine;
|
|
11
|
+
this._currentDuration = 0;
|
|
12
|
+
this._currentEmitDelay = 0;
|
|
13
|
+
this._currentSpawnDelay = 0;
|
|
14
|
+
this._initialPosition = position;
|
|
15
|
+
if (options instanceof Emitter) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.options = new Emitter();
|
|
20
|
+
this.options.load(options);
|
|
21
|
+
}
|
|
22
|
+
this._spawnDelay = (((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000) / this.container.retina.reduceFactor;
|
|
23
|
+
this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
|
|
24
|
+
this.name = this.options.name;
|
|
25
|
+
this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
|
|
26
|
+
this.fill = this.options.fill;
|
|
27
|
+
this._firstSpawn = !this.options.life.wait;
|
|
28
|
+
this._startParticlesAdded = false;
|
|
29
|
+
let particlesOptions = deepExtend({}, this.options.particles);
|
|
30
|
+
particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : (particlesOptions = {});
|
|
31
|
+
(_d = particlesOptions.move) !== null && _d !== void 0 ? _d : (particlesOptions.move = {});
|
|
32
|
+
(_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : (_h.direction = this.options.direction);
|
|
33
|
+
if (this.options.spawnColor) {
|
|
34
|
+
this.spawnColor = rangeColorToHsl(this.options.spawnColor);
|
|
35
|
+
}
|
|
36
|
+
this._paused = !this.options.autoPlay;
|
|
37
|
+
this._particlesOptions = particlesOptions;
|
|
38
|
+
this.size =
|
|
39
|
+
(_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
|
|
40
|
+
const size = new EmitterSize();
|
|
41
|
+
size.load({
|
|
42
|
+
height: 0,
|
|
43
|
+
mode: "percent",
|
|
44
|
+
width: 0,
|
|
45
|
+
});
|
|
46
|
+
return size;
|
|
47
|
+
})();
|
|
48
|
+
this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
|
|
49
|
+
this._immortal = this._lifeCount <= 0;
|
|
50
|
+
this._engine.dispatchEvent("emitterCreated", {
|
|
51
|
+
container,
|
|
52
|
+
data: {
|
|
53
|
+
emitter: this,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
this.play();
|
|
57
|
+
}
|
|
58
|
+
externalPause() {
|
|
59
|
+
this._paused = true;
|
|
60
|
+
this.pause();
|
|
61
|
+
}
|
|
62
|
+
externalPlay() {
|
|
63
|
+
this._paused = false;
|
|
64
|
+
this.play();
|
|
65
|
+
}
|
|
66
|
+
getPosition() {
|
|
67
|
+
if (this.options.domId) {
|
|
68
|
+
const container = this.container, element = document.getElementById(this.options.domId);
|
|
69
|
+
if (element) {
|
|
70
|
+
const elRect = element.getBoundingClientRect();
|
|
71
|
+
return {
|
|
72
|
+
x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio,
|
|
73
|
+
y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return this.position;
|
|
78
|
+
}
|
|
79
|
+
getSize() {
|
|
80
|
+
const container = this.container;
|
|
81
|
+
if (this.options.domId) {
|
|
82
|
+
const element = document.getElementById(this.options.domId);
|
|
83
|
+
if (element) {
|
|
84
|
+
const elRect = element.getBoundingClientRect();
|
|
85
|
+
return {
|
|
86
|
+
width: elRect.width * container.retina.pixelRatio,
|
|
87
|
+
height: elRect.height * container.retina.pixelRatio,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
width: this.size.mode === "percent"
|
|
93
|
+
? (container.canvas.size.width * this.size.width) / 100
|
|
94
|
+
: this.size.width,
|
|
95
|
+
height: this.size.mode === "percent"
|
|
96
|
+
? (container.canvas.size.height * this.size.height) / 100
|
|
97
|
+
: this.size.height,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
pause() {
|
|
101
|
+
if (this._paused) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
delete this._emitDelay;
|
|
105
|
+
}
|
|
106
|
+
play() {
|
|
107
|
+
var _a;
|
|
108
|
+
if (this._paused) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!(this.container.retina.reduceFactor &&
|
|
112
|
+
(this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
|
|
113
|
+
(this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (this._emitDelay === undefined) {
|
|
117
|
+
const delay = getRangeValue(this.options.rate.delay);
|
|
118
|
+
this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor;
|
|
119
|
+
}
|
|
120
|
+
if (this._lifeCount > 0 || this._immortal) {
|
|
121
|
+
this.prepareToDie();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
resize() {
|
|
125
|
+
const initialPosition = this._initialPosition;
|
|
126
|
+
this.position =
|
|
127
|
+
initialPosition && isPointInside(initialPosition, this.container.canvas.size, Vector.origin)
|
|
128
|
+
? initialPosition
|
|
129
|
+
: this.calcPosition();
|
|
130
|
+
}
|
|
131
|
+
update(delta) {
|
|
132
|
+
var _a, _b, _c;
|
|
133
|
+
if (this._paused) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (this._firstSpawn) {
|
|
137
|
+
this._firstSpawn = false;
|
|
138
|
+
this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
|
|
139
|
+
this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
|
|
140
|
+
}
|
|
141
|
+
if (!this._startParticlesAdded) {
|
|
142
|
+
this._startParticlesAdded = true;
|
|
143
|
+
this.emitParticles(this.options.startCount);
|
|
144
|
+
}
|
|
145
|
+
if (this._duration !== undefined) {
|
|
146
|
+
this._currentDuration += delta.value;
|
|
147
|
+
if (this._currentDuration >= this._duration) {
|
|
148
|
+
this.pause();
|
|
149
|
+
if (this._spawnDelay !== undefined) {
|
|
150
|
+
delete this._spawnDelay;
|
|
151
|
+
}
|
|
152
|
+
if (!this._immortal) {
|
|
153
|
+
this._lifeCount--;
|
|
154
|
+
}
|
|
155
|
+
if (this._lifeCount > 0 || this._immortal) {
|
|
156
|
+
this.position = this.calcPosition();
|
|
157
|
+
this._spawnDelay = (((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000) / this.container.retina.reduceFactor;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
this.destroy();
|
|
161
|
+
}
|
|
162
|
+
this._currentDuration -= this._duration;
|
|
163
|
+
delete this._duration;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (this._spawnDelay !== undefined) {
|
|
167
|
+
this._currentSpawnDelay += delta.value;
|
|
168
|
+
if (this._currentSpawnDelay >= this._spawnDelay) {
|
|
169
|
+
this._engine.dispatchEvent("emitterPlay", {
|
|
170
|
+
container: this.container,
|
|
171
|
+
});
|
|
172
|
+
this.play();
|
|
173
|
+
this._currentSpawnDelay -= this._currentSpawnDelay;
|
|
174
|
+
delete this._spawnDelay;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (this._emitDelay !== undefined) {
|
|
178
|
+
this._currentEmitDelay += delta.value;
|
|
179
|
+
if (this._currentEmitDelay >= this._emitDelay) {
|
|
180
|
+
this.emit();
|
|
181
|
+
this._currentEmitDelay -= this._emitDelay;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
calcPosition() {
|
|
186
|
+
return calcPositionOrRandomFromSizeRanged({
|
|
187
|
+
size: this.container.canvas.size,
|
|
188
|
+
position: this.options.position,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
destroy() {
|
|
192
|
+
this.emitters.removeEmitter(this);
|
|
193
|
+
this._engine.dispatchEvent("emitterDestroyed", {
|
|
194
|
+
container: this.container,
|
|
195
|
+
data: {
|
|
196
|
+
emitter: this,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
emit() {
|
|
201
|
+
if (this._paused) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const quantity = getRangeValue(this.options.rate.quantity);
|
|
205
|
+
this.emitParticles(quantity);
|
|
206
|
+
}
|
|
207
|
+
emitParticles(quantity) {
|
|
208
|
+
var _a, _b, _c;
|
|
209
|
+
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions);
|
|
210
|
+
for (let i = 0; i < quantity; i++) {
|
|
211
|
+
const particlesOptions = deepExtend({}, singleParticlesOptions);
|
|
212
|
+
if (this.spawnColor) {
|
|
213
|
+
const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
|
|
214
|
+
if (hslAnimation) {
|
|
215
|
+
this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
|
|
216
|
+
this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
|
|
217
|
+
this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
|
|
218
|
+
}
|
|
219
|
+
if (!particlesOptions.color) {
|
|
220
|
+
particlesOptions.color = {
|
|
221
|
+
value: this.spawnColor,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
particlesOptions.color.value = this.spawnColor;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (!position) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
|
|
232
|
+
this.container.particles.addParticle(pPosition, particlesOptions);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
prepareToDie() {
|
|
236
|
+
var _a;
|
|
237
|
+
if (this._paused) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
|
|
241
|
+
if (this.container.retina.reduceFactor &&
|
|
242
|
+
(this._lifeCount > 0 || this._immortal) &&
|
|
243
|
+
duration !== undefined &&
|
|
244
|
+
duration > 0) {
|
|
245
|
+
this._duration = duration * 1000;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
setColorAnimation(animation, initValue, maxValue) {
|
|
249
|
+
var _a;
|
|
250
|
+
const container = this.container;
|
|
251
|
+
if (!animation.enable) {
|
|
252
|
+
return initValue;
|
|
253
|
+
}
|
|
254
|
+
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = getRangeValue((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
|
|
255
|
+
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { arrayRandomIndex, executeOnSingleOrMultiple, itemFromArray } from "@tsparticles/engine";
|
|
2
|
+
import { Emitter } from "./Options/Classes/Emitter";
|
|
3
|
+
import { EmitterInstance } from "./EmitterInstance";
|
|
4
|
+
export class Emitters {
|
|
5
|
+
constructor(engine, container) {
|
|
6
|
+
this.container = container;
|
|
7
|
+
this._engine = engine;
|
|
8
|
+
this.array = [];
|
|
9
|
+
this.emitters = [];
|
|
10
|
+
this.interactivityEmitters = {
|
|
11
|
+
random: {
|
|
12
|
+
count: 1,
|
|
13
|
+
enable: false,
|
|
14
|
+
},
|
|
15
|
+
value: [],
|
|
16
|
+
};
|
|
17
|
+
container.getEmitter = (idxOrName) => idxOrName === undefined || typeof idxOrName === "number"
|
|
18
|
+
? this.array[idxOrName || 0]
|
|
19
|
+
: this.array.find((t) => t.name === idxOrName);
|
|
20
|
+
container.addEmitter = (options, position) => this.addEmitter(options, position);
|
|
21
|
+
container.removeEmitter = (idxOrName) => {
|
|
22
|
+
const emitter = container.getEmitter(idxOrName);
|
|
23
|
+
if (emitter) {
|
|
24
|
+
this.removeEmitter(emitter);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
container.playEmitter = (idxOrName) => {
|
|
28
|
+
const emitter = container.getEmitter(idxOrName);
|
|
29
|
+
if (emitter) {
|
|
30
|
+
emitter.externalPlay();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
container.pauseEmitter = (idxOrName) => {
|
|
34
|
+
const emitter = container.getEmitter(idxOrName);
|
|
35
|
+
if (emitter) {
|
|
36
|
+
emitter.externalPause();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
addEmitter(options, position) {
|
|
41
|
+
const emitterOptions = new Emitter();
|
|
42
|
+
emitterOptions.load(options);
|
|
43
|
+
const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position);
|
|
44
|
+
this.array.push(emitter);
|
|
45
|
+
return emitter;
|
|
46
|
+
}
|
|
47
|
+
handleClickMode(mode) {
|
|
48
|
+
const emitterOptions = this.emitters, modeEmitters = this.interactivityEmitters;
|
|
49
|
+
if (mode === "emitter") {
|
|
50
|
+
let emittersModeOptions;
|
|
51
|
+
if (modeEmitters && modeEmitters.value instanceof Array) {
|
|
52
|
+
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
|
|
53
|
+
emittersModeOptions = [];
|
|
54
|
+
const usedIndexes = [];
|
|
55
|
+
for (let i = 0; i < modeEmitters.random.count; i++) {
|
|
56
|
+
const idx = arrayRandomIndex(modeEmitters.value);
|
|
57
|
+
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
|
|
58
|
+
i--;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
usedIndexes.push(idx);
|
|
62
|
+
emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
emittersModeOptions = modeEmitters.value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
|
|
71
|
+
}
|
|
72
|
+
const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
|
|
73
|
+
executeOnSingleOrMultiple(emittersOptions, (emitter) => {
|
|
74
|
+
this.addEmitter(emitter, ePosition);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async init() {
|
|
79
|
+
this.emitters = this.container.actualOptions.emitters;
|
|
80
|
+
this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
|
|
81
|
+
if (this.emitters instanceof Array) {
|
|
82
|
+
for (const emitterOptions of this.emitters) {
|
|
83
|
+
this.addEmitter(emitterOptions);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.addEmitter(this.emitters);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
pause() {
|
|
91
|
+
for (const emitter of this.array) {
|
|
92
|
+
emitter.pause();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
play() {
|
|
96
|
+
for (const emitter of this.array) {
|
|
97
|
+
emitter.play();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
removeEmitter(emitter) {
|
|
101
|
+
const index = this.array.indexOf(emitter);
|
|
102
|
+
if (index >= 0) {
|
|
103
|
+
this.array.splice(index, 1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
resize() {
|
|
107
|
+
for (const emitter of this.array) {
|
|
108
|
+
emitter.resize();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
stop() {
|
|
112
|
+
this.array = [];
|
|
113
|
+
}
|
|
114
|
+
update(delta) {
|
|
115
|
+
for (const emitter of this.array) {
|
|
116
|
+
emitter.update(delta);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { EmitterLife } from "./EmitterLife";
|
|
3
|
+
import { EmitterRate } from "./EmitterRate";
|
|
4
|
+
import { EmitterSize } from "./EmitterSize";
|
|
5
|
+
export class Emitter {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.autoPlay = true;
|
|
8
|
+
this.fill = true;
|
|
9
|
+
this.life = new EmitterLife();
|
|
10
|
+
this.rate = new EmitterRate();
|
|
11
|
+
this.shape = "square";
|
|
12
|
+
this.startCount = 0;
|
|
13
|
+
}
|
|
14
|
+
load(data) {
|
|
15
|
+
if (data === undefined) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (data.autoPlay !== undefined) {
|
|
19
|
+
this.autoPlay = data.autoPlay;
|
|
20
|
+
}
|
|
21
|
+
if (data.size !== undefined) {
|
|
22
|
+
if (this.size === undefined) {
|
|
23
|
+
this.size = new EmitterSize();
|
|
24
|
+
}
|
|
25
|
+
this.size.load(data.size);
|
|
26
|
+
}
|
|
27
|
+
if (data.direction !== undefined) {
|
|
28
|
+
this.direction = data.direction;
|
|
29
|
+
}
|
|
30
|
+
this.domId = data.domId;
|
|
31
|
+
if (data.fill !== undefined) {
|
|
32
|
+
this.fill = data.fill;
|
|
33
|
+
}
|
|
34
|
+
this.life.load(data.life);
|
|
35
|
+
this.name = data.name;
|
|
36
|
+
this.particles = executeOnSingleOrMultiple(data.particles, (particles) => {
|
|
37
|
+
return deepExtend({}, particles);
|
|
38
|
+
});
|
|
39
|
+
this.rate.load(data.rate);
|
|
40
|
+
if (data.shape !== undefined) {
|
|
41
|
+
this.shape = data.shape;
|
|
42
|
+
}
|
|
43
|
+
if (data.position !== undefined) {
|
|
44
|
+
this.position = {};
|
|
45
|
+
if (data.position.x !== undefined) {
|
|
46
|
+
this.position.x = setRangeValue(data.position.x);
|
|
47
|
+
}
|
|
48
|
+
if (data.position.y !== undefined) {
|
|
49
|
+
this.position.y = setRangeValue(data.position.y);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (data.spawnColor !== undefined) {
|
|
53
|
+
if (this.spawnColor === undefined) {
|
|
54
|
+
this.spawnColor = new AnimatableColor();
|
|
55
|
+
}
|
|
56
|
+
this.spawnColor.load(data.spawnColor);
|
|
57
|
+
}
|
|
58
|
+
if (data.startCount !== undefined) {
|
|
59
|
+
this.startCount = data.startCount;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class EmitterLife {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.wait = false;
|
|
4
|
+
}
|
|
5
|
+
load(data) {
|
|
6
|
+
if (data === undefined) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (data.count !== undefined) {
|
|
10
|
+
this.count = data.count;
|
|
11
|
+
}
|
|
12
|
+
if (data.delay !== undefined) {
|
|
13
|
+
this.delay = data.delay;
|
|
14
|
+
}
|
|
15
|
+
if (data.duration !== undefined) {
|
|
16
|
+
this.duration = data.duration;
|
|
17
|
+
}
|
|
18
|
+
if (data.wait !== undefined) {
|
|
19
|
+
this.wait = data.wait;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
export class EmitterRate {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.quantity = 1;
|
|
5
|
+
this.delay = 0.1;
|
|
6
|
+
}
|
|
7
|
+
load(data) {
|
|
8
|
+
if (data === undefined) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (data.quantity !== undefined) {
|
|
12
|
+
this.quantity = setRangeValue(data.quantity);
|
|
13
|
+
}
|
|
14
|
+
if (data.delay !== undefined) {
|
|
15
|
+
this.delay = setRangeValue(data.delay);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class EmitterSize {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.mode = "percent";
|
|
4
|
+
this.height = 0;
|
|
5
|
+
this.width = 0;
|
|
6
|
+
}
|
|
7
|
+
load(data) {
|
|
8
|
+
if (data === undefined) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (data.mode !== undefined) {
|
|
12
|
+
this.mode = data.mode;
|
|
13
|
+
}
|
|
14
|
+
if (data.height !== undefined) {
|
|
15
|
+
this.height = data.height;
|
|
16
|
+
}
|
|
17
|
+
if (data.width !== undefined) {
|
|
18
|
+
this.width = data.width;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const shapes = new Map();
|
|
2
|
+
export class ShapeManager {
|
|
3
|
+
constructor(engine) {
|
|
4
|
+
this._engine = engine;
|
|
5
|
+
}
|
|
6
|
+
addShape(name, drawer) {
|
|
7
|
+
if (!this.getShape(name)) {
|
|
8
|
+
shapes.set(name, drawer);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
getShape(name) {
|
|
12
|
+
return shapes.get(name);
|
|
13
|
+
}
|
|
14
|
+
getSupportedShapes() {
|
|
15
|
+
return shapes.keys();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getRandom } from "@tsparticles/engine";
|
|
2
|
+
export class CircleShape {
|
|
3
|
+
randomPosition(position, size, fill) {
|
|
4
|
+
const generateTheta = (x, y) => {
|
|
5
|
+
const u = getRandom() / 4.0, theta = Math.atan((y / x) * Math.tan(2 * Math.PI * u)), v = getRandom();
|
|
6
|
+
if (v < 0.25) {
|
|
7
|
+
return theta;
|
|
8
|
+
}
|
|
9
|
+
else if (v < 0.5) {
|
|
10
|
+
return Math.PI - theta;
|
|
11
|
+
}
|
|
12
|
+
else if (v < 0.75) {
|
|
13
|
+
return Math.PI + theta;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return -theta;
|
|
17
|
+
}
|
|
18
|
+
}, radius = (x, y, theta) => (x * y) / Math.sqrt((y * Math.cos(theta)) ** 2 + (x * Math.sin(theta)) ** 2), [a, b] = [size.width / 2, size.height / 2], randomTheta = generateTheta(a, b), maxRadius = radius(a, b, randomTheta), randomRadius = fill ? maxRadius * Math.sqrt(getRandom()) : maxRadius;
|
|
19
|
+
return {
|
|
20
|
+
x: position.x + randomRadius * Math.cos(randomTheta),
|
|
21
|
+
y: position.y + randomRadius * Math.sin(randomTheta),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|