@tsparticles/move-base 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/BaseMover.js +78 -0
- package/browser/IParticleGravity.js +1 -0
- package/browser/IParticleSpin.js +1 -0
- package/browser/Types.js +1 -0
- package/browser/Utils.js +74 -0
- package/browser/index.js +4 -0
- package/cjs/BaseMover.js +82 -0
- package/cjs/IParticleGravity.js +2 -0
- package/cjs/IParticleSpin.js +2 -0
- package/cjs/Types.js +2 -0
- package/cjs/Utils.js +81 -0
- package/cjs/index.js +19 -0
- package/esm/BaseMover.js +78 -0
- package/esm/IParticleGravity.js +1 -0
- package/esm/IParticleSpin.js +1 -0
- package/esm/Types.js +1 -0
- package/esm/Utils.js +74 -0
- package/esm/index.js +4 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.move.base.js +287 -0
- package/tsparticles.move.base.min.js +2 -0
- package/tsparticles.move.base.min.js.LICENSE.txt +8 -0
- package/types/BaseMover.d.ts +7 -0
- package/types/IParticleGravity.d.ts +5 -0
- package/types/IParticleSpin.d.ts +8 -0
- package/types/Types.d.ts +10 -0
- package/types/Utils.d.ts +6 -0
- package/types/index.d.ts +2 -0
- package/umd/BaseMover.js +92 -0
- package/umd/IParticleGravity.js +12 -0
- package/umd/IParticleSpin.js +12 -0
- package/umd/Types.js +12 -0
- package/umd/Utils.js +91 -0
- package/umd/index.js +18 -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 Standard Mover
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/tsparticles-move-base)
|
|
6
|
+
[](https://www.npmjs.com/package/tsparticles-move-base)
|
|
7
|
+
[](https://www.npmjs.com/package/tsparticles-move-base) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) move plugin for standard movement effect.
|
|
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.move.base.min.js` file will export the function to load the interaction plugin:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
loadBaseMover;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadBaseMover(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-move-base
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add tsparticles-move-base
|
|
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 { loadBaseMover } = require("tsparticles-move-base");
|
|
59
|
+
|
|
60
|
+
loadBaseMover(tsParticles); // awaitable
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { tsParticles } from "tsparticles-engine";
|
|
67
|
+
import { loadBaseMover } from "tsparticles-move-base";
|
|
68
|
+
|
|
69
|
+
loadBaseMover(tsParticles); // awaitable
|
|
70
|
+
```
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getDistance, getRangeMax, getRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { applyDistance, applyPath, getProximitySpeedFactor, spin } from "./Utils";
|
|
3
|
+
export class BaseMover {
|
|
4
|
+
init(particle) {
|
|
5
|
+
var _a;
|
|
6
|
+
const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin;
|
|
7
|
+
particle.gravity = {
|
|
8
|
+
enable: gravityOptions.enable,
|
|
9
|
+
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
10
|
+
inverse: gravityOptions.inverse,
|
|
11
|
+
};
|
|
12
|
+
if (spinOptions.enable) {
|
|
13
|
+
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
|
|
14
|
+
x: (spinPos.x / 100) * container.canvas.size.width,
|
|
15
|
+
y: (spinPos.y / 100) * container.canvas.size.height,
|
|
16
|
+
}, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
|
|
17
|
+
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
18
|
+
particle.spin = {
|
|
19
|
+
center: spinCenter,
|
|
20
|
+
direction: particle.velocity.x >= 0 ? "clockwise" : "counter-clockwise",
|
|
21
|
+
angle: particle.velocity.angle,
|
|
22
|
+
radius: distance,
|
|
23
|
+
acceleration: particle.retina.spinAcceleration,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
isEnabled(particle) {
|
|
28
|
+
return !particle.destroyed && particle.options.move.enable;
|
|
29
|
+
}
|
|
30
|
+
move(particle, delta) {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
var _d, _e;
|
|
33
|
+
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
34
|
+
if (!moveOptions.enable) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const container = particle.container, slowFactor = getProximitySpeedFactor(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = getRangeValue(moveOptions.speed) * container.retina.pixelRatio)) *
|
|
38
|
+
container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = getRangeValue(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = getRangeMax(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor;
|
|
39
|
+
if (moveOptions.spin.enable) {
|
|
40
|
+
spin(particle, moveSpeed);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
applyPath(particle, delta);
|
|
44
|
+
const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
|
|
45
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
|
|
46
|
+
particle.velocity.y +=
|
|
47
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
|
|
48
|
+
}
|
|
49
|
+
if (moveDrift && moveSpeed) {
|
|
50
|
+
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
|
|
51
|
+
}
|
|
52
|
+
const decay = particle.moveDecay;
|
|
53
|
+
if (decay != 1) {
|
|
54
|
+
particle.velocity.multTo(decay);
|
|
55
|
+
}
|
|
56
|
+
const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
|
|
57
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) &&
|
|
58
|
+
maxSpeed > 0 &&
|
|
59
|
+
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
|
|
60
|
+
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
|
|
61
|
+
velocity.y = gravityFactor * maxSpeed;
|
|
62
|
+
if (moveSpeed) {
|
|
63
|
+
particle.velocity.y = velocity.y / moveSpeed;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
67
|
+
if (zVelocityFactor != 1) {
|
|
68
|
+
velocity.multTo(zVelocityFactor);
|
|
69
|
+
}
|
|
70
|
+
particle.position.addTo(velocity);
|
|
71
|
+
if (moveOptions.vibrate) {
|
|
72
|
+
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
|
|
73
|
+
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
applyDistance(particle);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/Utils.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { clamp, getDistances, getRandom } from "@tsparticles/engine";
|
|
2
|
+
export function applyDistance(particle) {
|
|
3
|
+
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical;
|
|
4
|
+
if (!hDistance && !vDistance) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (((hDistance && dxFixed >= hDistance) || (vDistance && dyFixed >= vDistance)) && !particle.misplaced) {
|
|
8
|
+
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
9
|
+
if (hDistance) {
|
|
10
|
+
particle.velocity.x = particle.velocity.y / 2 - particle.velocity.x;
|
|
11
|
+
}
|
|
12
|
+
if (vDistance) {
|
|
13
|
+
particle.velocity.y = particle.velocity.x / 2 - particle.velocity.y;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
17
|
+
particle.misplaced = false;
|
|
18
|
+
}
|
|
19
|
+
else if (particle.misplaced) {
|
|
20
|
+
const pos = particle.position, vel = particle.velocity;
|
|
21
|
+
if (hDistance && ((pos.x < initialPosition.x && vel.x < 0) || (pos.x > initialPosition.x && vel.x > 0))) {
|
|
22
|
+
vel.x *= -getRandom();
|
|
23
|
+
}
|
|
24
|
+
if (vDistance && ((pos.y < initialPosition.y && vel.y < 0) || (pos.y > initialPosition.y && vel.y > 0))) {
|
|
25
|
+
vel.y *= -getRandom();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function spin(particle, moveSpeed) {
|
|
30
|
+
const container = particle.container;
|
|
31
|
+
if (!particle.spin) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const updateFunc = {
|
|
35
|
+
x: particle.spin.direction === "clockwise" ? Math.cos : Math.sin,
|
|
36
|
+
y: particle.spin.direction === "clockwise" ? Math.sin : Math.cos,
|
|
37
|
+
};
|
|
38
|
+
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
39
|
+
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
40
|
+
particle.spin.radius += particle.spin.acceleration;
|
|
41
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height);
|
|
42
|
+
if (particle.spin.radius > maxCanvasSize / 2) {
|
|
43
|
+
particle.spin.radius = maxCanvasSize / 2;
|
|
44
|
+
particle.spin.acceleration *= -1;
|
|
45
|
+
}
|
|
46
|
+
else if (particle.spin.radius < 0) {
|
|
47
|
+
particle.spin.radius = 0;
|
|
48
|
+
particle.spin.acceleration *= -1;
|
|
49
|
+
}
|
|
50
|
+
particle.spin.angle += (moveSpeed / 100) * (1 - particle.spin.radius / maxCanvasSize);
|
|
51
|
+
}
|
|
52
|
+
export function applyPath(particle, delta) {
|
|
53
|
+
var _a;
|
|
54
|
+
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
55
|
+
if (!pathEnabled) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (particle.lastPathTime <= particle.pathDelay) {
|
|
59
|
+
particle.lastPathTime += delta.value;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
|
|
63
|
+
if (path) {
|
|
64
|
+
particle.velocity.addTo(path);
|
|
65
|
+
}
|
|
66
|
+
if (pathOptions.clamp) {
|
|
67
|
+
particle.velocity.x = clamp(particle.velocity.x, -1, 1);
|
|
68
|
+
particle.velocity.y = clamp(particle.velocity.y, -1, 1);
|
|
69
|
+
}
|
|
70
|
+
particle.lastPathTime -= particle.pathDelay;
|
|
71
|
+
}
|
|
72
|
+
export function getProximitySpeedFactor(particle) {
|
|
73
|
+
return particle.slow.inRange ? particle.slow.factor : 1;
|
|
74
|
+
}
|
package/browser/index.js
ADDED
package/cjs/BaseMover.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseMover = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const Utils_1 = require("./Utils");
|
|
6
|
+
class BaseMover {
|
|
7
|
+
init(particle) {
|
|
8
|
+
var _a;
|
|
9
|
+
const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin;
|
|
10
|
+
particle.gravity = {
|
|
11
|
+
enable: gravityOptions.enable,
|
|
12
|
+
acceleration: (0, engine_1.getRangeValue)(gravityOptions.acceleration),
|
|
13
|
+
inverse: gravityOptions.inverse,
|
|
14
|
+
};
|
|
15
|
+
if (spinOptions.enable) {
|
|
16
|
+
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
|
|
17
|
+
x: (spinPos.x / 100) * container.canvas.size.width,
|
|
18
|
+
y: (spinPos.y / 100) * container.canvas.size.height,
|
|
19
|
+
}, pos = particle.getPosition(), distance = (0, engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, engine_1.getRangeValue)(spinOptions.acceleration);
|
|
20
|
+
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
21
|
+
particle.spin = {
|
|
22
|
+
center: spinCenter,
|
|
23
|
+
direction: particle.velocity.x >= 0 ? "clockwise" : "counter-clockwise",
|
|
24
|
+
angle: particle.velocity.angle,
|
|
25
|
+
radius: distance,
|
|
26
|
+
acceleration: particle.retina.spinAcceleration,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
isEnabled(particle) {
|
|
31
|
+
return !particle.destroyed && particle.options.move.enable;
|
|
32
|
+
}
|
|
33
|
+
move(particle, delta) {
|
|
34
|
+
var _a, _b, _c;
|
|
35
|
+
var _d, _e;
|
|
36
|
+
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
37
|
+
if (!moveOptions.enable) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const container = particle.container, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = (0, engine_1.getRangeValue)(moveOptions.speed) * container.retina.pixelRatio)) *
|
|
41
|
+
container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = (0, engine_1.getRangeValue)(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = (0, engine_1.getRangeMax)(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor;
|
|
42
|
+
if (moveOptions.spin.enable) {
|
|
43
|
+
(0, Utils_1.spin)(particle, moveSpeed);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
(0, Utils_1.applyPath)(particle, delta);
|
|
47
|
+
const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
|
|
48
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
|
|
49
|
+
particle.velocity.y +=
|
|
50
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
|
|
51
|
+
}
|
|
52
|
+
if (moveDrift && moveSpeed) {
|
|
53
|
+
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
|
|
54
|
+
}
|
|
55
|
+
const decay = particle.moveDecay;
|
|
56
|
+
if (decay != 1) {
|
|
57
|
+
particle.velocity.multTo(decay);
|
|
58
|
+
}
|
|
59
|
+
const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
|
|
60
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) &&
|
|
61
|
+
maxSpeed > 0 &&
|
|
62
|
+
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
|
|
63
|
+
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
|
|
64
|
+
velocity.y = gravityFactor * maxSpeed;
|
|
65
|
+
if (moveSpeed) {
|
|
66
|
+
particle.velocity.y = velocity.y / moveSpeed;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = Math.pow((1 - particle.zIndexFactor), zIndexOptions.velocityRate);
|
|
70
|
+
if (zVelocityFactor != 1) {
|
|
71
|
+
velocity.multTo(zVelocityFactor);
|
|
72
|
+
}
|
|
73
|
+
particle.position.addTo(velocity);
|
|
74
|
+
if (moveOptions.vibrate) {
|
|
75
|
+
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
|
|
76
|
+
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
(0, Utils_1.applyDistance)(particle);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.BaseMover = BaseMover;
|
package/cjs/Types.js
ADDED
package/cjs/Utils.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.applyDistance = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
function applyDistance(particle) {
|
|
6
|
+
const initialPosition = particle.initialPosition, { dx, dy } = (0, engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical;
|
|
7
|
+
if (!hDistance && !vDistance) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (((hDistance && dxFixed >= hDistance) || (vDistance && dyFixed >= vDistance)) && !particle.misplaced) {
|
|
11
|
+
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
12
|
+
if (hDistance) {
|
|
13
|
+
particle.velocity.x = particle.velocity.y / 2 - particle.velocity.x;
|
|
14
|
+
}
|
|
15
|
+
if (vDistance) {
|
|
16
|
+
particle.velocity.y = particle.velocity.x / 2 - particle.velocity.y;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
20
|
+
particle.misplaced = false;
|
|
21
|
+
}
|
|
22
|
+
else if (particle.misplaced) {
|
|
23
|
+
const pos = particle.position, vel = particle.velocity;
|
|
24
|
+
if (hDistance && ((pos.x < initialPosition.x && vel.x < 0) || (pos.x > initialPosition.x && vel.x > 0))) {
|
|
25
|
+
vel.x *= -(0, engine_1.getRandom)();
|
|
26
|
+
}
|
|
27
|
+
if (vDistance && ((pos.y < initialPosition.y && vel.y < 0) || (pos.y > initialPosition.y && vel.y > 0))) {
|
|
28
|
+
vel.y *= -(0, engine_1.getRandom)();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.applyDistance = applyDistance;
|
|
33
|
+
function spin(particle, moveSpeed) {
|
|
34
|
+
const container = particle.container;
|
|
35
|
+
if (!particle.spin) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const updateFunc = {
|
|
39
|
+
x: particle.spin.direction === "clockwise" ? Math.cos : Math.sin,
|
|
40
|
+
y: particle.spin.direction === "clockwise" ? Math.sin : Math.cos,
|
|
41
|
+
};
|
|
42
|
+
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
43
|
+
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
44
|
+
particle.spin.radius += particle.spin.acceleration;
|
|
45
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height);
|
|
46
|
+
if (particle.spin.radius > maxCanvasSize / 2) {
|
|
47
|
+
particle.spin.radius = maxCanvasSize / 2;
|
|
48
|
+
particle.spin.acceleration *= -1;
|
|
49
|
+
}
|
|
50
|
+
else if (particle.spin.radius < 0) {
|
|
51
|
+
particle.spin.radius = 0;
|
|
52
|
+
particle.spin.acceleration *= -1;
|
|
53
|
+
}
|
|
54
|
+
particle.spin.angle += (moveSpeed / 100) * (1 - particle.spin.radius / maxCanvasSize);
|
|
55
|
+
}
|
|
56
|
+
exports.spin = spin;
|
|
57
|
+
function applyPath(particle, delta) {
|
|
58
|
+
var _a;
|
|
59
|
+
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
60
|
+
if (!pathEnabled) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (particle.lastPathTime <= particle.pathDelay) {
|
|
64
|
+
particle.lastPathTime += delta.value;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
|
|
68
|
+
if (path) {
|
|
69
|
+
particle.velocity.addTo(path);
|
|
70
|
+
}
|
|
71
|
+
if (pathOptions.clamp) {
|
|
72
|
+
particle.velocity.x = (0, engine_1.clamp)(particle.velocity.x, -1, 1);
|
|
73
|
+
particle.velocity.y = (0, engine_1.clamp)(particle.velocity.y, -1, 1);
|
|
74
|
+
}
|
|
75
|
+
particle.lastPathTime -= particle.pathDelay;
|
|
76
|
+
}
|
|
77
|
+
exports.applyPath = applyPath;
|
|
78
|
+
function getProximitySpeedFactor(particle) {
|
|
79
|
+
return particle.slow.inRange ? particle.slow.factor : 1;
|
|
80
|
+
}
|
|
81
|
+
exports.getProximitySpeedFactor = getProximitySpeedFactor;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadBaseMover = void 0;
|
|
13
|
+
const BaseMover_1 = require("./BaseMover");
|
|
14
|
+
function loadBaseMover(engine) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
engine.addMover("base", () => new BaseMover_1.BaseMover());
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.loadBaseMover = loadBaseMover;
|
package/esm/BaseMover.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getDistance, getRangeMax, getRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { applyDistance, applyPath, getProximitySpeedFactor, spin } from "./Utils";
|
|
3
|
+
export class BaseMover {
|
|
4
|
+
init(particle) {
|
|
5
|
+
var _a;
|
|
6
|
+
const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin;
|
|
7
|
+
particle.gravity = {
|
|
8
|
+
enable: gravityOptions.enable,
|
|
9
|
+
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
10
|
+
inverse: gravityOptions.inverse,
|
|
11
|
+
};
|
|
12
|
+
if (spinOptions.enable) {
|
|
13
|
+
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
|
|
14
|
+
x: (spinPos.x / 100) * container.canvas.size.width,
|
|
15
|
+
y: (spinPos.y / 100) * container.canvas.size.height,
|
|
16
|
+
}, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
|
|
17
|
+
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
18
|
+
particle.spin = {
|
|
19
|
+
center: spinCenter,
|
|
20
|
+
direction: particle.velocity.x >= 0 ? "clockwise" : "counter-clockwise",
|
|
21
|
+
angle: particle.velocity.angle,
|
|
22
|
+
radius: distance,
|
|
23
|
+
acceleration: particle.retina.spinAcceleration,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
isEnabled(particle) {
|
|
28
|
+
return !particle.destroyed && particle.options.move.enable;
|
|
29
|
+
}
|
|
30
|
+
move(particle, delta) {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
var _d, _e;
|
|
33
|
+
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
34
|
+
if (!moveOptions.enable) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const container = particle.container, slowFactor = getProximitySpeedFactor(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = getRangeValue(moveOptions.speed) * container.retina.pixelRatio)) *
|
|
38
|
+
container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = getRangeValue(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = getRangeMax(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor;
|
|
39
|
+
if (moveOptions.spin.enable) {
|
|
40
|
+
spin(particle, moveSpeed);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
applyPath(particle, delta);
|
|
44
|
+
const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
|
|
45
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
|
|
46
|
+
particle.velocity.y +=
|
|
47
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
|
|
48
|
+
}
|
|
49
|
+
if (moveDrift && moveSpeed) {
|
|
50
|
+
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
|
|
51
|
+
}
|
|
52
|
+
const decay = particle.moveDecay;
|
|
53
|
+
if (decay != 1) {
|
|
54
|
+
particle.velocity.multTo(decay);
|
|
55
|
+
}
|
|
56
|
+
const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
|
|
57
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) &&
|
|
58
|
+
maxSpeed > 0 &&
|
|
59
|
+
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
|
|
60
|
+
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
|
|
61
|
+
velocity.y = gravityFactor * maxSpeed;
|
|
62
|
+
if (moveSpeed) {
|
|
63
|
+
particle.velocity.y = velocity.y / moveSpeed;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
67
|
+
if (zVelocityFactor != 1) {
|
|
68
|
+
velocity.multTo(zVelocityFactor);
|
|
69
|
+
}
|
|
70
|
+
particle.position.addTo(velocity);
|
|
71
|
+
if (moveOptions.vibrate) {
|
|
72
|
+
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
|
|
73
|
+
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
applyDistance(particle);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/Utils.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { clamp, getDistances, getRandom } from "@tsparticles/engine";
|
|
2
|
+
export function applyDistance(particle) {
|
|
3
|
+
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical;
|
|
4
|
+
if (!hDistance && !vDistance) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (((hDistance && dxFixed >= hDistance) || (vDistance && dyFixed >= vDistance)) && !particle.misplaced) {
|
|
8
|
+
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
9
|
+
if (hDistance) {
|
|
10
|
+
particle.velocity.x = particle.velocity.y / 2 - particle.velocity.x;
|
|
11
|
+
}
|
|
12
|
+
if (vDistance) {
|
|
13
|
+
particle.velocity.y = particle.velocity.x / 2 - particle.velocity.y;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
17
|
+
particle.misplaced = false;
|
|
18
|
+
}
|
|
19
|
+
else if (particle.misplaced) {
|
|
20
|
+
const pos = particle.position, vel = particle.velocity;
|
|
21
|
+
if (hDistance && ((pos.x < initialPosition.x && vel.x < 0) || (pos.x > initialPosition.x && vel.x > 0))) {
|
|
22
|
+
vel.x *= -getRandom();
|
|
23
|
+
}
|
|
24
|
+
if (vDistance && ((pos.y < initialPosition.y && vel.y < 0) || (pos.y > initialPosition.y && vel.y > 0))) {
|
|
25
|
+
vel.y *= -getRandom();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function spin(particle, moveSpeed) {
|
|
30
|
+
const container = particle.container;
|
|
31
|
+
if (!particle.spin) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const updateFunc = {
|
|
35
|
+
x: particle.spin.direction === "clockwise" ? Math.cos : Math.sin,
|
|
36
|
+
y: particle.spin.direction === "clockwise" ? Math.sin : Math.cos,
|
|
37
|
+
};
|
|
38
|
+
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
39
|
+
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
40
|
+
particle.spin.radius += particle.spin.acceleration;
|
|
41
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height);
|
|
42
|
+
if (particle.spin.radius > maxCanvasSize / 2) {
|
|
43
|
+
particle.spin.radius = maxCanvasSize / 2;
|
|
44
|
+
particle.spin.acceleration *= -1;
|
|
45
|
+
}
|
|
46
|
+
else if (particle.spin.radius < 0) {
|
|
47
|
+
particle.spin.radius = 0;
|
|
48
|
+
particle.spin.acceleration *= -1;
|
|
49
|
+
}
|
|
50
|
+
particle.spin.angle += (moveSpeed / 100) * (1 - particle.spin.radius / maxCanvasSize);
|
|
51
|
+
}
|
|
52
|
+
export function applyPath(particle, delta) {
|
|
53
|
+
var _a;
|
|
54
|
+
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
55
|
+
if (!pathEnabled) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (particle.lastPathTime <= particle.pathDelay) {
|
|
59
|
+
particle.lastPathTime += delta.value;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
|
|
63
|
+
if (path) {
|
|
64
|
+
particle.velocity.addTo(path);
|
|
65
|
+
}
|
|
66
|
+
if (pathOptions.clamp) {
|
|
67
|
+
particle.velocity.x = clamp(particle.velocity.x, -1, 1);
|
|
68
|
+
particle.velocity.y = clamp(particle.velocity.y, -1, 1);
|
|
69
|
+
}
|
|
70
|
+
particle.lastPathTime -= particle.pathDelay;
|
|
71
|
+
}
|
|
72
|
+
export function getProximitySpeedFactor(particle) {
|
|
73
|
+
return particle.slow.inRange ? particle.slow.factor : 1;
|
|
74
|
+
}
|
package/esm/index.js
ADDED