@tsparticles/move-base 3.0.0-alpha.0 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -11
- package/browser/BaseMover.js +23 -49
- package/browser/Utils.js +33 -4
- package/browser/index.js +2 -2
- package/cjs/BaseMover.js +21 -47
- package/cjs/Utils.js +34 -4
- package/cjs/index.js +2 -13
- package/esm/BaseMover.js +23 -49
- package/esm/Utils.js +33 -4
- package/esm/index.js +2 -2
- package/package.json +6 -5
- package/report.html +4 -4
- package/tsparticles.move.base.js +69 -61
- package/tsparticles.move.base.min.js +1 -1
- package/tsparticles.move.base.min.js.LICENSE.txt +1 -8
- package/types/BaseMover.d.ts +2 -1
- package/types/Utils.d.ts +2 -1
- package/types/index.d.ts +1 -1
- package/umd/BaseMover.js +21 -47
- package/umd/Utils.js +34 -4
- package/umd/index.js +2 -2
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# tsParticles Standard Mover
|
|
4
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
8
|
|
|
9
9
|
[tsParticles](https://github.com/matteobruni/tsparticles) move plugin for standard movement effect.
|
|
10
10
|
|
|
@@ -42,29 +42,33 @@ Once the scripts are loaded you can set up `tsParticles` and the interaction plu
|
|
|
42
42
|
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
43
|
|
|
44
44
|
```shell
|
|
45
|
-
$ npm install tsparticles
|
|
45
|
+
$ npm install @tsparticles/move-base
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
or
|
|
49
49
|
|
|
50
50
|
```shell
|
|
51
|
-
$ yarn add tsparticles
|
|
51
|
+
$ yarn add @tsparticles/move-base
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Then you need to import it in the app, like this:
|
|
55
55
|
|
|
56
56
|
```javascript
|
|
57
|
-
const { tsParticles } = require("tsparticles
|
|
58
|
-
const { loadBaseMover } = require("tsparticles
|
|
57
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
58
|
+
const { loadBaseMover } = require("@tsparticles/move-base");
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
(async () => {
|
|
61
|
+
await loadBaseMover(tsParticles);
|
|
62
|
+
})();
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
or
|
|
64
66
|
|
|
65
67
|
```javascript
|
|
66
|
-
import { tsParticles } from "tsparticles
|
|
67
|
-
import { loadBaseMover } from "tsparticles
|
|
68
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
69
|
+
import { loadBaseMover } from "@tsparticles/move-base";
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
(async () => {
|
|
72
|
+
await loadBaseMover(tsParticles);
|
|
73
|
+
})();
|
|
70
74
|
```
|
package/browser/BaseMover.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { getDistance, getRangeMax, getRangeValue } from "@tsparticles/engine";
|
|
2
|
-
import { applyDistance,
|
|
1
|
+
import { getDistance, getRangeMax, getRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
import { applyDistance, getProximitySpeedFactor, move, spin } from "./Utils";
|
|
3
|
+
const diffFactor = 2;
|
|
3
4
|
export class BaseMover {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
if (spinOptions.enable) {
|
|
13
|
-
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
|
|
5
|
+
constructor() {
|
|
6
|
+
this._initSpin = (particle) => {
|
|
7
|
+
const container = particle.container, options = particle.options, spinOptions = options.move.spin;
|
|
8
|
+
if (!spinOptions.enable) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
|
|
14
12
|
x: (spinPos.x / 100) * container.canvas.size.width,
|
|
15
13
|
y: (spinPos.y / 100) * container.canvas.size.height,
|
|
16
14
|
}, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
|
|
@@ -22,56 +20,32 @@ export class BaseMover {
|
|
|
22
20
|
radius: distance,
|
|
23
21
|
acceleration: particle.retina.spinAcceleration,
|
|
24
22
|
};
|
|
25
|
-
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
init(particle) {
|
|
26
|
+
const options = particle.options, gravityOptions = options.move.gravity;
|
|
27
|
+
particle.gravity = {
|
|
28
|
+
enable: gravityOptions.enable,
|
|
29
|
+
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
30
|
+
inverse: gravityOptions.inverse,
|
|
31
|
+
};
|
|
32
|
+
this._initSpin(particle);
|
|
26
33
|
}
|
|
27
34
|
isEnabled(particle) {
|
|
28
35
|
return !particle.destroyed && particle.options.move.enable;
|
|
29
36
|
}
|
|
30
37
|
move(particle, delta) {
|
|
31
|
-
var _a, _b, _c;
|
|
32
|
-
var _d, _e;
|
|
33
38
|
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
34
39
|
if (!moveOptions.enable) {
|
|
35
40
|
return;
|
|
36
41
|
}
|
|
37
|
-
const container = particle.container, slowFactor = getProximitySpeedFactor(particle), baseSpeed = (
|
|
38
|
-
container.retina.reduceFactor, moveDrift = (
|
|
42
|
+
const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = getProximitySpeedFactor(particle), baseSpeed = (particle.retina.moveSpeed ??= getRangeValue(moveOptions.speed) * pxRatio) *
|
|
43
|
+
container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= getRangeValue(particle.options.move.drift) * pxRatio), maxSize = getRangeMax(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
|
|
39
44
|
if (moveOptions.spin.enable) {
|
|
40
45
|
spin(particle, moveSpeed);
|
|
41
46
|
}
|
|
42
47
|
else {
|
|
43
|
-
|
|
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
|
-
}
|
|
48
|
+
move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
|
|
75
49
|
}
|
|
76
50
|
applyDistance(particle);
|
|
77
51
|
}
|
package/browser/Utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { clamp, getDistances, getRandom } from "@tsparticles/engine";
|
|
1
|
+
import { clamp, getDistances, getRandom, } from "@tsparticles/engine";
|
|
2
2
|
export function applyDistance(particle) {
|
|
3
|
-
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy),
|
|
3
|
+
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical;
|
|
4
4
|
if (!hDistance && !vDistance) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
@@ -26,6 +26,36 @@ export function applyDistance(particle) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
export function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
30
|
+
applyPath(particle, delta);
|
|
31
|
+
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1;
|
|
32
|
+
if (moveDrift && moveSpeed) {
|
|
33
|
+
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
|
|
34
|
+
}
|
|
35
|
+
if (gravityOptions?.enable && moveSpeed) {
|
|
36
|
+
particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
|
|
37
|
+
}
|
|
38
|
+
const decay = particle.moveDecay;
|
|
39
|
+
particle.velocity.multTo(decay);
|
|
40
|
+
const velocity = particle.velocity.mult(moveSpeed);
|
|
41
|
+
if (gravityOptions?.enable &&
|
|
42
|
+
maxSpeed > 0 &&
|
|
43
|
+
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
|
|
44
|
+
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
|
|
45
|
+
velocity.y = gravityFactor * maxSpeed;
|
|
46
|
+
if (moveSpeed) {
|
|
47
|
+
particle.velocity.y = velocity.y / moveSpeed;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
51
|
+
velocity.multTo(zVelocityFactor);
|
|
52
|
+
const { position } = particle;
|
|
53
|
+
position.addTo(velocity);
|
|
54
|
+
if (moveOptions.vibrate) {
|
|
55
|
+
position.x += Math.sin(position.x * Math.cos(position.y));
|
|
56
|
+
position.y += Math.cos(position.y * Math.sin(position.x));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
29
59
|
export function spin(particle, moveSpeed) {
|
|
30
60
|
const container = particle.container;
|
|
31
61
|
if (!particle.spin) {
|
|
@@ -50,7 +80,6 @@ export function spin(particle, moveSpeed) {
|
|
|
50
80
|
particle.spin.angle += (moveSpeed / 100) * (1 - particle.spin.radius / maxCanvasSize);
|
|
51
81
|
}
|
|
52
82
|
export function applyPath(particle, delta) {
|
|
53
|
-
var _a;
|
|
54
83
|
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
55
84
|
if (!pathEnabled) {
|
|
56
85
|
return;
|
|
@@ -59,7 +88,7 @@ export function applyPath(particle, delta) {
|
|
|
59
88
|
particle.lastPathTime += delta.value;
|
|
60
89
|
return;
|
|
61
90
|
}
|
|
62
|
-
const path =
|
|
91
|
+
const path = particle.pathGenerator?.generate(particle, delta);
|
|
63
92
|
if (path) {
|
|
64
93
|
particle.velocity.addTo(path);
|
|
65
94
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BaseMover } from "./BaseMover";
|
|
2
|
-
export async function loadBaseMover(engine) {
|
|
3
|
-
engine.addMover("base", () => new BaseMover());
|
|
2
|
+
export async function loadBaseMover(engine, refresh = true) {
|
|
3
|
+
await engine.addMover("base", () => new BaseMover(), refresh);
|
|
4
4
|
}
|
package/cjs/BaseMover.js
CHANGED
|
@@ -3,17 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseMover = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
5
|
const Utils_1 = require("./Utils");
|
|
6
|
+
const diffFactor = 2;
|
|
6
7
|
class BaseMover {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
if (spinOptions.enable) {
|
|
16
|
-
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
|
|
8
|
+
constructor() {
|
|
9
|
+
this._initSpin = (particle) => {
|
|
10
|
+
const container = particle.container, options = particle.options, spinOptions = options.move.spin;
|
|
11
|
+
if (!spinOptions.enable) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
|
|
17
15
|
x: (spinPos.x / 100) * container.canvas.size.width,
|
|
18
16
|
y: (spinPos.y / 100) * container.canvas.size.height,
|
|
19
17
|
}, pos = particle.getPosition(), distance = (0, engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, engine_1.getRangeValue)(spinOptions.acceleration);
|
|
@@ -25,56 +23,32 @@ class BaseMover {
|
|
|
25
23
|
radius: distance,
|
|
26
24
|
acceleration: particle.retina.spinAcceleration,
|
|
27
25
|
};
|
|
28
|
-
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
init(particle) {
|
|
29
|
+
const options = particle.options, gravityOptions = options.move.gravity;
|
|
30
|
+
particle.gravity = {
|
|
31
|
+
enable: gravityOptions.enable,
|
|
32
|
+
acceleration: (0, engine_1.getRangeValue)(gravityOptions.acceleration),
|
|
33
|
+
inverse: gravityOptions.inverse,
|
|
34
|
+
};
|
|
35
|
+
this._initSpin(particle);
|
|
29
36
|
}
|
|
30
37
|
isEnabled(particle) {
|
|
31
38
|
return !particle.destroyed && particle.options.move.enable;
|
|
32
39
|
}
|
|
33
40
|
move(particle, delta) {
|
|
34
|
-
var _a, _b, _c;
|
|
35
|
-
var _d, _e;
|
|
36
41
|
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
37
42
|
if (!moveOptions.enable) {
|
|
38
43
|
return;
|
|
39
44
|
}
|
|
40
|
-
const container = particle.container, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = (
|
|
41
|
-
container.retina.reduceFactor, moveDrift = (
|
|
45
|
+
const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = (particle.retina.moveSpeed ??= (0, engine_1.getRangeValue)(moveOptions.speed) * pxRatio) *
|
|
46
|
+
container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= (0, engine_1.getRangeValue)(particle.options.move.drift) * pxRatio), maxSize = (0, engine_1.getRangeMax)(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
|
|
42
47
|
if (moveOptions.spin.enable) {
|
|
43
48
|
(0, Utils_1.spin)(particle, moveSpeed);
|
|
44
49
|
}
|
|
45
50
|
else {
|
|
46
|
-
(0, Utils_1.
|
|
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
|
-
}
|
|
51
|
+
(0, Utils_1.move)(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
|
|
78
52
|
}
|
|
79
53
|
(0, Utils_1.applyDistance)(particle);
|
|
80
54
|
}
|
package/cjs/Utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.applyDistance = void 0;
|
|
3
|
+
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.move = exports.applyDistance = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
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),
|
|
6
|
+
const initialPosition = particle.initialPosition, { dx, dy } = (0, engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical;
|
|
7
7
|
if (!hDistance && !vDistance) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
@@ -30,6 +30,37 @@ function applyDistance(particle) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
exports.applyDistance = applyDistance;
|
|
33
|
+
function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
34
|
+
applyPath(particle, delta);
|
|
35
|
+
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1;
|
|
36
|
+
if (moveDrift && moveSpeed) {
|
|
37
|
+
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
|
|
38
|
+
}
|
|
39
|
+
if (gravityOptions?.enable && moveSpeed) {
|
|
40
|
+
particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
|
|
41
|
+
}
|
|
42
|
+
const decay = particle.moveDecay;
|
|
43
|
+
particle.velocity.multTo(decay);
|
|
44
|
+
const velocity = particle.velocity.mult(moveSpeed);
|
|
45
|
+
if (gravityOptions?.enable &&
|
|
46
|
+
maxSpeed > 0 &&
|
|
47
|
+
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
|
|
48
|
+
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
|
|
49
|
+
velocity.y = gravityFactor * maxSpeed;
|
|
50
|
+
if (moveSpeed) {
|
|
51
|
+
particle.velocity.y = velocity.y / moveSpeed;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
55
|
+
velocity.multTo(zVelocityFactor);
|
|
56
|
+
const { position } = particle;
|
|
57
|
+
position.addTo(velocity);
|
|
58
|
+
if (moveOptions.vibrate) {
|
|
59
|
+
position.x += Math.sin(position.x * Math.cos(position.y));
|
|
60
|
+
position.y += Math.cos(position.y * Math.sin(position.x));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.move = move;
|
|
33
64
|
function spin(particle, moveSpeed) {
|
|
34
65
|
const container = particle.container;
|
|
35
66
|
if (!particle.spin) {
|
|
@@ -55,7 +86,6 @@ function spin(particle, moveSpeed) {
|
|
|
55
86
|
}
|
|
56
87
|
exports.spin = spin;
|
|
57
88
|
function applyPath(particle, delta) {
|
|
58
|
-
var _a;
|
|
59
89
|
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
60
90
|
if (!pathEnabled) {
|
|
61
91
|
return;
|
|
@@ -64,7 +94,7 @@ function applyPath(particle, delta) {
|
|
|
64
94
|
particle.lastPathTime += delta.value;
|
|
65
95
|
return;
|
|
66
96
|
}
|
|
67
|
-
const path =
|
|
97
|
+
const path = particle.pathGenerator?.generate(particle, delta);
|
|
68
98
|
if (path) {
|
|
69
99
|
particle.velocity.addTo(path);
|
|
70
100
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.loadBaseMover = void 0;
|
|
13
4
|
const BaseMover_1 = require("./BaseMover");
|
|
14
|
-
function loadBaseMover(engine) {
|
|
15
|
-
|
|
16
|
-
engine.addMover("base", () => new BaseMover_1.BaseMover());
|
|
17
|
-
});
|
|
5
|
+
async function loadBaseMover(engine, refresh = true) {
|
|
6
|
+
await engine.addMover("base", () => new BaseMover_1.BaseMover(), refresh);
|
|
18
7
|
}
|
|
19
8
|
exports.loadBaseMover = loadBaseMover;
|
package/esm/BaseMover.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { getDistance, getRangeMax, getRangeValue } from "@tsparticles/engine";
|
|
2
|
-
import { applyDistance,
|
|
1
|
+
import { getDistance, getRangeMax, getRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
import { applyDistance, getProximitySpeedFactor, move, spin } from "./Utils";
|
|
3
|
+
const diffFactor = 2;
|
|
3
4
|
export class BaseMover {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
if (spinOptions.enable) {
|
|
13
|
-
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
|
|
5
|
+
constructor() {
|
|
6
|
+
this._initSpin = (particle) => {
|
|
7
|
+
const container = particle.container, options = particle.options, spinOptions = options.move.spin;
|
|
8
|
+
if (!spinOptions.enable) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
|
|
14
12
|
x: (spinPos.x / 100) * container.canvas.size.width,
|
|
15
13
|
y: (spinPos.y / 100) * container.canvas.size.height,
|
|
16
14
|
}, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
|
|
@@ -22,56 +20,32 @@ export class BaseMover {
|
|
|
22
20
|
radius: distance,
|
|
23
21
|
acceleration: particle.retina.spinAcceleration,
|
|
24
22
|
};
|
|
25
|
-
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
init(particle) {
|
|
26
|
+
const options = particle.options, gravityOptions = options.move.gravity;
|
|
27
|
+
particle.gravity = {
|
|
28
|
+
enable: gravityOptions.enable,
|
|
29
|
+
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
30
|
+
inverse: gravityOptions.inverse,
|
|
31
|
+
};
|
|
32
|
+
this._initSpin(particle);
|
|
26
33
|
}
|
|
27
34
|
isEnabled(particle) {
|
|
28
35
|
return !particle.destroyed && particle.options.move.enable;
|
|
29
36
|
}
|
|
30
37
|
move(particle, delta) {
|
|
31
|
-
var _a, _b, _c;
|
|
32
|
-
var _d, _e;
|
|
33
38
|
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
34
39
|
if (!moveOptions.enable) {
|
|
35
40
|
return;
|
|
36
41
|
}
|
|
37
|
-
const container = particle.container, slowFactor = getProximitySpeedFactor(particle), baseSpeed = (
|
|
38
|
-
container.retina.reduceFactor, moveDrift = (
|
|
42
|
+
const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = getProximitySpeedFactor(particle), baseSpeed = (particle.retina.moveSpeed ??= getRangeValue(moveOptions.speed) * pxRatio) *
|
|
43
|
+
container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= getRangeValue(particle.options.move.drift) * pxRatio), maxSize = getRangeMax(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
|
|
39
44
|
if (moveOptions.spin.enable) {
|
|
40
45
|
spin(particle, moveSpeed);
|
|
41
46
|
}
|
|
42
47
|
else {
|
|
43
|
-
|
|
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
|
-
}
|
|
48
|
+
move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
|
|
75
49
|
}
|
|
76
50
|
applyDistance(particle);
|
|
77
51
|
}
|
package/esm/Utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { clamp, getDistances, getRandom } from "@tsparticles/engine";
|
|
1
|
+
import { clamp, getDistances, getRandom, } from "@tsparticles/engine";
|
|
2
2
|
export function applyDistance(particle) {
|
|
3
|
-
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy),
|
|
3
|
+
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical;
|
|
4
4
|
if (!hDistance && !vDistance) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
@@ -26,6 +26,36 @@ export function applyDistance(particle) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
export function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
30
|
+
applyPath(particle, delta);
|
|
31
|
+
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1;
|
|
32
|
+
if (moveDrift && moveSpeed) {
|
|
33
|
+
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
|
|
34
|
+
}
|
|
35
|
+
if (gravityOptions?.enable && moveSpeed) {
|
|
36
|
+
particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
|
|
37
|
+
}
|
|
38
|
+
const decay = particle.moveDecay;
|
|
39
|
+
particle.velocity.multTo(decay);
|
|
40
|
+
const velocity = particle.velocity.mult(moveSpeed);
|
|
41
|
+
if (gravityOptions?.enable &&
|
|
42
|
+
maxSpeed > 0 &&
|
|
43
|
+
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
|
|
44
|
+
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
|
|
45
|
+
velocity.y = gravityFactor * maxSpeed;
|
|
46
|
+
if (moveSpeed) {
|
|
47
|
+
particle.velocity.y = velocity.y / moveSpeed;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
51
|
+
velocity.multTo(zVelocityFactor);
|
|
52
|
+
const { position } = particle;
|
|
53
|
+
position.addTo(velocity);
|
|
54
|
+
if (moveOptions.vibrate) {
|
|
55
|
+
position.x += Math.sin(position.x * Math.cos(position.y));
|
|
56
|
+
position.y += Math.cos(position.y * Math.sin(position.x));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
29
59
|
export function spin(particle, moveSpeed) {
|
|
30
60
|
const container = particle.container;
|
|
31
61
|
if (!particle.spin) {
|
|
@@ -50,7 +80,6 @@ export function spin(particle, moveSpeed) {
|
|
|
50
80
|
particle.spin.angle += (moveSpeed / 100) * (1 - particle.spin.radius / maxCanvasSize);
|
|
51
81
|
}
|
|
52
82
|
export function applyPath(particle, delta) {
|
|
53
|
-
var _a;
|
|
54
83
|
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
55
84
|
if (!pathEnabled) {
|
|
56
85
|
return;
|
|
@@ -59,7 +88,7 @@ export function applyPath(particle, delta) {
|
|
|
59
88
|
particle.lastPathTime += delta.value;
|
|
60
89
|
return;
|
|
61
90
|
}
|
|
62
|
-
const path =
|
|
91
|
+
const path = particle.pathGenerator?.generate(particle, delta);
|
|
63
92
|
if (path) {
|
|
64
93
|
particle.velocity.addTo(path);
|
|
65
94
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BaseMover } from "./BaseMover";
|
|
2
|
-
export async function loadBaseMover(engine) {
|
|
3
|
-
engine.addMover("base", () => new BaseMover());
|
|
2
|
+
export async function loadBaseMover(engine, refresh = true) {
|
|
3
|
+
await engine.addMover("base", () => new BaseMover(), refresh);
|
|
4
4
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/move-base",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"description": "tsParticles Base movement",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -73,10 +73,11 @@
|
|
|
73
73
|
"unpkg": "tsparticles.move.base.min.js",
|
|
74
74
|
"module": "esm/index.js",
|
|
75
75
|
"types": "types/index.d.ts",
|
|
76
|
+
"sideEffects": false,
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"@tsparticles/engine": "^3.0.0-beta.0"
|
|
79
|
+
},
|
|
76
80
|
"publishConfig": {
|
|
77
81
|
"access": "public"
|
|
78
|
-
},
|
|
79
|
-
"dependencies": {
|
|
80
|
-
"@tsparticles/engine": "^3.0.0-alpha.0"
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
+
}
|