@tsparticles/move-base 3.0.2 → 3.1.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/browser/BaseMover.js +10 -7
- package/browser/Utils.js +26 -21
- package/cjs/BaseMover.js +10 -7
- package/cjs/Utils.js +26 -21
- package/esm/BaseMover.js +10 -7
- package/esm/Utils.js +26 -21
- package/package.json +2 -2
- package/report.html +2 -2
- package/tsparticles.move.base.js +45 -30
- package/tsparticles.move.base.min.js +1 -1
- package/tsparticles.move.base.min.js.LICENSE.txt +1 -1
- package/umd/BaseMover.js +10 -7
- package/umd/Utils.js +26 -21
package/browser/BaseMover.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getDistance, getRangeMax, getRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
import { applyDistance, getProximitySpeedFactor, move, spin } from "./Utils.js";
|
|
3
|
-
const diffFactor = 2;
|
|
3
|
+
const diffFactor = 2, defaultSizeFactor = 1, defaultDeltaFactor = 1;
|
|
4
4
|
export class BaseMover {
|
|
5
5
|
constructor() {
|
|
6
6
|
this._initSpin = (particle) => {
|
|
@@ -8,14 +8,15 @@ export class BaseMover {
|
|
|
8
8
|
if (!spinOptions.enable) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
|
|
12
|
-
x: spinPos.x *
|
|
13
|
-
y: spinPos.y *
|
|
11
|
+
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinFactor = 0.01, spinCenter = {
|
|
12
|
+
x: spinPos.x * spinFactor * container.canvas.size.width,
|
|
13
|
+
y: spinPos.y * spinFactor * container.canvas.size.height,
|
|
14
14
|
}, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
|
|
15
15
|
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
16
|
+
const minVelocity = 0;
|
|
16
17
|
particle.spin = {
|
|
17
18
|
center: spinCenter,
|
|
18
|
-
direction: particle.velocity.x >=
|
|
19
|
+
direction: particle.velocity.x >= minVelocity ? "clockwise" : "counter-clockwise",
|
|
19
20
|
angle: particle.velocity.angle,
|
|
20
21
|
radius: distance,
|
|
21
22
|
acceleration: particle.retina.spinAcceleration,
|
|
@@ -39,8 +40,10 @@ export class BaseMover {
|
|
|
39
40
|
if (!moveOptions.enable) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
const container = particle.container, pxRatio = container.retina.pixelRatio
|
|
43
|
-
|
|
43
|
+
const container = particle.container, pxRatio = container.retina.pixelRatio;
|
|
44
|
+
particle.retina.moveSpeed ??= getRangeValue(moveOptions.speed) * pxRatio;
|
|
45
|
+
particle.retina.moveDrift ??= getRangeValue(particle.options.move.drift) * pxRatio;
|
|
46
|
+
const slowFactor = getProximitySpeedFactor(particle), baseSpeed = particle.retina.moveSpeed * container.retina.reduceFactor, moveDrift = particle.retina.moveDrift, maxSize = getRangeMax(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : defaultSizeFactor, deltaFactor = delta.factor || defaultDeltaFactor, moveSpeed = (baseSpeed * sizeFactor * slowFactor * deltaFactor) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
|
|
44
47
|
if (moveOptions.spin.enable) {
|
|
45
48
|
spin(particle, moveSpeed);
|
|
46
49
|
}
|
package/browser/Utils.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { clamp, getDistances, getRandom, } from "@tsparticles/engine";
|
|
2
|
+
const half = 0.5, minVelocity = 0, identity = 1, moveSpeedFactor = 60, minSpinRadius = 0, spinFactor = 0.01;
|
|
2
3
|
export function applyDistance(particle) {
|
|
3
4
|
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
5
|
if (!hDistance && !vDistance) {
|
|
5
6
|
return;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
const hasHDistance = (hDistance && dxFixed >= hDistance) ?? false, hasVDistance = (vDistance && dyFixed >= vDistance) ?? false;
|
|
9
|
+
if ((hasHDistance || hasVDistance) && !particle.misplaced) {
|
|
8
10
|
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
9
11
|
if (hDistance) {
|
|
10
|
-
particle.velocity.x = particle.velocity.y *
|
|
12
|
+
particle.velocity.x = particle.velocity.y * half - particle.velocity.x;
|
|
11
13
|
}
|
|
12
14
|
if (vDistance) {
|
|
13
|
-
particle.velocity.y = particle.velocity.x *
|
|
15
|
+
particle.velocity.y = particle.velocity.x * half - particle.velocity.y;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
@@ -18,36 +20,39 @@ export function applyDistance(particle) {
|
|
|
18
20
|
}
|
|
19
21
|
else if (particle.misplaced) {
|
|
20
22
|
const pos = particle.position, vel = particle.velocity;
|
|
21
|
-
if (hDistance &&
|
|
23
|
+
if (hDistance &&
|
|
24
|
+
((pos.x < initialPosition.x && vel.x < minVelocity) || (pos.x > initialPosition.x && vel.x > minVelocity))) {
|
|
22
25
|
vel.x *= -getRandom();
|
|
23
26
|
}
|
|
24
|
-
if (vDistance &&
|
|
27
|
+
if (vDistance &&
|
|
28
|
+
((pos.y < initialPosition.y && vel.y < minVelocity) || (pos.y > initialPosition.y && vel.y > minVelocity))) {
|
|
25
29
|
vel.y *= -getRandom();
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
export function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
30
34
|
applyPath(particle, delta);
|
|
31
|
-
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -
|
|
35
|
+
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -identity : identity;
|
|
32
36
|
if (moveDrift && moveSpeed) {
|
|
33
|
-
particle.velocity.x += (moveDrift * delta.factor) / (
|
|
37
|
+
particle.velocity.x += (moveDrift * delta.factor) / (moveSpeedFactor * moveSpeed);
|
|
34
38
|
}
|
|
35
39
|
if (gravityOptions?.enable && moveSpeed) {
|
|
36
|
-
particle.velocity.y +=
|
|
40
|
+
particle.velocity.y +=
|
|
41
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (moveSpeedFactor * moveSpeed);
|
|
37
42
|
}
|
|
38
43
|
const decay = particle.moveDecay;
|
|
39
44
|
particle.velocity.multTo(decay);
|
|
40
45
|
const velocity = particle.velocity.mult(moveSpeed);
|
|
41
46
|
if (gravityOptions?.enable &&
|
|
42
|
-
maxSpeed >
|
|
43
|
-
((!gravityOptions.inverse && velocity.y >=
|
|
44
|
-
(gravityOptions.inverse && velocity.y <=
|
|
47
|
+
maxSpeed > minVelocity &&
|
|
48
|
+
((!gravityOptions.inverse && velocity.y >= minVelocity && velocity.y >= maxSpeed) ||
|
|
49
|
+
(gravityOptions.inverse && velocity.y <= minVelocity && velocity.y <= -maxSpeed))) {
|
|
45
50
|
velocity.y = gravityFactor * maxSpeed;
|
|
46
51
|
if (moveSpeed) {
|
|
47
52
|
particle.velocity.y = velocity.y / moveSpeed;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
|
-
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (
|
|
55
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (identity - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
51
56
|
velocity.multTo(zVelocityFactor);
|
|
52
57
|
const { position } = particle;
|
|
53
58
|
position.addTo(velocity);
|
|
@@ -68,16 +73,16 @@ export function spin(particle, moveSpeed) {
|
|
|
68
73
|
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
69
74
|
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
70
75
|
particle.spin.radius += particle.spin.acceleration;
|
|
71
|
-
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize *
|
|
76
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize * half;
|
|
72
77
|
if (particle.spin.radius > halfMaxSize) {
|
|
73
78
|
particle.spin.radius = halfMaxSize;
|
|
74
|
-
particle.spin.acceleration *= -
|
|
79
|
+
particle.spin.acceleration *= -identity;
|
|
75
80
|
}
|
|
76
|
-
else if (particle.spin.radius <
|
|
77
|
-
particle.spin.radius =
|
|
78
|
-
particle.spin.acceleration *= -
|
|
81
|
+
else if (particle.spin.radius < minSpinRadius) {
|
|
82
|
+
particle.spin.radius = minSpinRadius;
|
|
83
|
+
particle.spin.acceleration *= -identity;
|
|
79
84
|
}
|
|
80
|
-
particle.spin.angle += moveSpeed *
|
|
85
|
+
particle.spin.angle += moveSpeed * spinFactor * (identity - particle.spin.radius / maxCanvasSize);
|
|
81
86
|
}
|
|
82
87
|
export function applyPath(particle, delta) {
|
|
83
88
|
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
@@ -93,11 +98,11 @@ export function applyPath(particle, delta) {
|
|
|
93
98
|
particle.velocity.addTo(path);
|
|
94
99
|
}
|
|
95
100
|
if (pathOptions.clamp) {
|
|
96
|
-
particle.velocity.x = clamp(particle.velocity.x, -
|
|
97
|
-
particle.velocity.y = clamp(particle.velocity.y, -
|
|
101
|
+
particle.velocity.x = clamp(particle.velocity.x, -identity, identity);
|
|
102
|
+
particle.velocity.y = clamp(particle.velocity.y, -identity, identity);
|
|
98
103
|
}
|
|
99
104
|
particle.lastPathTime -= particle.pathDelay;
|
|
100
105
|
}
|
|
101
106
|
export function getProximitySpeedFactor(particle) {
|
|
102
|
-
return particle.slow.inRange ? particle.slow.factor :
|
|
107
|
+
return particle.slow.inRange ? particle.slow.factor : identity;
|
|
103
108
|
}
|
package/cjs/BaseMover.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseMover = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
5
|
const Utils_js_1 = require("./Utils.js");
|
|
6
|
-
const diffFactor = 2;
|
|
6
|
+
const diffFactor = 2, defaultSizeFactor = 1, defaultDeltaFactor = 1;
|
|
7
7
|
class BaseMover {
|
|
8
8
|
constructor() {
|
|
9
9
|
this._initSpin = (particle) => {
|
|
@@ -11,14 +11,15 @@ class BaseMover {
|
|
|
11
11
|
if (!spinOptions.enable) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
|
|
15
|
-
x: spinPos.x *
|
|
16
|
-
y: spinPos.y *
|
|
14
|
+
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinFactor = 0.01, spinCenter = {
|
|
15
|
+
x: spinPos.x * spinFactor * container.canvas.size.width,
|
|
16
|
+
y: spinPos.y * spinFactor * container.canvas.size.height,
|
|
17
17
|
}, pos = particle.getPosition(), distance = (0, engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, engine_1.getRangeValue)(spinOptions.acceleration);
|
|
18
18
|
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
19
|
+
const minVelocity = 0;
|
|
19
20
|
particle.spin = {
|
|
20
21
|
center: spinCenter,
|
|
21
|
-
direction: particle.velocity.x >=
|
|
22
|
+
direction: particle.velocity.x >= minVelocity ? "clockwise" : "counter-clockwise",
|
|
22
23
|
angle: particle.velocity.angle,
|
|
23
24
|
radius: distance,
|
|
24
25
|
acceleration: particle.retina.spinAcceleration,
|
|
@@ -42,8 +43,10 @@ class BaseMover {
|
|
|
42
43
|
if (!moveOptions.enable) {
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
|
-
const container = particle.container, pxRatio = container.retina.pixelRatio
|
|
46
|
-
|
|
46
|
+
const container = particle.container, pxRatio = container.retina.pixelRatio;
|
|
47
|
+
particle.retina.moveSpeed ??= (0, engine_1.getRangeValue)(moveOptions.speed) * pxRatio;
|
|
48
|
+
particle.retina.moveDrift ??= (0, engine_1.getRangeValue)(particle.options.move.drift) * pxRatio;
|
|
49
|
+
const slowFactor = (0, Utils_js_1.getProximitySpeedFactor)(particle), baseSpeed = particle.retina.moveSpeed * container.retina.reduceFactor, moveDrift = particle.retina.moveDrift, maxSize = (0, engine_1.getRangeMax)(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : defaultSizeFactor, deltaFactor = delta.factor || defaultDeltaFactor, moveSpeed = (baseSpeed * sizeFactor * slowFactor * deltaFactor) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
|
|
47
50
|
if (moveOptions.spin.enable) {
|
|
48
51
|
(0, Utils_js_1.spin)(particle, moveSpeed);
|
|
49
52
|
}
|
package/cjs/Utils.js
CHANGED
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.move = exports.applyDistance = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const half = 0.5, minVelocity = 0, identity = 1, moveSpeedFactor = 60, minSpinRadius = 0, spinFactor = 0.01;
|
|
5
6
|
function applyDistance(particle) {
|
|
6
7
|
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
8
|
if (!hDistance && !vDistance) {
|
|
8
9
|
return;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
const hasHDistance = (hDistance && dxFixed >= hDistance) ?? false, hasVDistance = (vDistance && dyFixed >= vDistance) ?? false;
|
|
12
|
+
if ((hasHDistance || hasVDistance) && !particle.misplaced) {
|
|
11
13
|
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
12
14
|
if (hDistance) {
|
|
13
|
-
particle.velocity.x = particle.velocity.y *
|
|
15
|
+
particle.velocity.x = particle.velocity.y * half - particle.velocity.x;
|
|
14
16
|
}
|
|
15
17
|
if (vDistance) {
|
|
16
|
-
particle.velocity.y = particle.velocity.x *
|
|
18
|
+
particle.velocity.y = particle.velocity.x * half - particle.velocity.y;
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
@@ -21,10 +23,12 @@ function applyDistance(particle) {
|
|
|
21
23
|
}
|
|
22
24
|
else if (particle.misplaced) {
|
|
23
25
|
const pos = particle.position, vel = particle.velocity;
|
|
24
|
-
if (hDistance &&
|
|
26
|
+
if (hDistance &&
|
|
27
|
+
((pos.x < initialPosition.x && vel.x < minVelocity) || (pos.x > initialPosition.x && vel.x > minVelocity))) {
|
|
25
28
|
vel.x *= -(0, engine_1.getRandom)();
|
|
26
29
|
}
|
|
27
|
-
if (vDistance &&
|
|
30
|
+
if (vDistance &&
|
|
31
|
+
((pos.y < initialPosition.y && vel.y < minVelocity) || (pos.y > initialPosition.y && vel.y > minVelocity))) {
|
|
28
32
|
vel.y *= -(0, engine_1.getRandom)();
|
|
29
33
|
}
|
|
30
34
|
}
|
|
@@ -32,26 +36,27 @@ function applyDistance(particle) {
|
|
|
32
36
|
exports.applyDistance = applyDistance;
|
|
33
37
|
function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
34
38
|
applyPath(particle, delta);
|
|
35
|
-
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -
|
|
39
|
+
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -identity : identity;
|
|
36
40
|
if (moveDrift && moveSpeed) {
|
|
37
|
-
particle.velocity.x += (moveDrift * delta.factor) / (
|
|
41
|
+
particle.velocity.x += (moveDrift * delta.factor) / (moveSpeedFactor * moveSpeed);
|
|
38
42
|
}
|
|
39
43
|
if (gravityOptions?.enable && moveSpeed) {
|
|
40
|
-
particle.velocity.y +=
|
|
44
|
+
particle.velocity.y +=
|
|
45
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (moveSpeedFactor * moveSpeed);
|
|
41
46
|
}
|
|
42
47
|
const decay = particle.moveDecay;
|
|
43
48
|
particle.velocity.multTo(decay);
|
|
44
49
|
const velocity = particle.velocity.mult(moveSpeed);
|
|
45
50
|
if (gravityOptions?.enable &&
|
|
46
|
-
maxSpeed >
|
|
47
|
-
((!gravityOptions.inverse && velocity.y >=
|
|
48
|
-
(gravityOptions.inverse && velocity.y <=
|
|
51
|
+
maxSpeed > minVelocity &&
|
|
52
|
+
((!gravityOptions.inverse && velocity.y >= minVelocity && velocity.y >= maxSpeed) ||
|
|
53
|
+
(gravityOptions.inverse && velocity.y <= minVelocity && velocity.y <= -maxSpeed))) {
|
|
49
54
|
velocity.y = gravityFactor * maxSpeed;
|
|
50
55
|
if (moveSpeed) {
|
|
51
56
|
particle.velocity.y = velocity.y / moveSpeed;
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
|
-
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (
|
|
59
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (identity - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
55
60
|
velocity.multTo(zVelocityFactor);
|
|
56
61
|
const { position } = particle;
|
|
57
62
|
position.addTo(velocity);
|
|
@@ -73,16 +78,16 @@ function spin(particle, moveSpeed) {
|
|
|
73
78
|
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
74
79
|
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
75
80
|
particle.spin.radius += particle.spin.acceleration;
|
|
76
|
-
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize *
|
|
81
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize * half;
|
|
77
82
|
if (particle.spin.radius > halfMaxSize) {
|
|
78
83
|
particle.spin.radius = halfMaxSize;
|
|
79
|
-
particle.spin.acceleration *= -
|
|
84
|
+
particle.spin.acceleration *= -identity;
|
|
80
85
|
}
|
|
81
|
-
else if (particle.spin.radius <
|
|
82
|
-
particle.spin.radius =
|
|
83
|
-
particle.spin.acceleration *= -
|
|
86
|
+
else if (particle.spin.radius < minSpinRadius) {
|
|
87
|
+
particle.spin.radius = minSpinRadius;
|
|
88
|
+
particle.spin.acceleration *= -identity;
|
|
84
89
|
}
|
|
85
|
-
particle.spin.angle += moveSpeed *
|
|
90
|
+
particle.spin.angle += moveSpeed * spinFactor * (identity - particle.spin.radius / maxCanvasSize);
|
|
86
91
|
}
|
|
87
92
|
exports.spin = spin;
|
|
88
93
|
function applyPath(particle, delta) {
|
|
@@ -99,13 +104,13 @@ function applyPath(particle, delta) {
|
|
|
99
104
|
particle.velocity.addTo(path);
|
|
100
105
|
}
|
|
101
106
|
if (pathOptions.clamp) {
|
|
102
|
-
particle.velocity.x = (0, engine_1.clamp)(particle.velocity.x, -
|
|
103
|
-
particle.velocity.y = (0, engine_1.clamp)(particle.velocity.y, -
|
|
107
|
+
particle.velocity.x = (0, engine_1.clamp)(particle.velocity.x, -identity, identity);
|
|
108
|
+
particle.velocity.y = (0, engine_1.clamp)(particle.velocity.y, -identity, identity);
|
|
104
109
|
}
|
|
105
110
|
particle.lastPathTime -= particle.pathDelay;
|
|
106
111
|
}
|
|
107
112
|
exports.applyPath = applyPath;
|
|
108
113
|
function getProximitySpeedFactor(particle) {
|
|
109
|
-
return particle.slow.inRange ? particle.slow.factor :
|
|
114
|
+
return particle.slow.inRange ? particle.slow.factor : identity;
|
|
110
115
|
}
|
|
111
116
|
exports.getProximitySpeedFactor = getProximitySpeedFactor;
|
package/esm/BaseMover.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getDistance, getRangeMax, getRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
import { applyDistance, getProximitySpeedFactor, move, spin } from "./Utils.js";
|
|
3
|
-
const diffFactor = 2;
|
|
3
|
+
const diffFactor = 2, defaultSizeFactor = 1, defaultDeltaFactor = 1;
|
|
4
4
|
export class BaseMover {
|
|
5
5
|
constructor() {
|
|
6
6
|
this._initSpin = (particle) => {
|
|
@@ -8,14 +8,15 @@ export class BaseMover {
|
|
|
8
8
|
if (!spinOptions.enable) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
|
|
12
|
-
x: spinPos.x *
|
|
13
|
-
y: spinPos.y *
|
|
11
|
+
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinFactor = 0.01, spinCenter = {
|
|
12
|
+
x: spinPos.x * spinFactor * container.canvas.size.width,
|
|
13
|
+
y: spinPos.y * spinFactor * container.canvas.size.height,
|
|
14
14
|
}, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
|
|
15
15
|
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
16
|
+
const minVelocity = 0;
|
|
16
17
|
particle.spin = {
|
|
17
18
|
center: spinCenter,
|
|
18
|
-
direction: particle.velocity.x >=
|
|
19
|
+
direction: particle.velocity.x >= minVelocity ? "clockwise" : "counter-clockwise",
|
|
19
20
|
angle: particle.velocity.angle,
|
|
20
21
|
radius: distance,
|
|
21
22
|
acceleration: particle.retina.spinAcceleration,
|
|
@@ -39,8 +40,10 @@ export class BaseMover {
|
|
|
39
40
|
if (!moveOptions.enable) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
const container = particle.container, pxRatio = container.retina.pixelRatio
|
|
43
|
-
|
|
43
|
+
const container = particle.container, pxRatio = container.retina.pixelRatio;
|
|
44
|
+
particle.retina.moveSpeed ??= getRangeValue(moveOptions.speed) * pxRatio;
|
|
45
|
+
particle.retina.moveDrift ??= getRangeValue(particle.options.move.drift) * pxRatio;
|
|
46
|
+
const slowFactor = getProximitySpeedFactor(particle), baseSpeed = particle.retina.moveSpeed * container.retina.reduceFactor, moveDrift = particle.retina.moveDrift, maxSize = getRangeMax(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : defaultSizeFactor, deltaFactor = delta.factor || defaultDeltaFactor, moveSpeed = (baseSpeed * sizeFactor * slowFactor * deltaFactor) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
|
|
44
47
|
if (moveOptions.spin.enable) {
|
|
45
48
|
spin(particle, moveSpeed);
|
|
46
49
|
}
|
package/esm/Utils.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { clamp, getDistances, getRandom, } from "@tsparticles/engine";
|
|
2
|
+
const half = 0.5, minVelocity = 0, identity = 1, moveSpeedFactor = 60, minSpinRadius = 0, spinFactor = 0.01;
|
|
2
3
|
export function applyDistance(particle) {
|
|
3
4
|
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
5
|
if (!hDistance && !vDistance) {
|
|
5
6
|
return;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
const hasHDistance = (hDistance && dxFixed >= hDistance) ?? false, hasVDistance = (vDistance && dyFixed >= vDistance) ?? false;
|
|
9
|
+
if ((hasHDistance || hasVDistance) && !particle.misplaced) {
|
|
8
10
|
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
9
11
|
if (hDistance) {
|
|
10
|
-
particle.velocity.x = particle.velocity.y *
|
|
12
|
+
particle.velocity.x = particle.velocity.y * half - particle.velocity.x;
|
|
11
13
|
}
|
|
12
14
|
if (vDistance) {
|
|
13
|
-
particle.velocity.y = particle.velocity.x *
|
|
15
|
+
particle.velocity.y = particle.velocity.x * half - particle.velocity.y;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
@@ -18,36 +20,39 @@ export function applyDistance(particle) {
|
|
|
18
20
|
}
|
|
19
21
|
else if (particle.misplaced) {
|
|
20
22
|
const pos = particle.position, vel = particle.velocity;
|
|
21
|
-
if (hDistance &&
|
|
23
|
+
if (hDistance &&
|
|
24
|
+
((pos.x < initialPosition.x && vel.x < minVelocity) || (pos.x > initialPosition.x && vel.x > minVelocity))) {
|
|
22
25
|
vel.x *= -getRandom();
|
|
23
26
|
}
|
|
24
|
-
if (vDistance &&
|
|
27
|
+
if (vDistance &&
|
|
28
|
+
((pos.y < initialPosition.y && vel.y < minVelocity) || (pos.y > initialPosition.y && vel.y > minVelocity))) {
|
|
25
29
|
vel.y *= -getRandom();
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
export function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
30
34
|
applyPath(particle, delta);
|
|
31
|
-
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -
|
|
35
|
+
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -identity : identity;
|
|
32
36
|
if (moveDrift && moveSpeed) {
|
|
33
|
-
particle.velocity.x += (moveDrift * delta.factor) / (
|
|
37
|
+
particle.velocity.x += (moveDrift * delta.factor) / (moveSpeedFactor * moveSpeed);
|
|
34
38
|
}
|
|
35
39
|
if (gravityOptions?.enable && moveSpeed) {
|
|
36
|
-
particle.velocity.y +=
|
|
40
|
+
particle.velocity.y +=
|
|
41
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (moveSpeedFactor * moveSpeed);
|
|
37
42
|
}
|
|
38
43
|
const decay = particle.moveDecay;
|
|
39
44
|
particle.velocity.multTo(decay);
|
|
40
45
|
const velocity = particle.velocity.mult(moveSpeed);
|
|
41
46
|
if (gravityOptions?.enable &&
|
|
42
|
-
maxSpeed >
|
|
43
|
-
((!gravityOptions.inverse && velocity.y >=
|
|
44
|
-
(gravityOptions.inverse && velocity.y <=
|
|
47
|
+
maxSpeed > minVelocity &&
|
|
48
|
+
((!gravityOptions.inverse && velocity.y >= minVelocity && velocity.y >= maxSpeed) ||
|
|
49
|
+
(gravityOptions.inverse && velocity.y <= minVelocity && velocity.y <= -maxSpeed))) {
|
|
45
50
|
velocity.y = gravityFactor * maxSpeed;
|
|
46
51
|
if (moveSpeed) {
|
|
47
52
|
particle.velocity.y = velocity.y / moveSpeed;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
|
-
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (
|
|
55
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (identity - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
51
56
|
velocity.multTo(zVelocityFactor);
|
|
52
57
|
const { position } = particle;
|
|
53
58
|
position.addTo(velocity);
|
|
@@ -68,16 +73,16 @@ export function spin(particle, moveSpeed) {
|
|
|
68
73
|
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
69
74
|
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
70
75
|
particle.spin.radius += particle.spin.acceleration;
|
|
71
|
-
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize *
|
|
76
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize * half;
|
|
72
77
|
if (particle.spin.radius > halfMaxSize) {
|
|
73
78
|
particle.spin.radius = halfMaxSize;
|
|
74
|
-
particle.spin.acceleration *= -
|
|
79
|
+
particle.spin.acceleration *= -identity;
|
|
75
80
|
}
|
|
76
|
-
else if (particle.spin.radius <
|
|
77
|
-
particle.spin.radius =
|
|
78
|
-
particle.spin.acceleration *= -
|
|
81
|
+
else if (particle.spin.radius < minSpinRadius) {
|
|
82
|
+
particle.spin.radius = minSpinRadius;
|
|
83
|
+
particle.spin.acceleration *= -identity;
|
|
79
84
|
}
|
|
80
|
-
particle.spin.angle += moveSpeed *
|
|
85
|
+
particle.spin.angle += moveSpeed * spinFactor * (identity - particle.spin.radius / maxCanvasSize);
|
|
81
86
|
}
|
|
82
87
|
export function applyPath(particle, delta) {
|
|
83
88
|
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
@@ -93,11 +98,11 @@ export function applyPath(particle, delta) {
|
|
|
93
98
|
particle.velocity.addTo(path);
|
|
94
99
|
}
|
|
95
100
|
if (pathOptions.clamp) {
|
|
96
|
-
particle.velocity.x = clamp(particle.velocity.x, -
|
|
97
|
-
particle.velocity.y = clamp(particle.velocity.y, -
|
|
101
|
+
particle.velocity.x = clamp(particle.velocity.x, -identity, identity);
|
|
102
|
+
particle.velocity.y = clamp(particle.velocity.y, -identity, identity);
|
|
98
103
|
}
|
|
99
104
|
particle.lastPathTime -= particle.pathDelay;
|
|
100
105
|
}
|
|
101
106
|
export function getProximitySpeedFactor(particle) {
|
|
102
|
-
return particle.slow.inRange ? particle.slow.factor :
|
|
107
|
+
return particle.slow.inRange ? particle.slow.factor : identity;
|
|
103
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/move-base",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "tsParticles Base movement",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"./package.json": "./package.json"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@tsparticles/engine": "^3.0
|
|
90
|
+
"@tsparticles/engine": "^3.1.0"
|
|
91
91
|
},
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|
package/report.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8"/>
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
6
|
-
<title>@tsparticles/move-base [
|
|
6
|
+
<title>@tsparticles/move-base [13 Jan 2024 at 23:01]</title>
|
|
7
7
|
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
|
|
8
8
|
|
|
9
9
|
<script>
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
<body>
|
|
32
32
|
<div id="app"></div>
|
|
33
33
|
<script>
|
|
34
|
-
window.chartData = [{"label":"tsparticles.move.base.js","isAsset":true,"statSize":
|
|
34
|
+
window.chartData = [{"label":"tsparticles.move.base.js","isAsset":true,"statSize":8064,"parsedSize":11940,"gzipSize":3260,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":8022,"groups":[{"id":208,"label":"index.js + 2 modules (concatenated)","path":"./dist/browser/index.js + 2 modules (concatenated)","statSize":8022,"parsedSize":11940,"gzipSize":3260,"concatenated":true,"groups":[{"label":"dist/browser","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser","statSize":8022,"groups":[{"id":null,"label":"index.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/index.js","statSize":172,"parsedSize":256,"gzipSize":69,"inaccurateSizes":true},{"id":null,"label":"BaseMover.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/BaseMover.js","statSize":2892,"parsedSize":4304,"gzipSize":1175,"inaccurateSizes":true},{"id":null,"label":"Utils.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/Utils.js","statSize":4958,"parsedSize":7379,"gzipSize":2014,"inaccurateSizes":true}],"parsedSize":11940,"gzipSize":3260,"inaccurateSizes":true}]}],"parsedSize":11940,"gzipSize":3260},{"label":"engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":533,"label":"engine\",\"root\":\"window\"}","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles/engine\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0}],"isInitialByEntrypoint":{"tsparticles.move.base":true}}];
|
|
35
35
|
window.entrypoints = ["tsparticles.move.base","tsparticles.move.base.min"];
|
|
36
36
|
window.defaultSizes = "parsed";
|
|
37
37
|
</script>
|
package/tsparticles.move.base.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Demo / Generator : https://particles.js.org/
|
|
5
5
|
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
6
|
* How to use? : Check the GitHub README
|
|
7
|
-
* v3.0
|
|
7
|
+
* v3.1.0
|
|
8
8
|
*/
|
|
9
9
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
10
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
@@ -98,6 +98,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
98
98
|
var engine_root_window_ = __webpack_require__(533);
|
|
99
99
|
;// CONCATENATED MODULE: ./dist/browser/Utils.js
|
|
100
100
|
|
|
101
|
+
const half = 0.5,
|
|
102
|
+
minVelocity = 0,
|
|
103
|
+
identity = 1,
|
|
104
|
+
moveSpeedFactor = 60,
|
|
105
|
+
minSpinRadius = 0,
|
|
106
|
+
spinFactor = 0.01;
|
|
101
107
|
function applyDistance(particle) {
|
|
102
108
|
const initialPosition = particle.initialPosition,
|
|
103
109
|
{
|
|
@@ -114,23 +120,25 @@ function applyDistance(particle) {
|
|
|
114
120
|
if (!hDistance && !vDistance) {
|
|
115
121
|
return;
|
|
116
122
|
}
|
|
117
|
-
|
|
123
|
+
const hasHDistance = (hDistance && dxFixed >= hDistance) ?? false,
|
|
124
|
+
hasVDistance = (vDistance && dyFixed >= vDistance) ?? false;
|
|
125
|
+
if ((hasHDistance || hasVDistance) && !particle.misplaced) {
|
|
118
126
|
particle.misplaced = !!hDistance && dxFixed > hDistance || !!vDistance && dyFixed > vDistance;
|
|
119
127
|
if (hDistance) {
|
|
120
|
-
particle.velocity.x = particle.velocity.y *
|
|
128
|
+
particle.velocity.x = particle.velocity.y * half - particle.velocity.x;
|
|
121
129
|
}
|
|
122
130
|
if (vDistance) {
|
|
123
|
-
particle.velocity.y = particle.velocity.x *
|
|
131
|
+
particle.velocity.y = particle.velocity.x * half - particle.velocity.y;
|
|
124
132
|
}
|
|
125
133
|
} else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
126
134
|
particle.misplaced = false;
|
|
127
135
|
} else if (particle.misplaced) {
|
|
128
136
|
const pos = particle.position,
|
|
129
137
|
vel = particle.velocity;
|
|
130
|
-
if (hDistance && (pos.x < initialPosition.x && vel.x <
|
|
138
|
+
if (hDistance && (pos.x < initialPosition.x && vel.x < minVelocity || pos.x > initialPosition.x && vel.x > minVelocity)) {
|
|
131
139
|
vel.x *= -(0,engine_root_window_.getRandom)();
|
|
132
140
|
}
|
|
133
|
-
if (vDistance && (pos.y < initialPosition.y && vel.y <
|
|
141
|
+
if (vDistance && (pos.y < initialPosition.y && vel.y < minVelocity || pos.y > initialPosition.y && vel.y > minVelocity)) {
|
|
134
142
|
vel.y *= -(0,engine_root_window_.getRandom)();
|
|
135
143
|
}
|
|
136
144
|
}
|
|
@@ -138,24 +146,24 @@ function applyDistance(particle) {
|
|
|
138
146
|
function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
139
147
|
applyPath(particle, delta);
|
|
140
148
|
const gravityOptions = particle.gravity,
|
|
141
|
-
gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -
|
|
149
|
+
gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -identity : identity;
|
|
142
150
|
if (moveDrift && moveSpeed) {
|
|
143
|
-
particle.velocity.x += moveDrift * delta.factor / (
|
|
151
|
+
particle.velocity.x += moveDrift * delta.factor / (moveSpeedFactor * moveSpeed);
|
|
144
152
|
}
|
|
145
153
|
if (gravityOptions?.enable && moveSpeed) {
|
|
146
|
-
particle.velocity.y += gravityFactor * (gravityOptions.acceleration * delta.factor) / (
|
|
154
|
+
particle.velocity.y += gravityFactor * (gravityOptions.acceleration * delta.factor) / (moveSpeedFactor * moveSpeed);
|
|
147
155
|
}
|
|
148
156
|
const decay = particle.moveDecay;
|
|
149
157
|
particle.velocity.multTo(decay);
|
|
150
158
|
const velocity = particle.velocity.mult(moveSpeed);
|
|
151
|
-
if (gravityOptions?.enable && maxSpeed >
|
|
159
|
+
if (gravityOptions?.enable && maxSpeed > minVelocity && (!gravityOptions.inverse && velocity.y >= minVelocity && velocity.y >= maxSpeed || gravityOptions.inverse && velocity.y <= minVelocity && velocity.y <= -maxSpeed)) {
|
|
152
160
|
velocity.y = gravityFactor * maxSpeed;
|
|
153
161
|
if (moveSpeed) {
|
|
154
162
|
particle.velocity.y = velocity.y / moveSpeed;
|
|
155
163
|
}
|
|
156
164
|
}
|
|
157
165
|
const zIndexOptions = particle.options.zIndex,
|
|
158
|
-
zVelocityFactor = (
|
|
166
|
+
zVelocityFactor = (identity - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
159
167
|
velocity.multTo(zVelocityFactor);
|
|
160
168
|
const {
|
|
161
169
|
position
|
|
@@ -179,15 +187,15 @@ function spin(particle, moveSpeed) {
|
|
|
179
187
|
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
180
188
|
particle.spin.radius += particle.spin.acceleration;
|
|
181
189
|
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height),
|
|
182
|
-
halfMaxSize = maxCanvasSize *
|
|
190
|
+
halfMaxSize = maxCanvasSize * half;
|
|
183
191
|
if (particle.spin.radius > halfMaxSize) {
|
|
184
192
|
particle.spin.radius = halfMaxSize;
|
|
185
|
-
particle.spin.acceleration *= -
|
|
186
|
-
} else if (particle.spin.radius <
|
|
187
|
-
particle.spin.radius =
|
|
188
|
-
particle.spin.acceleration *= -
|
|
193
|
+
particle.spin.acceleration *= -identity;
|
|
194
|
+
} else if (particle.spin.radius < minSpinRadius) {
|
|
195
|
+
particle.spin.radius = minSpinRadius;
|
|
196
|
+
particle.spin.acceleration *= -identity;
|
|
189
197
|
}
|
|
190
|
-
particle.spin.angle += moveSpeed *
|
|
198
|
+
particle.spin.angle += moveSpeed * spinFactor * (identity - particle.spin.radius / maxCanvasSize);
|
|
191
199
|
}
|
|
192
200
|
function applyPath(particle, delta) {
|
|
193
201
|
const particlesOptions = particle.options,
|
|
@@ -205,18 +213,20 @@ function applyPath(particle, delta) {
|
|
|
205
213
|
particle.velocity.addTo(path);
|
|
206
214
|
}
|
|
207
215
|
if (pathOptions.clamp) {
|
|
208
|
-
particle.velocity.x = (0,engine_root_window_.clamp)(particle.velocity.x, -
|
|
209
|
-
particle.velocity.y = (0,engine_root_window_.clamp)(particle.velocity.y, -
|
|
216
|
+
particle.velocity.x = (0,engine_root_window_.clamp)(particle.velocity.x, -identity, identity);
|
|
217
|
+
particle.velocity.y = (0,engine_root_window_.clamp)(particle.velocity.y, -identity, identity);
|
|
210
218
|
}
|
|
211
219
|
particle.lastPathTime -= particle.pathDelay;
|
|
212
220
|
}
|
|
213
221
|
function getProximitySpeedFactor(particle) {
|
|
214
|
-
return particle.slow.inRange ? particle.slow.factor :
|
|
222
|
+
return particle.slow.inRange ? particle.slow.factor : identity;
|
|
215
223
|
}
|
|
216
224
|
;// CONCATENATED MODULE: ./dist/browser/BaseMover.js
|
|
217
225
|
|
|
218
226
|
|
|
219
|
-
const diffFactor = 2
|
|
227
|
+
const diffFactor = 2,
|
|
228
|
+
defaultSizeFactor = 1,
|
|
229
|
+
defaultDeltaFactor = 1;
|
|
220
230
|
class BaseMover {
|
|
221
231
|
constructor() {
|
|
222
232
|
this._initSpin = particle => {
|
|
@@ -230,17 +240,19 @@ class BaseMover {
|
|
|
230
240
|
x: 50,
|
|
231
241
|
y: 50
|
|
232
242
|
},
|
|
243
|
+
spinFactor = 0.01,
|
|
233
244
|
spinCenter = {
|
|
234
|
-
x: spinPos.x *
|
|
235
|
-
y: spinPos.y *
|
|
245
|
+
x: spinPos.x * spinFactor * container.canvas.size.width,
|
|
246
|
+
y: spinPos.y * spinFactor * container.canvas.size.height
|
|
236
247
|
},
|
|
237
248
|
pos = particle.getPosition(),
|
|
238
249
|
distance = (0,engine_root_window_.getDistance)(pos, spinCenter),
|
|
239
250
|
spinAcceleration = (0,engine_root_window_.getRangeValue)(spinOptions.acceleration);
|
|
240
251
|
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
252
|
+
const minVelocity = 0;
|
|
241
253
|
particle.spin = {
|
|
242
254
|
center: spinCenter,
|
|
243
|
-
direction: particle.velocity.x >=
|
|
255
|
+
direction: particle.velocity.x >= minVelocity ? "clockwise" : "counter-clockwise",
|
|
244
256
|
angle: particle.velocity.angle,
|
|
245
257
|
radius: distance,
|
|
246
258
|
acceleration: particle.retina.spinAcceleration
|
|
@@ -267,13 +279,16 @@ class BaseMover {
|
|
|
267
279
|
return;
|
|
268
280
|
}
|
|
269
281
|
const container = particle.container,
|
|
270
|
-
pxRatio = container.retina.pixelRatio
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
282
|
+
pxRatio = container.retina.pixelRatio;
|
|
283
|
+
particle.retina.moveSpeed ??= (0,engine_root_window_.getRangeValue)(moveOptions.speed) * pxRatio;
|
|
284
|
+
particle.retina.moveDrift ??= (0,engine_root_window_.getRangeValue)(particle.options.move.drift) * pxRatio;
|
|
285
|
+
const slowFactor = getProximitySpeedFactor(particle),
|
|
286
|
+
baseSpeed = particle.retina.moveSpeed * container.retina.reduceFactor,
|
|
287
|
+
moveDrift = particle.retina.moveDrift,
|
|
274
288
|
maxSize = (0,engine_root_window_.getRangeMax)(particleOptions.size.value) * pxRatio,
|
|
275
|
-
sizeFactor = moveOptions.size ? particle.getRadius() / maxSize :
|
|
276
|
-
|
|
289
|
+
sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : defaultSizeFactor,
|
|
290
|
+
deltaFactor = delta.factor || defaultDeltaFactor,
|
|
291
|
+
moveSpeed = baseSpeed * sizeFactor * slowFactor * deltaFactor / diffFactor,
|
|
277
292
|
maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
|
|
278
293
|
if (moveOptions.spin.enable) {
|
|
279
294
|
spin(particle, moveSpeed);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see tsparticles.move.base.min.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function n(e){var o=i[e];if(void 0!==o)return o.exports;var a=i[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{loadBaseMover:()=>
|
|
2
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function n(e){var o=i[e];if(void 0!==o)return o.exports;var a=i[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{loadBaseMover:()=>s});var e=n(533);const t=1;function i(i,n,o,a,s,r){!function(i,n){const o=i.options,a=o.move.path;if(!a.enable)return;if(i.lastPathTime<=i.pathDelay)return void(i.lastPathTime+=n.value);const s=i.pathGenerator?.generate(i,n);s&&i.velocity.addTo(s);a.clamp&&(i.velocity.x=(0,e.clamp)(i.velocity.x,-t,t),i.velocity.y=(0,e.clamp)(i.velocity.y,-t,t));i.lastPathTime-=i.pathDelay}(i,r);const c=i.gravity,l=c?.enable&&c.inverse?-t:t;s&&o&&(i.velocity.x+=s*r.factor/(60*o)),c?.enable&&o&&(i.velocity.y+=l*(c.acceleration*r.factor)/(60*o));const p=i.moveDecay;i.velocity.multTo(p);const y=i.velocity.mult(o);c?.enable&&a>0&&(!c.inverse&&y.y>=0&&y.y>=a||c.inverse&&y.y<=0&&y.y<=-a)&&(y.y=l*a,o&&(i.velocity.y=y.y/o));const v=i.options.zIndex,d=(t-i.zIndexFactor)**v.velocityRate;y.multTo(d);const{position:u}=i;u.addTo(y),n.vibrate&&(u.x+=Math.sin(u.x*Math.cos(u.y)),u.y+=Math.cos(u.y*Math.sin(u.x)))}class a{constructor(){this._initSpin=t=>{const i=t.container,n=t.options.move.spin;if(!n.enable)return;const o=n.position??{x:50,y:50},a={x:.01*o.x*i.canvas.size.width,y:.01*o.y*i.canvas.size.height},s=t.getPosition(),r=(0,e.getDistance)(s,a),c=(0,e.getRangeValue)(n.acceleration);t.retina.spinAcceleration=c*i.retina.pixelRatio;t.spin={center:a,direction:t.velocity.x>=0?"clockwise":"counter-clockwise",angle:t.velocity.angle,radius:r,acceleration:t.retina.spinAcceleration}}}init(t){const i=t.options.move.gravity;t.gravity={enable:i.enable,acceleration:(0,e.getRangeValue)(i.acceleration),inverse:i.inverse},this._initSpin(t)}isEnabled(e){return!e.destroyed&&e.options.move.enable}move(n,o){const a=n.options,s=a.move;if(!s.enable)return;const r=n.container,c=r.retina.pixelRatio;n.retina.moveSpeed??=(0,e.getRangeValue)(s.speed)*c,n.retina.moveDrift??=(0,e.getRangeValue)(n.options.move.drift)*c;const l=function(e){return e.slow.inRange?e.slow.factor:t}(n),p=n.retina.moveSpeed*r.retina.reduceFactor,y=n.retina.moveDrift,v=(0,e.getRangeMax)(a.size.value)*c,d=p*(s.size?n.getRadius()/v:1)*l*(o.factor||1)/2,u=n.retina.maxSpeed??r.retina.maxSpeed;s.spin.enable?function(e,i){const n=e.container;if(!e.spin)return;const o={x:"clockwise"===e.spin.direction?Math.cos:Math.sin,y:"clockwise"===e.spin.direction?Math.sin:Math.cos};e.position.x=e.spin.center.x+e.spin.radius*o.x(e.spin.angle),e.position.y=e.spin.center.y+e.spin.radius*o.y(e.spin.angle),e.spin.radius+=e.spin.acceleration;const a=Math.max(n.canvas.size.width,n.canvas.size.height),s=.5*a;e.spin.radius>s?(e.spin.radius=s,e.spin.acceleration*=-t):e.spin.radius<0&&(e.spin.radius=0,e.spin.acceleration*=-t),e.spin.angle+=.01*i*(t-e.spin.radius/a)}(n,d):i(n,s,d,u,y,o),function(t){const i=t.initialPosition,{dx:n,dy:o}=(0,e.getDistances)(i,t.position),a=Math.abs(n),s=Math.abs(o),{maxDistance:r}=t.retina,c=r.horizontal,l=r.vertical;if(!c&&!l)return;if((c&&a>=c||l&&s>=l)&&!t.misplaced)t.misplaced=!!c&&a>c||!!l&&s>l,c&&(t.velocity.x=.5*t.velocity.y-t.velocity.x),l&&(t.velocity.y=.5*t.velocity.x-t.velocity.y);else if((!c||a<c)&&(!l||s<l)&&t.misplaced)t.misplaced=!1;else if(t.misplaced){const n=t.position,o=t.velocity;c&&(n.x<i.x&&o.x<0||n.x>i.x&&o.x>0)&&(o.x*=-(0,e.getRandom)()),l&&(n.y<i.y&&o.y<0||n.y>i.y&&o.y>0)&&(o.y*=-(0,e.getRandom)())}}(n)}}async function s(e,t=!0){await e.addMover("base",(()=>new a),t)}})(),o})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! tsParticles Base Move v3.0
|
|
1
|
+
/*! tsParticles Base Move v3.1.0 by Matteo Bruni */
|
package/umd/BaseMover.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
exports.BaseMover = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const Utils_js_1 = require("./Utils.js");
|
|
15
|
-
const diffFactor = 2;
|
|
15
|
+
const diffFactor = 2, defaultSizeFactor = 1, defaultDeltaFactor = 1;
|
|
16
16
|
class BaseMover {
|
|
17
17
|
constructor() {
|
|
18
18
|
this._initSpin = (particle) => {
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
if (!spinOptions.enable) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
|
|
24
|
-
x: spinPos.x *
|
|
25
|
-
y: spinPos.y *
|
|
23
|
+
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinFactor = 0.01, spinCenter = {
|
|
24
|
+
x: spinPos.x * spinFactor * container.canvas.size.width,
|
|
25
|
+
y: spinPos.y * spinFactor * container.canvas.size.height,
|
|
26
26
|
}, pos = particle.getPosition(), distance = (0, engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, engine_1.getRangeValue)(spinOptions.acceleration);
|
|
27
27
|
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
28
|
+
const minVelocity = 0;
|
|
28
29
|
particle.spin = {
|
|
29
30
|
center: spinCenter,
|
|
30
|
-
direction: particle.velocity.x >=
|
|
31
|
+
direction: particle.velocity.x >= minVelocity ? "clockwise" : "counter-clockwise",
|
|
31
32
|
angle: particle.velocity.angle,
|
|
32
33
|
radius: distance,
|
|
33
34
|
acceleration: particle.retina.spinAcceleration,
|
|
@@ -51,8 +52,10 @@
|
|
|
51
52
|
if (!moveOptions.enable) {
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
|
-
const container = particle.container, pxRatio = container.retina.pixelRatio
|
|
55
|
-
|
|
55
|
+
const container = particle.container, pxRatio = container.retina.pixelRatio;
|
|
56
|
+
particle.retina.moveSpeed ??= (0, engine_1.getRangeValue)(moveOptions.speed) * pxRatio;
|
|
57
|
+
particle.retina.moveDrift ??= (0, engine_1.getRangeValue)(particle.options.move.drift) * pxRatio;
|
|
58
|
+
const slowFactor = (0, Utils_js_1.getProximitySpeedFactor)(particle), baseSpeed = particle.retina.moveSpeed * container.retina.reduceFactor, moveDrift = particle.retina.moveDrift, maxSize = (0, engine_1.getRangeMax)(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : defaultSizeFactor, deltaFactor = delta.factor || defaultDeltaFactor, moveSpeed = (baseSpeed * sizeFactor * slowFactor * deltaFactor) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
|
|
56
59
|
if (moveOptions.spin.enable) {
|
|
57
60
|
(0, Utils_js_1.spin)(particle, moveSpeed);
|
|
58
61
|
}
|
package/umd/Utils.js
CHANGED
|
@@ -11,18 +11,20 @@
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.move = exports.applyDistance = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const half = 0.5, minVelocity = 0, identity = 1, moveSpeedFactor = 60, minSpinRadius = 0, spinFactor = 0.01;
|
|
14
15
|
function applyDistance(particle) {
|
|
15
16
|
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;
|
|
16
17
|
if (!hDistance && !vDistance) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
const hasHDistance = (hDistance && dxFixed >= hDistance) ?? false, hasVDistance = (vDistance && dyFixed >= vDistance) ?? false;
|
|
21
|
+
if ((hasHDistance || hasVDistance) && !particle.misplaced) {
|
|
20
22
|
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
21
23
|
if (hDistance) {
|
|
22
|
-
particle.velocity.x = particle.velocity.y *
|
|
24
|
+
particle.velocity.x = particle.velocity.y * half - particle.velocity.x;
|
|
23
25
|
}
|
|
24
26
|
if (vDistance) {
|
|
25
|
-
particle.velocity.y = particle.velocity.x *
|
|
27
|
+
particle.velocity.y = particle.velocity.x * half - particle.velocity.y;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
@@ -30,10 +32,12 @@
|
|
|
30
32
|
}
|
|
31
33
|
else if (particle.misplaced) {
|
|
32
34
|
const pos = particle.position, vel = particle.velocity;
|
|
33
|
-
if (hDistance &&
|
|
35
|
+
if (hDistance &&
|
|
36
|
+
((pos.x < initialPosition.x && vel.x < minVelocity) || (pos.x > initialPosition.x && vel.x > minVelocity))) {
|
|
34
37
|
vel.x *= -(0, engine_1.getRandom)();
|
|
35
38
|
}
|
|
36
|
-
if (vDistance &&
|
|
39
|
+
if (vDistance &&
|
|
40
|
+
((pos.y < initialPosition.y && vel.y < minVelocity) || (pos.y > initialPosition.y && vel.y > minVelocity))) {
|
|
37
41
|
vel.y *= -(0, engine_1.getRandom)();
|
|
38
42
|
}
|
|
39
43
|
}
|
|
@@ -41,26 +45,27 @@
|
|
|
41
45
|
exports.applyDistance = applyDistance;
|
|
42
46
|
function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
43
47
|
applyPath(particle, delta);
|
|
44
|
-
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -
|
|
48
|
+
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -identity : identity;
|
|
45
49
|
if (moveDrift && moveSpeed) {
|
|
46
|
-
particle.velocity.x += (moveDrift * delta.factor) / (
|
|
50
|
+
particle.velocity.x += (moveDrift * delta.factor) / (moveSpeedFactor * moveSpeed);
|
|
47
51
|
}
|
|
48
52
|
if (gravityOptions?.enable && moveSpeed) {
|
|
49
|
-
particle.velocity.y +=
|
|
53
|
+
particle.velocity.y +=
|
|
54
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (moveSpeedFactor * moveSpeed);
|
|
50
55
|
}
|
|
51
56
|
const decay = particle.moveDecay;
|
|
52
57
|
particle.velocity.multTo(decay);
|
|
53
58
|
const velocity = particle.velocity.mult(moveSpeed);
|
|
54
59
|
if (gravityOptions?.enable &&
|
|
55
|
-
maxSpeed >
|
|
56
|
-
((!gravityOptions.inverse && velocity.y >=
|
|
57
|
-
(gravityOptions.inverse && velocity.y <=
|
|
60
|
+
maxSpeed > minVelocity &&
|
|
61
|
+
((!gravityOptions.inverse && velocity.y >= minVelocity && velocity.y >= maxSpeed) ||
|
|
62
|
+
(gravityOptions.inverse && velocity.y <= minVelocity && velocity.y <= -maxSpeed))) {
|
|
58
63
|
velocity.y = gravityFactor * maxSpeed;
|
|
59
64
|
if (moveSpeed) {
|
|
60
65
|
particle.velocity.y = velocity.y / moveSpeed;
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
|
-
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (
|
|
68
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (identity - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
64
69
|
velocity.multTo(zVelocityFactor);
|
|
65
70
|
const { position } = particle;
|
|
66
71
|
position.addTo(velocity);
|
|
@@ -82,16 +87,16 @@
|
|
|
82
87
|
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
83
88
|
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
84
89
|
particle.spin.radius += particle.spin.acceleration;
|
|
85
|
-
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize *
|
|
90
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize * half;
|
|
86
91
|
if (particle.spin.radius > halfMaxSize) {
|
|
87
92
|
particle.spin.radius = halfMaxSize;
|
|
88
|
-
particle.spin.acceleration *= -
|
|
93
|
+
particle.spin.acceleration *= -identity;
|
|
89
94
|
}
|
|
90
|
-
else if (particle.spin.radius <
|
|
91
|
-
particle.spin.radius =
|
|
92
|
-
particle.spin.acceleration *= -
|
|
95
|
+
else if (particle.spin.radius < minSpinRadius) {
|
|
96
|
+
particle.spin.radius = minSpinRadius;
|
|
97
|
+
particle.spin.acceleration *= -identity;
|
|
93
98
|
}
|
|
94
|
-
particle.spin.angle += moveSpeed *
|
|
99
|
+
particle.spin.angle += moveSpeed * spinFactor * (identity - particle.spin.radius / maxCanvasSize);
|
|
95
100
|
}
|
|
96
101
|
exports.spin = spin;
|
|
97
102
|
function applyPath(particle, delta) {
|
|
@@ -108,14 +113,14 @@
|
|
|
108
113
|
particle.velocity.addTo(path);
|
|
109
114
|
}
|
|
110
115
|
if (pathOptions.clamp) {
|
|
111
|
-
particle.velocity.x = (0, engine_1.clamp)(particle.velocity.x, -
|
|
112
|
-
particle.velocity.y = (0, engine_1.clamp)(particle.velocity.y, -
|
|
116
|
+
particle.velocity.x = (0, engine_1.clamp)(particle.velocity.x, -identity, identity);
|
|
117
|
+
particle.velocity.y = (0, engine_1.clamp)(particle.velocity.y, -identity, identity);
|
|
113
118
|
}
|
|
114
119
|
particle.lastPathTime -= particle.pathDelay;
|
|
115
120
|
}
|
|
116
121
|
exports.applyPath = applyPath;
|
|
117
122
|
function getProximitySpeedFactor(particle) {
|
|
118
|
-
return particle.slow.inRange ? particle.slow.factor :
|
|
123
|
+
return particle.slow.inRange ? particle.slow.factor : identity;
|
|
119
124
|
}
|
|
120
125
|
exports.getProximitySpeedFactor = getProximitySpeedFactor;
|
|
121
126
|
});
|