@tsparticles/engine 4.0.0-alpha.8 → 4.0.0-beta.1
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/155.min.js +1 -0
- package/README.md +41 -28
- package/browser/Core/CanvasManager.js +303 -0
- package/browser/Core/Container.js +134 -101
- package/browser/Core/Engine.js +29 -162
- package/browser/Core/Particle.js +197 -183
- package/browser/Core/ParticlesManager.js +363 -0
- package/browser/Core/RenderManager.js +303 -0
- package/browser/Core/Retina.js +6 -6
- package/browser/Core/Utils/Constants.js +2 -2
- package/browser/Core/Utils/EventListeners.js +67 -63
- package/browser/Core/Utils/PluginManager.js +145 -0
- package/browser/Core/Utils/Ranges.js +29 -10
- package/browser/Core/Utils/SpatialHashGrid.js +102 -0
- package/browser/Core/Utils/Vectors.js +17 -18
- package/browser/Options/Classes/AnimatableColor.js +1 -0
- package/browser/Options/Classes/AnimationOptions.js +8 -0
- package/browser/Options/Classes/Background/Background.js +6 -0
- package/browser/Options/Classes/ColorAnimation.js +12 -1
- package/browser/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/browser/Options/Classes/HslAnimation.js +4 -5
- package/browser/Options/Classes/Options.js +67 -8
- package/browser/Options/Classes/OptionsColor.js +1 -0
- package/browser/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/browser/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/browser/Options/Classes/Particles/Fill.js +28 -0
- package/browser/Options/Classes/Particles/Move/Move.js +17 -3
- package/browser/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/browser/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/browser/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/browser/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/browser/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/browser/Options/Classes/Particles/Move/Spin.js +3 -0
- package/browser/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/browser/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/browser/Options/Classes/Particles/ParticlesOptions.js +29 -9
- package/browser/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/browser/Options/Classes/Particles/Size/Size.js +1 -0
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/browser/Options/Classes/Particles/Stroke.js +3 -0
- package/browser/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/browser/Options/Classes/ResizeEvent.js +2 -0
- package/browser/Options/Classes/ValueWithRandom.js +3 -4
- package/browser/Utils/CanvasUtils.js +44 -51
- package/browser/Utils/ColorUtils.js +51 -40
- package/browser/Utils/EventDispatcher.js +1 -0
- package/browser/Utils/LogUtils.js +1 -0
- package/browser/Utils/MathUtils.js +12 -7
- package/browser/Utils/OptionsUtils.js +2 -2
- package/browser/Utils/Utils.js +109 -31
- package/browser/exports.js +1 -2
- package/cjs/Core/CanvasManager.js +303 -0
- package/cjs/Core/Container.js +134 -101
- package/cjs/Core/Engine.js +29 -162
- package/cjs/Core/Particle.js +197 -183
- package/cjs/Core/ParticlesManager.js +363 -0
- package/cjs/Core/RenderManager.js +303 -0
- package/cjs/Core/Retina.js +6 -6
- package/cjs/Core/Utils/Constants.js +2 -2
- package/cjs/Core/Utils/EventListeners.js +67 -63
- package/cjs/Core/Utils/PluginManager.js +145 -0
- package/cjs/Core/Utils/Ranges.js +29 -10
- package/cjs/Core/Utils/SpatialHashGrid.js +102 -0
- package/cjs/Core/Utils/Vectors.js +17 -18
- package/cjs/Options/Classes/AnimatableColor.js +1 -0
- package/cjs/Options/Classes/AnimationOptions.js +8 -0
- package/cjs/Options/Classes/Background/Background.js +6 -0
- package/cjs/Options/Classes/ColorAnimation.js +12 -1
- package/cjs/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/cjs/Options/Classes/HslAnimation.js +4 -5
- package/cjs/Options/Classes/Options.js +67 -8
- package/cjs/Options/Classes/OptionsColor.js +1 -0
- package/cjs/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/cjs/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/cjs/Options/Classes/Particles/Fill.js +28 -0
- package/cjs/Options/Classes/Particles/Move/Move.js +17 -3
- package/cjs/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/cjs/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/cjs/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/cjs/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/cjs/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/cjs/Options/Classes/Particles/Move/Spin.js +3 -0
- package/cjs/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/cjs/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +29 -9
- package/cjs/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/cjs/Options/Classes/Particles/Size/Size.js +1 -0
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/cjs/Options/Classes/Particles/Stroke.js +3 -0
- package/cjs/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/cjs/Options/Classes/ResizeEvent.js +2 -0
- package/cjs/Options/Classes/ValueWithRandom.js +3 -4
- package/cjs/Utils/CanvasUtils.js +44 -51
- package/cjs/Utils/ColorUtils.js +51 -40
- package/cjs/Utils/EventDispatcher.js +1 -0
- package/cjs/Utils/LogUtils.js +1 -0
- package/cjs/Utils/MathUtils.js +12 -7
- package/cjs/Utils/OptionsUtils.js +2 -2
- package/cjs/Utils/Utils.js +109 -31
- package/cjs/exports.js +1 -2
- package/dist_browser_Core_Container_js.js +30 -20
- package/esm/Core/CanvasManager.js +303 -0
- package/esm/Core/Container.js +134 -101
- package/esm/Core/Engine.js +29 -162
- package/esm/Core/Particle.js +197 -183
- package/esm/Core/ParticlesManager.js +363 -0
- package/esm/Core/RenderManager.js +303 -0
- package/esm/Core/Retina.js +6 -6
- package/esm/Core/Utils/Constants.js +2 -2
- package/esm/Core/Utils/EventListeners.js +67 -63
- package/esm/Core/Utils/PluginManager.js +145 -0
- package/esm/Core/Utils/Ranges.js +29 -10
- package/esm/Core/Utils/SpatialHashGrid.js +102 -0
- package/esm/Core/Utils/Vectors.js +17 -18
- package/esm/Options/Classes/AnimatableColor.js +1 -0
- package/esm/Options/Classes/AnimationOptions.js +8 -0
- package/esm/Options/Classes/Background/Background.js +6 -0
- package/esm/Options/Classes/ColorAnimation.js +12 -1
- package/esm/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/esm/Options/Classes/HslAnimation.js +4 -5
- package/esm/Options/Classes/Options.js +67 -8
- package/esm/Options/Classes/OptionsColor.js +1 -0
- package/esm/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/esm/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/esm/Options/Classes/Particles/Fill.js +28 -0
- package/esm/Options/Classes/Particles/Move/Move.js +17 -3
- package/esm/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/esm/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/esm/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/esm/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/esm/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/esm/Options/Classes/Particles/Move/Spin.js +3 -0
- package/esm/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/esm/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/esm/Options/Classes/Particles/ParticlesOptions.js +29 -9
- package/esm/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/esm/Options/Classes/Particles/Size/Size.js +1 -0
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/esm/Options/Classes/Particles/Stroke.js +3 -0
- package/esm/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/esm/Options/Classes/ResizeEvent.js +2 -0
- package/esm/Options/Classes/ValueWithRandom.js +3 -4
- package/esm/Utils/CanvasUtils.js +44 -51
- package/esm/Utils/ColorUtils.js +51 -40
- package/esm/Utils/EventDispatcher.js +1 -0
- package/esm/Utils/LogUtils.js +1 -0
- package/esm/Utils/MathUtils.js +12 -7
- package/esm/Utils/OptionsUtils.js +2 -2
- package/esm/Utils/Utils.js +109 -31
- package/esm/exports.js +1 -2
- package/package.json +1 -1
- package/report.html +84 -29
- package/scripts/install.js +4 -20
- package/tsparticles.engine.js +98 -86
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/CanvasManager.d.ts +39 -0
- package/types/Core/Container.d.ts +29 -14
- package/types/Core/Engine.d.ts +2 -61
- package/types/Core/Interfaces/IColorManager.d.ts +0 -1
- package/types/Core/Interfaces/IContainerPlugin.d.ts +10 -8
- package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
- package/types/Core/Interfaces/IPalette.d.ts +7 -0
- package/types/Core/Interfaces/IParticleOpacityData.d.ts +1 -0
- package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +3 -3
- package/types/Core/Interfaces/IShapeDrawData.d.ts +10 -1
- package/types/Core/Interfaces/IShapeDrawer.d.ts +0 -1
- package/types/Core/Interfaces/IShapeValues.d.ts +0 -1
- package/types/Core/Particle.d.ts +7 -11
- package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +15 -14
- package/types/Core/RenderManager.d.ts +49 -0
- package/types/Core/Retina.d.ts +0 -2
- package/types/Core/Utils/Constants.d.ts +2 -2
- package/types/Core/Utils/PluginManager.d.ts +62 -0
- package/types/Core/Utils/Ranges.d.ts +4 -1
- package/types/Core/Utils/SpatialHashGrid.d.ts +25 -0
- package/types/Core/Utils/Vectors.d.ts +8 -10
- package/types/Options/Classes/ColorAnimation.d.ts +3 -1
- package/types/Options/Classes/HslAnimation.d.ts +3 -4
- package/types/Options/Classes/Options.d.ts +5 -3
- package/types/Options/Classes/Particles/Effect/Effect.d.ts +0 -1
- package/types/Options/Classes/Particles/Fill.d.ts +12 -0
- package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +5 -5
- package/types/Options/Classes/Particles/Shape/Shape.d.ts +0 -1
- package/types/Options/Classes/ValueWithRandom.d.ts +0 -1
- package/types/Options/Interfaces/IColorAnimation.d.ts +2 -0
- package/types/Options/Interfaces/IOptions.d.ts +1 -0
- package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +0 -1
- package/types/Options/Interfaces/Particles/IFill.d.ts +9 -0
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -2
- package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
- package/types/Options/Interfaces/Particles/Shape/IShape.d.ts +0 -1
- package/types/Types/CanvasContextType.d.ts +1 -0
- package/types/Types/EngineInitializers.d.ts +6 -3
- package/types/Utils/CanvasUtils.d.ts +13 -16
- package/types/Utils/ColorUtils.d.ts +11 -10
- package/types/Utils/LogUtils.d.ts +1 -0
- package/types/Utils/MathUtils.d.ts +2 -0
- package/types/Utils/OptionsUtils.d.ts +2 -2
- package/types/Utils/Utils.d.ts +8 -1
- package/types/export-types.d.ts +7 -7
- package/types/exports.d.ts +1 -2
- package/umd/Core/CanvasManager.js +317 -0
- package/umd/Core/Container.js +134 -101
- package/umd/Core/Engine.js +28 -161
- package/umd/Core/Particle.js +198 -184
- package/umd/Core/{Particles.js → ParticlesManager.js} +186 -167
- package/umd/Core/RenderManager.js +317 -0
- package/umd/Core/Retina.js +6 -6
- package/umd/Core/Utils/Constants.js +3 -3
- package/umd/Core/Utils/EventListeners.js +67 -63
- package/umd/Core/Utils/PluginManager.js +159 -0
- package/umd/Core/Utils/Ranges.js +28 -9
- package/umd/Core/Utils/SpatialHashGrid.js +116 -0
- package/umd/Core/Utils/Vectors.js +17 -18
- package/umd/Options/Classes/AnimatableColor.js +1 -0
- package/umd/Options/Classes/AnimationOptions.js +8 -0
- package/umd/Options/Classes/Background/Background.js +6 -0
- package/umd/Options/Classes/ColorAnimation.js +12 -1
- package/umd/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/umd/Options/Classes/HslAnimation.js +5 -6
- package/umd/Options/Classes/Options.js +67 -8
- package/umd/Options/Classes/OptionsColor.js +1 -0
- package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/umd/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/umd/Options/Classes/Particles/Fill.js +42 -0
- package/umd/Options/Classes/Particles/Move/Move.js +18 -4
- package/umd/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/umd/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/umd/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/umd/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/umd/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/umd/Options/Classes/Particles/Move/Spin.js +3 -0
- package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/umd/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/umd/Options/Classes/Particles/ParticlesOptions.js +30 -10
- package/umd/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/umd/Options/Classes/Particles/Size/Size.js +1 -0
- package/umd/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/umd/Options/Classes/Particles/Stroke.js +3 -0
- package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/umd/Options/Classes/ResizeEvent.js +2 -0
- package/umd/Options/Classes/ValueWithRandom.js +3 -4
- package/umd/Utils/CanvasUtils.js +44 -53
- package/umd/Utils/ColorUtils.js +51 -39
- package/umd/Utils/EventDispatcher.js +1 -0
- package/umd/Utils/LogUtils.js +1 -0
- package/umd/Utils/MathUtils.js +14 -7
- package/umd/Utils/OptionsUtils.js +2 -2
- package/umd/Utils/Utils.js +111 -32
- package/umd/exports.js +2 -3
- package/794.min.js +0 -2
- package/794.min.js.LICENSE.txt +0 -1
- package/browser/Core/Canvas.js +0 -469
- package/browser/Core/Particles.js +0 -344
- package/browser/Core/Utils/Point.js +0 -6
- package/browser/Core/Utils/QuadTree.js +0 -59
- package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -33
- package/cjs/Core/Canvas.js +0 -469
- package/cjs/Core/Particles.js +0 -344
- package/cjs/Core/Utils/Point.js +0 -6
- package/cjs/Core/Utils/QuadTree.js +0 -59
- package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -33
- package/esm/Core/Canvas.js +0 -469
- package/esm/Core/Particles.js +0 -344
- package/esm/Core/Utils/Point.js +0 -6
- package/esm/Core/Utils/QuadTree.js +0 -59
- package/esm/Options/Classes/Particles/Move/MoveAttract.js +0 -33
- package/tsparticles.engine.min.js.LICENSE.txt +0 -1
- package/types/Core/Canvas.d.ts +0 -55
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +0 -10
- package/types/Core/Interfaces/IParticleMover.d.ts +0 -7
- package/types/Core/Utils/Point.d.ts +0 -7
- package/types/Core/Utils/QuadTree.d.ts +0 -18
- package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -12
- package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -7
- package/umd/Core/Canvas.js +0 -483
- package/umd/Core/Utils/Point.js +0 -20
- package/umd/Core/Utils/QuadTree.js +0 -73
- package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -47
- /package/browser/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/browser/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/browser/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
- /package/cjs/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/cjs/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/cjs/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
- /package/esm/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/esm/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/esm/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
- /package/umd/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/umd/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/umd/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import { countOffset, defaultDensityFactor, defaultRemoveQuantity, deleteCount, lengthOffset, minCount, minIndex, minLimit, posOffset, qTreeCapacity, sizeFactor, squareExp, } from "./Utils/Constants.js";
|
|
2
|
-
import { EventType } from "../Enums/Types/EventType.js";
|
|
3
|
-
import { LimitMode } from "../Enums/Modes/LimitMode.js";
|
|
4
|
-
import { Particle } from "./Particle.js";
|
|
5
|
-
import { Point } from "./Utils/Point.js";
|
|
6
|
-
import { QuadTree } from "./Utils/QuadTree.js";
|
|
7
|
-
import { Rectangle } from "./Utils/Ranges.js";
|
|
8
|
-
import { getLogger } from "../Utils/LogUtils.js";
|
|
9
|
-
import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
|
|
10
|
-
const qTreeRectangle = (canvasSize) => {
|
|
11
|
-
const { height, width } = canvasSize;
|
|
12
|
-
return new Rectangle(posOffset * width, posOffset * height, sizeFactor * width, sizeFactor * height);
|
|
13
|
-
};
|
|
14
|
-
export class Particles {
|
|
15
|
-
constructor(engine, container) {
|
|
16
|
-
this._addToPool = (...particles) => {
|
|
17
|
-
this._pool.push(...particles);
|
|
18
|
-
};
|
|
19
|
-
this._applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
20
|
-
const numberOptions = options.number;
|
|
21
|
-
if (!numberOptions.density.enable) {
|
|
22
|
-
if (group === undefined) {
|
|
23
|
-
this._limit = numberOptions.limit.value;
|
|
24
|
-
}
|
|
25
|
-
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
26
|
-
this._groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
27
|
-
}
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
|
|
31
|
-
if (group === undefined) {
|
|
32
|
-
this._limit = numberOptions.limit.value * densityFactor;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this._groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
36
|
-
}
|
|
37
|
-
if (particlesCount < particlesNumber) {
|
|
38
|
-
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
39
|
-
}
|
|
40
|
-
else if (particlesCount > particlesNumber) {
|
|
41
|
-
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
this._initDensityFactor = densityOptions => {
|
|
45
|
-
const container = this._container;
|
|
46
|
-
if (!container.canvas.element || !densityOptions.enable) {
|
|
47
|
-
return defaultDensityFactor;
|
|
48
|
-
}
|
|
49
|
-
const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
|
|
50
|
-
return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
|
|
51
|
-
};
|
|
52
|
-
this._pushParticle = (position, overrideOptions, group, initializer) => {
|
|
53
|
-
try {
|
|
54
|
-
const particle = this._pool.pop() ?? new Particle(this._engine, this._container);
|
|
55
|
-
particle.init(this._nextId, position, overrideOptions, group);
|
|
56
|
-
let canAdd = true;
|
|
57
|
-
if (initializer) {
|
|
58
|
-
canAdd = initializer(particle);
|
|
59
|
-
}
|
|
60
|
-
if (!canAdd) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
this._array.push(particle);
|
|
64
|
-
this._zArray.push(particle);
|
|
65
|
-
this._nextId++;
|
|
66
|
-
this._engine.dispatchEvent(EventType.particleAdded, {
|
|
67
|
-
container: this._container,
|
|
68
|
-
data: {
|
|
69
|
-
particle,
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
return particle;
|
|
73
|
-
}
|
|
74
|
-
catch (e) {
|
|
75
|
-
getLogger().warning(`error adding particle: ${e}`);
|
|
76
|
-
}
|
|
77
|
-
return undefined;
|
|
78
|
-
};
|
|
79
|
-
this._removeParticle = (index, group, override) => {
|
|
80
|
-
const particle = this._array[index];
|
|
81
|
-
if (!particle) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
if (particle.group !== group) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const zIdx = this._zArray.indexOf(particle);
|
|
88
|
-
this._array.splice(index, deleteCount);
|
|
89
|
-
this._zArray.splice(zIdx, deleteCount);
|
|
90
|
-
particle.destroy(override);
|
|
91
|
-
this._engine.dispatchEvent(EventType.particleRemoved, {
|
|
92
|
-
container: this._container,
|
|
93
|
-
data: {
|
|
94
|
-
particle,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
this._addToPool(particle);
|
|
98
|
-
return true;
|
|
99
|
-
};
|
|
100
|
-
this._engine = engine;
|
|
101
|
-
this._container = container;
|
|
102
|
-
this._nextId = 0;
|
|
103
|
-
this._array = [];
|
|
104
|
-
this._zArray = [];
|
|
105
|
-
this._pool = [];
|
|
106
|
-
this._limit = 0;
|
|
107
|
-
this._groupLimits = new Map();
|
|
108
|
-
this._needsSort = false;
|
|
109
|
-
this._lastZIndex = 0;
|
|
110
|
-
this._pluginsInitialized = false;
|
|
111
|
-
const canvasSize = container.canvas.size;
|
|
112
|
-
this.quadTree = new QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
|
|
113
|
-
this.movers = [];
|
|
114
|
-
this.updaters = [];
|
|
115
|
-
}
|
|
116
|
-
get count() {
|
|
117
|
-
return this._array.length;
|
|
118
|
-
}
|
|
119
|
-
addParticle(position, overrideOptions, group, initializer) {
|
|
120
|
-
const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count;
|
|
121
|
-
if (limit > minLimit) {
|
|
122
|
-
switch (limitMode) {
|
|
123
|
-
case LimitMode.delete: {
|
|
124
|
-
const countToRemove = currentCount + countOffset - limit;
|
|
125
|
-
if (countToRemove > minCount) {
|
|
126
|
-
this.removeQuantity(countToRemove);
|
|
127
|
-
}
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
case LimitMode.wait:
|
|
131
|
-
if (currentCount >= limit) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return this._pushParticle(position, overrideOptions, group, initializer);
|
|
138
|
-
}
|
|
139
|
-
clear() {
|
|
140
|
-
this._array = [];
|
|
141
|
-
this._zArray = [];
|
|
142
|
-
this._pluginsInitialized = false;
|
|
143
|
-
}
|
|
144
|
-
destroy() {
|
|
145
|
-
this._array = [];
|
|
146
|
-
this._zArray = [];
|
|
147
|
-
this.movers = [];
|
|
148
|
-
this.updaters = [];
|
|
149
|
-
}
|
|
150
|
-
drawParticles(delta) {
|
|
151
|
-
for (const particle of this._zArray) {
|
|
152
|
-
particle.draw(delta);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
filter(condition) {
|
|
156
|
-
return this._array.filter(condition);
|
|
157
|
-
}
|
|
158
|
-
find(condition) {
|
|
159
|
-
return this._array.find(condition);
|
|
160
|
-
}
|
|
161
|
-
get(index) {
|
|
162
|
-
return this._array[index];
|
|
163
|
-
}
|
|
164
|
-
async init() {
|
|
165
|
-
const container = this._container, options = container.actualOptions;
|
|
166
|
-
this._lastZIndex = 0;
|
|
167
|
-
this._needsSort = false;
|
|
168
|
-
for (const plugin of container.plugins) {
|
|
169
|
-
if (plugin.redrawInit) {
|
|
170
|
-
await plugin.redrawInit();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
await this.initPlugins();
|
|
174
|
-
let handled = false;
|
|
175
|
-
for (const plugin of container.plugins) {
|
|
176
|
-
handled = plugin.particlesInitialization?.() ?? handled;
|
|
177
|
-
if (handled) {
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (!handled) {
|
|
182
|
-
const particlesOptions = options.particles, groups = particlesOptions.groups;
|
|
183
|
-
for (const group in groups) {
|
|
184
|
-
const groupOptions = groups[group];
|
|
185
|
-
if (!groupOptions) {
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
|
|
189
|
-
this.addParticle(undefined, groupOptions, group);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
for (let i = this.count; i < particlesOptions.number.value; i++) {
|
|
193
|
-
this.addParticle();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
async initPlugins() {
|
|
198
|
-
if (this._pluginsInitialized) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const container = this._container;
|
|
202
|
-
this.movers = await this._engine.getMovers(container, true);
|
|
203
|
-
this.updaters = await this._engine.getUpdaters(container, true);
|
|
204
|
-
for (const pathGenerator of container.pathGenerators.values()) {
|
|
205
|
-
pathGenerator.init(container);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
push(nb, position, overrideOptions, group) {
|
|
209
|
-
for (let i = 0; i < nb; i++) {
|
|
210
|
-
this.addParticle(position, overrideOptions, group);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
async redraw() {
|
|
214
|
-
this.clear();
|
|
215
|
-
await this.init();
|
|
216
|
-
this._container.canvas.drawParticles({ value: 0, factor: 0 });
|
|
217
|
-
}
|
|
218
|
-
remove(particle, group, override) {
|
|
219
|
-
this.removeAt(this._array.indexOf(particle), undefined, group, override);
|
|
220
|
-
}
|
|
221
|
-
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
222
|
-
if (index < minIndex || index > this.count) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
let deleted = 0;
|
|
226
|
-
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
227
|
-
if (this._removeParticle(i, group, override)) {
|
|
228
|
-
i--;
|
|
229
|
-
deleted++;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
removeQuantity(quantity, group) {
|
|
234
|
-
this.removeAt(minIndex, quantity, group);
|
|
235
|
-
}
|
|
236
|
-
setDensity() {
|
|
237
|
-
const options = this._container.actualOptions, groups = options.particles.groups;
|
|
238
|
-
let pluginsCount = 0;
|
|
239
|
-
for (const plugin of this._container.plugins) {
|
|
240
|
-
if (plugin.particlesDensityCount) {
|
|
241
|
-
pluginsCount += plugin.particlesDensityCount();
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
for (const group in groups) {
|
|
245
|
-
const groupData = groups[group];
|
|
246
|
-
if (!groupData) {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
const groupDataOptions = loadParticlesOptions(this._engine, this._container, groupData);
|
|
250
|
-
this._applyDensity(groupDataOptions, pluginsCount, group);
|
|
251
|
-
}
|
|
252
|
-
this._applyDensity(options.particles, pluginsCount);
|
|
253
|
-
}
|
|
254
|
-
setLastZIndex(zIndex) {
|
|
255
|
-
this._lastZIndex = zIndex;
|
|
256
|
-
this._needsSort = this._needsSort || this._lastZIndex < zIndex;
|
|
257
|
-
}
|
|
258
|
-
setResizeFactor(factor) {
|
|
259
|
-
this._resizeFactor = factor;
|
|
260
|
-
}
|
|
261
|
-
update(delta) {
|
|
262
|
-
const container = this._container, particlesToDelete = new Set();
|
|
263
|
-
this.quadTree = new QuadTree(qTreeRectangle(container.canvas.size), qTreeCapacity);
|
|
264
|
-
for (const pathGenerator of container.pathGenerators.values()) {
|
|
265
|
-
pathGenerator.update();
|
|
266
|
-
}
|
|
267
|
-
for (const plugin of container.plugins) {
|
|
268
|
-
plugin.update?.(delta);
|
|
269
|
-
}
|
|
270
|
-
const resizeFactor = this._resizeFactor;
|
|
271
|
-
for (const particle of this._array) {
|
|
272
|
-
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
273
|
-
particle.position.x *= resizeFactor.width;
|
|
274
|
-
particle.position.y *= resizeFactor.height;
|
|
275
|
-
particle.initialPosition.x *= resizeFactor.width;
|
|
276
|
-
particle.initialPosition.y *= resizeFactor.height;
|
|
277
|
-
}
|
|
278
|
-
particle.ignoresResizeRatio = false;
|
|
279
|
-
for (const plugin of this._container.plugins) {
|
|
280
|
-
if (plugin.particleReset) {
|
|
281
|
-
plugin.particleReset(particle);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
for (const plugin of this._container.plugins) {
|
|
285
|
-
if (particle.destroyed) {
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
plugin.particleUpdate?.(particle, delta);
|
|
289
|
-
}
|
|
290
|
-
for (const mover of this.movers) {
|
|
291
|
-
if (mover.isEnabled(particle)) {
|
|
292
|
-
mover.move(particle, delta);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (particle.destroyed) {
|
|
296
|
-
particlesToDelete.add(particle);
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
this.quadTree.insert(new Point(particle.getPosition(), particle));
|
|
300
|
-
}
|
|
301
|
-
if (particlesToDelete.size) {
|
|
302
|
-
const checkDelete = (p) => !particlesToDelete.has(p);
|
|
303
|
-
this._array = this.filter(checkDelete);
|
|
304
|
-
this._zArray = this._zArray.filter(checkDelete);
|
|
305
|
-
for (const particle of particlesToDelete) {
|
|
306
|
-
this._engine.dispatchEvent(EventType.particleRemoved, {
|
|
307
|
-
container: this._container,
|
|
308
|
-
data: {
|
|
309
|
-
particle,
|
|
310
|
-
},
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
this._addToPool(...particlesToDelete);
|
|
314
|
-
}
|
|
315
|
-
for (const plugin of container.plugins) {
|
|
316
|
-
if (plugin.postUpdate) {
|
|
317
|
-
plugin.postUpdate(delta);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
for (const particle of this._array) {
|
|
321
|
-
for (const updater of this.updaters) {
|
|
322
|
-
updater.update(particle, delta);
|
|
323
|
-
}
|
|
324
|
-
if (!particle.destroyed && !particle.spawning) {
|
|
325
|
-
for (const plugin of container.plugins) {
|
|
326
|
-
if (plugin.postParticleUpdate) {
|
|
327
|
-
plugin.postParticleUpdate(particle, delta);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
delete this._resizeFactor;
|
|
333
|
-
if (this._needsSort) {
|
|
334
|
-
const zArray = this._zArray;
|
|
335
|
-
zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
|
|
336
|
-
const lastItem = zArray[zArray.length - lengthOffset];
|
|
337
|
-
if (!lastItem) {
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
this._lastZIndex = lastItem.position.z;
|
|
341
|
-
this._needsSort = false;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Circle, Rectangle } from "./Ranges.js";
|
|
2
|
-
import { double, half, subdivideCount } from "./Constants.js";
|
|
3
|
-
import { getDistance } from "../../Utils/MathUtils.js";
|
|
4
|
-
export class QuadTree {
|
|
5
|
-
constructor(rectangle, capacity) {
|
|
6
|
-
this.rectangle = rectangle;
|
|
7
|
-
this.capacity = capacity;
|
|
8
|
-
this._subdivide = () => {
|
|
9
|
-
const { x, y } = this.rectangle.position, { width, height } = this.rectangle.size, { capacity } = this;
|
|
10
|
-
for (let i = 0; i < subdivideCount; i++) {
|
|
11
|
-
const fixedIndex = i % double;
|
|
12
|
-
this._subs.push(new QuadTree(new Rectangle(x + width * half * fixedIndex, y + height * half * (Math.round(i * half) - fixedIndex), width * half, height * half), capacity));
|
|
13
|
-
}
|
|
14
|
-
this._divided = true;
|
|
15
|
-
};
|
|
16
|
-
this._points = [];
|
|
17
|
-
this._divided = false;
|
|
18
|
-
this._subs = [];
|
|
19
|
-
}
|
|
20
|
-
insert(point) {
|
|
21
|
-
if (!this.rectangle.contains(point.position)) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
if (this._points.length < this.capacity) {
|
|
25
|
-
this._points.push(point);
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
if (!this._divided) {
|
|
29
|
-
this._subdivide();
|
|
30
|
-
}
|
|
31
|
-
return this._subs.some(sub => sub.insert(point));
|
|
32
|
-
}
|
|
33
|
-
query(range, check) {
|
|
34
|
-
const res = [];
|
|
35
|
-
if (!range.intersects(this.rectangle)) {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
for (const p of this._points) {
|
|
39
|
-
if (!range.contains(p.position) &&
|
|
40
|
-
getDistance(range.position, p.position) > p.particle.getRadius() &&
|
|
41
|
-
(!check || check(p.particle))) {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
res.push(p.particle);
|
|
45
|
-
}
|
|
46
|
-
if (this._divided) {
|
|
47
|
-
for (const sub of this._subs) {
|
|
48
|
-
res.push(...sub.query(range, check));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return res;
|
|
52
|
-
}
|
|
53
|
-
queryCircle(position, radius, check) {
|
|
54
|
-
return this.query(new Circle(position.x, position.y, radius), check);
|
|
55
|
-
}
|
|
56
|
-
queryRectangle(position, size, check) {
|
|
57
|
-
return this.query(new Rectangle(position.x, position.y, size.width, size.height), check);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { isNull } from "../../../../Utils/TypeUtils.js";
|
|
2
|
-
import { setRangeValue } from "../../../../Utils/MathUtils.js";
|
|
3
|
-
export class MoveAttract {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.distance = 200;
|
|
6
|
-
this.enable = false;
|
|
7
|
-
this.rotate = {
|
|
8
|
-
x: 3000,
|
|
9
|
-
y: 3000,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
load(data) {
|
|
13
|
-
if (isNull(data)) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (data.distance !== undefined) {
|
|
17
|
-
this.distance = setRangeValue(data.distance);
|
|
18
|
-
}
|
|
19
|
-
if (data.enable !== undefined) {
|
|
20
|
-
this.enable = data.enable;
|
|
21
|
-
}
|
|
22
|
-
if (data.rotate) {
|
|
23
|
-
const rotateX = data.rotate.x;
|
|
24
|
-
if (rotateX !== undefined) {
|
|
25
|
-
this.rotate.x = rotateX;
|
|
26
|
-
}
|
|
27
|
-
const rotateY = data.rotate.y;
|
|
28
|
-
if (rotateY !== undefined) {
|
|
29
|
-
this.rotate.y = rotateY;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|