@tsparticles/updater-gradient 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/GradientUpdater.js +16 -13
- package/browser/Utils.js +4 -97
- package/cjs/GradientUpdater.js +15 -12
- package/cjs/Utils.js +4 -97
- package/esm/GradientUpdater.js +16 -13
- package/esm/Utils.js +4 -97
- package/package.json +2 -2
- package/report.html +2 -2
- package/tsparticles.updater.gradient.js +28 -110
- package/tsparticles.updater.gradient.min.js +1 -1
- package/tsparticles.updater.gradient.min.js.LICENSE.txt +1 -1
- package/types/Types.d.ts +2 -2
- package/umd/GradientUpdater.js +15 -12
- package/umd/Utils.js +5 -98
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
1
|
+
import { executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, halfRandom, itemFromSingleOrMultiple, millisecondsToSeconds, percentDenominator, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
2
|
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
|
|
3
3
|
import { updateGradient } from "./Utils.js";
|
|
4
|
+
const double = 2, doublePI = Math.PI * double;
|
|
4
5
|
export class GradientUpdater {
|
|
5
6
|
getColorStyles(particle, context, radius, opacity) {
|
|
6
7
|
const gradient = particle.gradient;
|
|
7
8
|
if (!gradient) {
|
|
8
9
|
return {};
|
|
9
10
|
}
|
|
10
|
-
const gradientAngle = gradient.angle.value, fillGradient = gradient.type === "radial"
|
|
11
|
-
? context.createRadialGradient(
|
|
11
|
+
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === "radial"
|
|
12
|
+
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
12
13
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
13
14
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
14
15
|
fillGradient.addColorStop(stop, getStyleFromHsl({
|
|
@@ -24,14 +25,16 @@ export class GradientUpdater {
|
|
|
24
25
|
if (!gradient) {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
|
-
const { angle } = gradient;
|
|
28
|
+
const { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
28
29
|
particle.gradient = {
|
|
29
30
|
angle: {
|
|
30
31
|
value: getRangeValue(angle.value),
|
|
31
32
|
enable: angle.animation.enable,
|
|
32
|
-
velocity: (getRangeValue(angle.animation.speed) /
|
|
33
|
-
decay:
|
|
34
|
-
delayTime: getRangeValue(angle.animation.delay) *
|
|
33
|
+
velocity: (getRangeValue(angle.animation.speed) / speedFactor) * particle.container.retina.reduceFactor,
|
|
34
|
+
decay: delayOffset - getRangeValue(angle.animation.decay),
|
|
35
|
+
delayTime: getRangeValue(angle.animation.delay) * millisecondsToSeconds,
|
|
36
|
+
max: doublePI,
|
|
37
|
+
min: 0,
|
|
35
38
|
time: 0,
|
|
36
39
|
},
|
|
37
40
|
type: gradient.type,
|
|
@@ -39,7 +42,7 @@ export class GradientUpdater {
|
|
|
39
42
|
};
|
|
40
43
|
let rotateDirection = gradient.angle.direction;
|
|
41
44
|
if (rotateDirection === "random") {
|
|
42
|
-
rotateDirection = getRandom() >
|
|
45
|
+
rotateDirection = getRandom() > halfRandom ? "counter-clockwise" : "clockwise";
|
|
43
46
|
}
|
|
44
47
|
switch (rotateDirection) {
|
|
45
48
|
case "counter-clockwise":
|
|
@@ -66,10 +69,10 @@ export class GradientUpdater {
|
|
|
66
69
|
min: getRangeMin(grColor.opacity.value),
|
|
67
70
|
status: "increasing",
|
|
68
71
|
value: getRangeValue(grColor.opacity.value),
|
|
69
|
-
velocity: (getRangeValue(grColor.opacity.animation.speed) /
|
|
72
|
+
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) *
|
|
70
73
|
particle.container.retina.reduceFactor,
|
|
71
|
-
decay:
|
|
72
|
-
delayTime: getRangeValue(grColor.opacity.animation.delay) *
|
|
74
|
+
decay: delayOffset - getRangeValue(grColor.opacity.animation.decay),
|
|
75
|
+
delayTime: getRangeValue(grColor.opacity.animation.delay) * millisecondsToSeconds,
|
|
73
76
|
time: 0,
|
|
74
77
|
}
|
|
75
78
|
: undefined,
|
|
@@ -93,7 +96,7 @@ export class GradientUpdater {
|
|
|
93
96
|
default:
|
|
94
97
|
addOpacity.value = randomInRange(addOpacity);
|
|
95
98
|
addOpacity.status =
|
|
96
|
-
getRandom() >=
|
|
99
|
+
getRandom() >= halfRandom ? "increasing" : "decreasing";
|
|
97
100
|
break;
|
|
98
101
|
}
|
|
99
102
|
}
|
|
@@ -103,7 +106,7 @@ export class GradientUpdater {
|
|
|
103
106
|
isEnabled(particle) {
|
|
104
107
|
return (!particle.destroyed &&
|
|
105
108
|
!particle.spawning &&
|
|
106
|
-
(particle.gradient?.angle.enable ||
|
|
109
|
+
(!!particle.gradient?.angle.enable ||
|
|
107
110
|
(particle.gradient?.colors.some((c) => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
108
111
|
false)));
|
|
109
112
|
}
|
package/browser/Utils.js
CHANGED
|
@@ -1,107 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
if (!value.enable) {
|
|
3
|
-
return;
|
|
4
|
-
}
|
|
5
|
-
const decay = value.decay ?? 1;
|
|
6
|
-
switch (value.status) {
|
|
7
|
-
case "increasing":
|
|
8
|
-
if (value.value >= value.max) {
|
|
9
|
-
value.status = "decreasing";
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
value.value += (value.velocity ?? 0) * delta.factor;
|
|
13
|
-
}
|
|
14
|
-
break;
|
|
15
|
-
case "decreasing":
|
|
16
|
-
if (value.value <= value.min) {
|
|
17
|
-
value.status = "increasing";
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
value.value -= (value.velocity ?? 0) * delta.factor;
|
|
21
|
-
}
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
if (value.velocity && decay !== 1) {
|
|
25
|
-
value.velocity *= decay;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function updateColorValue(delta, colorValue, max, decrease) {
|
|
29
|
-
if (!colorValue || !colorValue.enable) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (!colorValue.time) {
|
|
33
|
-
colorValue.time = 0;
|
|
34
|
-
}
|
|
35
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
36
|
-
colorValue.time += delta.value;
|
|
37
|
-
}
|
|
38
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const velocity = (colorValue.velocity ?? 0) * delta.factor, decay = colorValue.decay ?? 1;
|
|
42
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
43
|
-
colorValue.value += velocity;
|
|
44
|
-
if (decrease && colorValue.value > max) {
|
|
45
|
-
colorValue.status = "decreasing";
|
|
46
|
-
colorValue.value -= colorValue.value % max;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
colorValue.value -= velocity;
|
|
51
|
-
if (colorValue.value < 0) {
|
|
52
|
-
colorValue.status = "increasing";
|
|
53
|
-
colorValue.value += colorValue.value;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (colorValue.value > max) {
|
|
57
|
-
colorValue.value %= max;
|
|
58
|
-
}
|
|
59
|
-
if (colorValue.velocity && decay !== 1) {
|
|
60
|
-
colorValue.velocity *= decay;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function updateAngle(delta, angle) {
|
|
64
|
-
const speed = (angle.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = angle.decay ?? 1;
|
|
65
|
-
if (!angle.enable) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
switch (angle.status) {
|
|
69
|
-
case "increasing":
|
|
70
|
-
angle.value += speed;
|
|
71
|
-
if (angle.value > max) {
|
|
72
|
-
angle.value -= max;
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
case "decreasing":
|
|
76
|
-
default:
|
|
77
|
-
angle.value -= speed;
|
|
78
|
-
if (angle.value < 0) {
|
|
79
|
-
angle.value += max;
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
if (angle.velocity && decay !== 1) {
|
|
84
|
-
angle.velocity *= decay;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
import { updateAnimation, updateColor } from "@tsparticles/engine";
|
|
87
2
|
export function updateGradient(particle, delta) {
|
|
88
3
|
const { gradient } = particle;
|
|
89
4
|
if (!gradient) {
|
|
90
5
|
return;
|
|
91
6
|
}
|
|
92
|
-
|
|
7
|
+
updateAnimation(particle, gradient.angle, false, "none", delta);
|
|
93
8
|
for (const color of gradient.colors) {
|
|
94
|
-
|
|
95
|
-
updateColorValue(delta, color.value.h, 360, false);
|
|
96
|
-
}
|
|
97
|
-
if (particle.color?.s !== undefined) {
|
|
98
|
-
updateColorValue(delta, color.value.s, 100, true);
|
|
99
|
-
}
|
|
100
|
-
if (particle.color?.l !== undefined) {
|
|
101
|
-
updateColorValue(delta, color.value.l, 100, true);
|
|
102
|
-
}
|
|
9
|
+
updateColor(color.value, delta);
|
|
103
10
|
if (color.opacity) {
|
|
104
|
-
|
|
11
|
+
updateAnimation(particle, color.opacity, true, "none", delta);
|
|
105
12
|
}
|
|
106
13
|
}
|
|
107
14
|
}
|
package/cjs/GradientUpdater.js
CHANGED
|
@@ -4,14 +4,15 @@ exports.GradientUpdater = void 0;
|
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
5
|
const AnimatableGradient_js_1 = require("./Options/Classes/AnimatableGradient.js");
|
|
6
6
|
const Utils_js_1 = require("./Utils.js");
|
|
7
|
+
const double = 2, doublePI = Math.PI * double;
|
|
7
8
|
class GradientUpdater {
|
|
8
9
|
getColorStyles(particle, context, radius, opacity) {
|
|
9
10
|
const gradient = particle.gradient;
|
|
10
11
|
if (!gradient) {
|
|
11
12
|
return {};
|
|
12
13
|
}
|
|
13
|
-
const gradientAngle = gradient.angle.value, fillGradient = gradient.type === "radial"
|
|
14
|
-
? context.createRadialGradient(
|
|
14
|
+
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === "radial"
|
|
15
|
+
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
15
16
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
16
17
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
17
18
|
fillGradient.addColorStop(stop, (0, engine_1.getStyleFromHsl)({
|
|
@@ -27,14 +28,16 @@ class GradientUpdater {
|
|
|
27
28
|
if (!gradient) {
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
30
|
-
const { angle } = gradient;
|
|
31
|
+
const { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
31
32
|
particle.gradient = {
|
|
32
33
|
angle: {
|
|
33
34
|
value: (0, engine_1.getRangeValue)(angle.value),
|
|
34
35
|
enable: angle.animation.enable,
|
|
35
|
-
velocity: ((0, engine_1.getRangeValue)(angle.animation.speed) /
|
|
36
|
-
decay:
|
|
37
|
-
delayTime: (0, engine_1.getRangeValue)(angle.animation.delay) *
|
|
36
|
+
velocity: ((0, engine_1.getRangeValue)(angle.animation.speed) / speedFactor) * particle.container.retina.reduceFactor,
|
|
37
|
+
decay: delayOffset - (0, engine_1.getRangeValue)(angle.animation.decay),
|
|
38
|
+
delayTime: (0, engine_1.getRangeValue)(angle.animation.delay) * engine_1.millisecondsToSeconds,
|
|
39
|
+
max: doublePI,
|
|
40
|
+
min: 0,
|
|
38
41
|
time: 0,
|
|
39
42
|
},
|
|
40
43
|
type: gradient.type,
|
|
@@ -42,7 +45,7 @@ class GradientUpdater {
|
|
|
42
45
|
};
|
|
43
46
|
let rotateDirection = gradient.angle.direction;
|
|
44
47
|
if (rotateDirection === "random") {
|
|
45
|
-
rotateDirection = (0, engine_1.getRandom)() >
|
|
48
|
+
rotateDirection = (0, engine_1.getRandom)() > engine_1.halfRandom ? "counter-clockwise" : "clockwise";
|
|
46
49
|
}
|
|
47
50
|
switch (rotateDirection) {
|
|
48
51
|
case "counter-clockwise":
|
|
@@ -69,10 +72,10 @@ class GradientUpdater {
|
|
|
69
72
|
min: (0, engine_1.getRangeMin)(grColor.opacity.value),
|
|
70
73
|
status: "increasing",
|
|
71
74
|
value: (0, engine_1.getRangeValue)(grColor.opacity.value),
|
|
72
|
-
velocity: ((0, engine_1.getRangeValue)(grColor.opacity.animation.speed) /
|
|
75
|
+
velocity: ((0, engine_1.getRangeValue)(grColor.opacity.animation.speed) / engine_1.percentDenominator) *
|
|
73
76
|
particle.container.retina.reduceFactor,
|
|
74
|
-
decay:
|
|
75
|
-
delayTime: (0, engine_1.getRangeValue)(grColor.opacity.animation.delay) *
|
|
77
|
+
decay: delayOffset - (0, engine_1.getRangeValue)(grColor.opacity.animation.decay),
|
|
78
|
+
delayTime: (0, engine_1.getRangeValue)(grColor.opacity.animation.delay) * engine_1.millisecondsToSeconds,
|
|
76
79
|
time: 0,
|
|
77
80
|
}
|
|
78
81
|
: undefined,
|
|
@@ -96,7 +99,7 @@ class GradientUpdater {
|
|
|
96
99
|
default:
|
|
97
100
|
addOpacity.value = (0, engine_1.randomInRange)(addOpacity);
|
|
98
101
|
addOpacity.status =
|
|
99
|
-
(0, engine_1.getRandom)() >=
|
|
102
|
+
(0, engine_1.getRandom)() >= engine_1.halfRandom ? "increasing" : "decreasing";
|
|
100
103
|
break;
|
|
101
104
|
}
|
|
102
105
|
}
|
|
@@ -106,7 +109,7 @@ class GradientUpdater {
|
|
|
106
109
|
isEnabled(particle) {
|
|
107
110
|
return (!particle.destroyed &&
|
|
108
111
|
!particle.spawning &&
|
|
109
|
-
(particle.gradient?.angle.enable ||
|
|
112
|
+
(!!particle.gradient?.angle.enable ||
|
|
110
113
|
(particle.gradient?.colors.some((c) => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
111
114
|
false)));
|
|
112
115
|
}
|
package/cjs/Utils.js
CHANGED
|
@@ -1,110 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateGradient = void 0;
|
|
4
|
-
|
|
5
|
-
if (!value.enable) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const decay = value.decay ?? 1;
|
|
9
|
-
switch (value.status) {
|
|
10
|
-
case "increasing":
|
|
11
|
-
if (value.value >= value.max) {
|
|
12
|
-
value.status = "decreasing";
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
value.value += (value.velocity ?? 0) * delta.factor;
|
|
16
|
-
}
|
|
17
|
-
break;
|
|
18
|
-
case "decreasing":
|
|
19
|
-
if (value.value <= value.min) {
|
|
20
|
-
value.status = "increasing";
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
value.value -= (value.velocity ?? 0) * delta.factor;
|
|
24
|
-
}
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
if (value.velocity && decay !== 1) {
|
|
28
|
-
value.velocity *= decay;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function updateColorValue(delta, colorValue, max, decrease) {
|
|
32
|
-
if (!colorValue || !colorValue.enable) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (!colorValue.time) {
|
|
36
|
-
colorValue.time = 0;
|
|
37
|
-
}
|
|
38
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
39
|
-
colorValue.time += delta.value;
|
|
40
|
-
}
|
|
41
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const velocity = (colorValue.velocity ?? 0) * delta.factor, decay = colorValue.decay ?? 1;
|
|
45
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
46
|
-
colorValue.value += velocity;
|
|
47
|
-
if (decrease && colorValue.value > max) {
|
|
48
|
-
colorValue.status = "decreasing";
|
|
49
|
-
colorValue.value -= colorValue.value % max;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
colorValue.value -= velocity;
|
|
54
|
-
if (colorValue.value < 0) {
|
|
55
|
-
colorValue.status = "increasing";
|
|
56
|
-
colorValue.value += colorValue.value;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (colorValue.value > max) {
|
|
60
|
-
colorValue.value %= max;
|
|
61
|
-
}
|
|
62
|
-
if (colorValue.velocity && decay !== 1) {
|
|
63
|
-
colorValue.velocity *= decay;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function updateAngle(delta, angle) {
|
|
67
|
-
const speed = (angle.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = angle.decay ?? 1;
|
|
68
|
-
if (!angle.enable) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
switch (angle.status) {
|
|
72
|
-
case "increasing":
|
|
73
|
-
angle.value += speed;
|
|
74
|
-
if (angle.value > max) {
|
|
75
|
-
angle.value -= max;
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
case "decreasing":
|
|
79
|
-
default:
|
|
80
|
-
angle.value -= speed;
|
|
81
|
-
if (angle.value < 0) {
|
|
82
|
-
angle.value += max;
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
if (angle.velocity && decay !== 1) {
|
|
87
|
-
angle.velocity *= decay;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
90
5
|
function updateGradient(particle, delta) {
|
|
91
6
|
const { gradient } = particle;
|
|
92
7
|
if (!gradient) {
|
|
93
8
|
return;
|
|
94
9
|
}
|
|
95
|
-
|
|
10
|
+
(0, engine_1.updateAnimation)(particle, gradient.angle, false, "none", delta);
|
|
96
11
|
for (const color of gradient.colors) {
|
|
97
|
-
|
|
98
|
-
updateColorValue(delta, color.value.h, 360, false);
|
|
99
|
-
}
|
|
100
|
-
if (particle.color?.s !== undefined) {
|
|
101
|
-
updateColorValue(delta, color.value.s, 100, true);
|
|
102
|
-
}
|
|
103
|
-
if (particle.color?.l !== undefined) {
|
|
104
|
-
updateColorValue(delta, color.value.l, 100, true);
|
|
105
|
-
}
|
|
12
|
+
(0, engine_1.updateColor)(color.value, delta);
|
|
106
13
|
if (color.opacity) {
|
|
107
|
-
|
|
14
|
+
(0, engine_1.updateAnimation)(particle, color.opacity, true, "none", delta);
|
|
108
15
|
}
|
|
109
16
|
}
|
|
110
17
|
}
|
package/esm/GradientUpdater.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
1
|
+
import { executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, halfRandom, itemFromSingleOrMultiple, millisecondsToSeconds, percentDenominator, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
2
|
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
|
|
3
3
|
import { updateGradient } from "./Utils.js";
|
|
4
|
+
const double = 2, doublePI = Math.PI * double;
|
|
4
5
|
export class GradientUpdater {
|
|
5
6
|
getColorStyles(particle, context, radius, opacity) {
|
|
6
7
|
const gradient = particle.gradient;
|
|
7
8
|
if (!gradient) {
|
|
8
9
|
return {};
|
|
9
10
|
}
|
|
10
|
-
const gradientAngle = gradient.angle.value, fillGradient = gradient.type === "radial"
|
|
11
|
-
? context.createRadialGradient(
|
|
11
|
+
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === "radial"
|
|
12
|
+
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
12
13
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
13
14
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
14
15
|
fillGradient.addColorStop(stop, getStyleFromHsl({
|
|
@@ -24,14 +25,16 @@ export class GradientUpdater {
|
|
|
24
25
|
if (!gradient) {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
|
-
const { angle } = gradient;
|
|
28
|
+
const { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
28
29
|
particle.gradient = {
|
|
29
30
|
angle: {
|
|
30
31
|
value: getRangeValue(angle.value),
|
|
31
32
|
enable: angle.animation.enable,
|
|
32
|
-
velocity: (getRangeValue(angle.animation.speed) /
|
|
33
|
-
decay:
|
|
34
|
-
delayTime: getRangeValue(angle.animation.delay) *
|
|
33
|
+
velocity: (getRangeValue(angle.animation.speed) / speedFactor) * particle.container.retina.reduceFactor,
|
|
34
|
+
decay: delayOffset - getRangeValue(angle.animation.decay),
|
|
35
|
+
delayTime: getRangeValue(angle.animation.delay) * millisecondsToSeconds,
|
|
36
|
+
max: doublePI,
|
|
37
|
+
min: 0,
|
|
35
38
|
time: 0,
|
|
36
39
|
},
|
|
37
40
|
type: gradient.type,
|
|
@@ -39,7 +42,7 @@ export class GradientUpdater {
|
|
|
39
42
|
};
|
|
40
43
|
let rotateDirection = gradient.angle.direction;
|
|
41
44
|
if (rotateDirection === "random") {
|
|
42
|
-
rotateDirection = getRandom() >
|
|
45
|
+
rotateDirection = getRandom() > halfRandom ? "counter-clockwise" : "clockwise";
|
|
43
46
|
}
|
|
44
47
|
switch (rotateDirection) {
|
|
45
48
|
case "counter-clockwise":
|
|
@@ -66,10 +69,10 @@ export class GradientUpdater {
|
|
|
66
69
|
min: getRangeMin(grColor.opacity.value),
|
|
67
70
|
status: "increasing",
|
|
68
71
|
value: getRangeValue(grColor.opacity.value),
|
|
69
|
-
velocity: (getRangeValue(grColor.opacity.animation.speed) /
|
|
72
|
+
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) *
|
|
70
73
|
particle.container.retina.reduceFactor,
|
|
71
|
-
decay:
|
|
72
|
-
delayTime: getRangeValue(grColor.opacity.animation.delay) *
|
|
74
|
+
decay: delayOffset - getRangeValue(grColor.opacity.animation.decay),
|
|
75
|
+
delayTime: getRangeValue(grColor.opacity.animation.delay) * millisecondsToSeconds,
|
|
73
76
|
time: 0,
|
|
74
77
|
}
|
|
75
78
|
: undefined,
|
|
@@ -93,7 +96,7 @@ export class GradientUpdater {
|
|
|
93
96
|
default:
|
|
94
97
|
addOpacity.value = randomInRange(addOpacity);
|
|
95
98
|
addOpacity.status =
|
|
96
|
-
getRandom() >=
|
|
99
|
+
getRandom() >= halfRandom ? "increasing" : "decreasing";
|
|
97
100
|
break;
|
|
98
101
|
}
|
|
99
102
|
}
|
|
@@ -103,7 +106,7 @@ export class GradientUpdater {
|
|
|
103
106
|
isEnabled(particle) {
|
|
104
107
|
return (!particle.destroyed &&
|
|
105
108
|
!particle.spawning &&
|
|
106
|
-
(particle.gradient?.angle.enable ||
|
|
109
|
+
(!!particle.gradient?.angle.enable ||
|
|
107
110
|
(particle.gradient?.colors.some((c) => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
108
111
|
false)));
|
|
109
112
|
}
|
package/esm/Utils.js
CHANGED
|
@@ -1,107 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
if (!value.enable) {
|
|
3
|
-
return;
|
|
4
|
-
}
|
|
5
|
-
const decay = value.decay ?? 1;
|
|
6
|
-
switch (value.status) {
|
|
7
|
-
case "increasing":
|
|
8
|
-
if (value.value >= value.max) {
|
|
9
|
-
value.status = "decreasing";
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
value.value += (value.velocity ?? 0) * delta.factor;
|
|
13
|
-
}
|
|
14
|
-
break;
|
|
15
|
-
case "decreasing":
|
|
16
|
-
if (value.value <= value.min) {
|
|
17
|
-
value.status = "increasing";
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
value.value -= (value.velocity ?? 0) * delta.factor;
|
|
21
|
-
}
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
if (value.velocity && decay !== 1) {
|
|
25
|
-
value.velocity *= decay;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function updateColorValue(delta, colorValue, max, decrease) {
|
|
29
|
-
if (!colorValue || !colorValue.enable) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (!colorValue.time) {
|
|
33
|
-
colorValue.time = 0;
|
|
34
|
-
}
|
|
35
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
36
|
-
colorValue.time += delta.value;
|
|
37
|
-
}
|
|
38
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const velocity = (colorValue.velocity ?? 0) * delta.factor, decay = colorValue.decay ?? 1;
|
|
42
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
43
|
-
colorValue.value += velocity;
|
|
44
|
-
if (decrease && colorValue.value > max) {
|
|
45
|
-
colorValue.status = "decreasing";
|
|
46
|
-
colorValue.value -= colorValue.value % max;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
colorValue.value -= velocity;
|
|
51
|
-
if (colorValue.value < 0) {
|
|
52
|
-
colorValue.status = "increasing";
|
|
53
|
-
colorValue.value += colorValue.value;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (colorValue.value > max) {
|
|
57
|
-
colorValue.value %= max;
|
|
58
|
-
}
|
|
59
|
-
if (colorValue.velocity && decay !== 1) {
|
|
60
|
-
colorValue.velocity *= decay;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function updateAngle(delta, angle) {
|
|
64
|
-
const speed = (angle.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = angle.decay ?? 1;
|
|
65
|
-
if (!angle.enable) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
switch (angle.status) {
|
|
69
|
-
case "increasing":
|
|
70
|
-
angle.value += speed;
|
|
71
|
-
if (angle.value > max) {
|
|
72
|
-
angle.value -= max;
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
case "decreasing":
|
|
76
|
-
default:
|
|
77
|
-
angle.value -= speed;
|
|
78
|
-
if (angle.value < 0) {
|
|
79
|
-
angle.value += max;
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
if (angle.velocity && decay !== 1) {
|
|
84
|
-
angle.velocity *= decay;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
import { updateAnimation, updateColor } from "@tsparticles/engine";
|
|
87
2
|
export function updateGradient(particle, delta) {
|
|
88
3
|
const { gradient } = particle;
|
|
89
4
|
if (!gradient) {
|
|
90
5
|
return;
|
|
91
6
|
}
|
|
92
|
-
|
|
7
|
+
updateAnimation(particle, gradient.angle, false, "none", delta);
|
|
93
8
|
for (const color of gradient.colors) {
|
|
94
|
-
|
|
95
|
-
updateColorValue(delta, color.value.h, 360, false);
|
|
96
|
-
}
|
|
97
|
-
if (particle.color?.s !== undefined) {
|
|
98
|
-
updateColorValue(delta, color.value.s, 100, true);
|
|
99
|
-
}
|
|
100
|
-
if (particle.color?.l !== undefined) {
|
|
101
|
-
updateColorValue(delta, color.value.l, 100, true);
|
|
102
|
-
}
|
|
9
|
+
updateColor(color.value, delta);
|
|
103
10
|
if (color.opacity) {
|
|
104
|
-
|
|
11
|
+
updateAnimation(particle, color.opacity, true, "none", delta);
|
|
105
12
|
}
|
|
106
13
|
}
|
|
107
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/updater-gradient",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "tsParticles particles gradient updater",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"./package.json": "./package.json"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@tsparticles/engine": "^3.0
|
|
104
|
+
"@tsparticles/engine": "^3.1.0"
|
|
105
105
|
},
|
|
106
106
|
"publishConfig": {
|
|
107
107
|
"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/updater-gradient [
|
|
6
|
+
<title>@tsparticles/updater-gradient [13 Jan 2024 at 23:08]</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.updater.gradient.js","isAsset":true,"statSize":
|
|
34
|
+
window.chartData = [{"label":"tsparticles.updater.gradient.js","isAsset":true,"statSize":10014,"parsedSize":14255,"gzipSize":3280,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":9972,"groups":[{"id":453,"label":"index.js + 8 modules (concatenated)","path":"./dist/browser/index.js + 8 modules (concatenated)","statSize":9972,"parsedSize":14255,"gzipSize":3280,"concatenated":true,"groups":[{"label":"dist/browser","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser","statSize":9972,"groups":[{"id":null,"label":"index.js","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/index.js","statSize":210,"parsedSize":300,"gzipSize":69,"inaccurateSizes":true},{"id":null,"label":"GradientUpdater.js","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/GradientUpdater.js","statSize":5299,"parsedSize":7574,"gzipSize":1742,"inaccurateSizes":true},{"label":"Options/Classes","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/Options/Classes","statSize":4021,"groups":[{"id":null,"label":"AnimatableGradient.js","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/Options/Classes/AnimatableGradient.js","statSize":614,"parsedSize":877,"gzipSize":201,"inaccurateSizes":true},{"id":null,"label":"GradientAngle.js","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/Options/Classes/GradientAngle.js","statSize":550,"parsedSize":786,"gzipSize":180,"inaccurateSizes":true},{"id":null,"label":"AnimatableGradientColor.js","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/Options/Classes/AnimatableGradientColor.js","statSize":679,"parsedSize":970,"gzipSize":223,"inaccurateSizes":true},{"id":null,"label":"GradientAngleAnimation.js","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/Options/Classes/GradientAngleAnimation.js","statSize":796,"parsedSize":1137,"gzipSize":261,"inaccurateSizes":true},{"id":null,"label":"GradientColorOpacity.js","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/Options/Classes/GradientColorOpacity.js","statSize":459,"parsedSize":656,"gzipSize":150,"inaccurateSizes":true},{"id":null,"label":"GradientColorOpacityAnimation.js","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/Options/Classes/GradientColorOpacityAnimation.js","statSize":923,"parsedSize":1319,"gzipSize":303,"inaccurateSizes":true}],"parsedSize":5748,"gzipSize":1322,"inaccurateSizes":true},{"id":null,"label":"Utils.js","path":"./dist/browser/index.js + 8 modules (concatenated)/dist/browser/Utils.js","statSize":442,"parsedSize":631,"gzipSize":145,"inaccurateSizes":true}],"parsedSize":14255,"gzipSize":3280,"inaccurateSizes":true}]}],"parsedSize":14255,"gzipSize":3280},{"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.updater.gradient":true}}];
|
|
35
35
|
window.entrypoints = ["tsparticles.updater.gradient","tsparticles.updater.gradient.min"];
|
|
36
36
|
window.defaultSizes = "parsed";
|
|
37
37
|
</script>
|
|
@@ -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')
|
|
@@ -263,92 +263,7 @@ class AnimatableGradient {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
;// CONCATENATED MODULE: ./dist/browser/Utils.js
|
|
266
|
-
|
|
267
|
-
if (!value.enable) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
const decay = value.decay ?? 1;
|
|
271
|
-
switch (value.status) {
|
|
272
|
-
case "increasing":
|
|
273
|
-
if (value.value >= value.max) {
|
|
274
|
-
value.status = "decreasing";
|
|
275
|
-
} else {
|
|
276
|
-
value.value += (value.velocity ?? 0) * delta.factor;
|
|
277
|
-
}
|
|
278
|
-
break;
|
|
279
|
-
case "decreasing":
|
|
280
|
-
if (value.value <= value.min) {
|
|
281
|
-
value.status = "increasing";
|
|
282
|
-
} else {
|
|
283
|
-
value.value -= (value.velocity ?? 0) * delta.factor;
|
|
284
|
-
}
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
if (value.velocity && decay !== 1) {
|
|
288
|
-
value.velocity *= decay;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
function updateColorValue(delta, colorValue, max, decrease) {
|
|
292
|
-
if (!colorValue || !colorValue.enable) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
if (!colorValue.time) {
|
|
296
|
-
colorValue.time = 0;
|
|
297
|
-
}
|
|
298
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
299
|
-
colorValue.time += delta.value;
|
|
300
|
-
}
|
|
301
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
const velocity = (colorValue.velocity ?? 0) * delta.factor,
|
|
305
|
-
decay = colorValue.decay ?? 1;
|
|
306
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
307
|
-
colorValue.value += velocity;
|
|
308
|
-
if (decrease && colorValue.value > max) {
|
|
309
|
-
colorValue.status = "decreasing";
|
|
310
|
-
colorValue.value -= colorValue.value % max;
|
|
311
|
-
}
|
|
312
|
-
} else {
|
|
313
|
-
colorValue.value -= velocity;
|
|
314
|
-
if (colorValue.value < 0) {
|
|
315
|
-
colorValue.status = "increasing";
|
|
316
|
-
colorValue.value += colorValue.value;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
if (colorValue.value > max) {
|
|
320
|
-
colorValue.value %= max;
|
|
321
|
-
}
|
|
322
|
-
if (colorValue.velocity && decay !== 1) {
|
|
323
|
-
colorValue.velocity *= decay;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
function updateAngle(delta, angle) {
|
|
327
|
-
const speed = (angle.velocity ?? 0) * delta.factor,
|
|
328
|
-
max = 2 * Math.PI,
|
|
329
|
-
decay = angle.decay ?? 1;
|
|
330
|
-
if (!angle.enable) {
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
switch (angle.status) {
|
|
334
|
-
case "increasing":
|
|
335
|
-
angle.value += speed;
|
|
336
|
-
if (angle.value > max) {
|
|
337
|
-
angle.value -= max;
|
|
338
|
-
}
|
|
339
|
-
break;
|
|
340
|
-
case "decreasing":
|
|
341
|
-
default:
|
|
342
|
-
angle.value -= speed;
|
|
343
|
-
if (angle.value < 0) {
|
|
344
|
-
angle.value += max;
|
|
345
|
-
}
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
if (angle.velocity && decay !== 1) {
|
|
349
|
-
angle.velocity *= decay;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
266
|
+
|
|
352
267
|
function updateGradient(particle, delta) {
|
|
353
268
|
const {
|
|
354
269
|
gradient
|
|
@@ -356,19 +271,11 @@ function updateGradient(particle, delta) {
|
|
|
356
271
|
if (!gradient) {
|
|
357
272
|
return;
|
|
358
273
|
}
|
|
359
|
-
|
|
274
|
+
(0,engine_root_window_.updateAnimation)(particle, gradient.angle, false, "none", delta);
|
|
360
275
|
for (const color of gradient.colors) {
|
|
361
|
-
|
|
362
|
-
updateColorValue(delta, color.value.h, 360, false);
|
|
363
|
-
}
|
|
364
|
-
if (particle.color?.s !== undefined) {
|
|
365
|
-
updateColorValue(delta, color.value.s, 100, true);
|
|
366
|
-
}
|
|
367
|
-
if (particle.color?.l !== undefined) {
|
|
368
|
-
updateColorValue(delta, color.value.l, 100, true);
|
|
369
|
-
}
|
|
276
|
+
(0,engine_root_window_.updateColor)(color.value, delta);
|
|
370
277
|
if (color.opacity) {
|
|
371
|
-
|
|
278
|
+
(0,engine_root_window_.updateAnimation)(particle, color.opacity, true, "none", delta);
|
|
372
279
|
}
|
|
373
280
|
}
|
|
374
281
|
}
|
|
@@ -376,6 +283,8 @@ function updateGradient(particle, delta) {
|
|
|
376
283
|
|
|
377
284
|
|
|
378
285
|
|
|
286
|
+
const GradientUpdater_double = 2,
|
|
287
|
+
doublePI = Math.PI * GradientUpdater_double;
|
|
379
288
|
class GradientUpdater {
|
|
380
289
|
getColorStyles(particle, context, radius, opacity) {
|
|
381
290
|
const gradient = particle.gradient;
|
|
@@ -383,7 +292,12 @@ class GradientUpdater {
|
|
|
383
292
|
return {};
|
|
384
293
|
}
|
|
385
294
|
const gradientAngle = gradient.angle.value,
|
|
386
|
-
|
|
295
|
+
origin = {
|
|
296
|
+
x: 0,
|
|
297
|
+
y: 0
|
|
298
|
+
},
|
|
299
|
+
minRadius = 0,
|
|
300
|
+
fillGradient = gradient.type === "radial" ? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius) : context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
387
301
|
for (const {
|
|
388
302
|
stop,
|
|
389
303
|
value,
|
|
@@ -405,15 +319,19 @@ class GradientUpdater {
|
|
|
405
319
|
return;
|
|
406
320
|
}
|
|
407
321
|
const {
|
|
408
|
-
|
|
409
|
-
|
|
322
|
+
angle
|
|
323
|
+
} = gradient,
|
|
324
|
+
speedFactor = 360,
|
|
325
|
+
delayOffset = 1;
|
|
410
326
|
particle.gradient = {
|
|
411
327
|
angle: {
|
|
412
328
|
value: (0,engine_root_window_.getRangeValue)(angle.value),
|
|
413
329
|
enable: angle.animation.enable,
|
|
414
|
-
velocity: (0,engine_root_window_.getRangeValue)(angle.animation.speed) /
|
|
415
|
-
decay:
|
|
416
|
-
delayTime: (0,engine_root_window_.getRangeValue)(angle.animation.delay) *
|
|
330
|
+
velocity: (0,engine_root_window_.getRangeValue)(angle.animation.speed) / speedFactor * particle.container.retina.reduceFactor,
|
|
331
|
+
decay: delayOffset - (0,engine_root_window_.getRangeValue)(angle.animation.decay),
|
|
332
|
+
delayTime: (0,engine_root_window_.getRangeValue)(angle.animation.delay) * engine_root_window_.millisecondsToSeconds,
|
|
333
|
+
max: doublePI,
|
|
334
|
+
min: 0,
|
|
417
335
|
time: 0
|
|
418
336
|
},
|
|
419
337
|
type: gradient.type,
|
|
@@ -421,7 +339,7 @@ class GradientUpdater {
|
|
|
421
339
|
};
|
|
422
340
|
let rotateDirection = gradient.angle.direction;
|
|
423
341
|
if (rotateDirection === "random") {
|
|
424
|
-
rotateDirection = (0,engine_root_window_.getRandom)() >
|
|
342
|
+
rotateDirection = (0,engine_root_window_.getRandom)() > engine_root_window_.halfRandom ? "counter-clockwise" : "clockwise";
|
|
425
343
|
}
|
|
426
344
|
switch (rotateDirection) {
|
|
427
345
|
case "counter-clockwise":
|
|
@@ -448,9 +366,9 @@ class GradientUpdater {
|
|
|
448
366
|
min: (0,engine_root_window_.getRangeMin)(grColor.opacity.value),
|
|
449
367
|
status: "increasing",
|
|
450
368
|
value: (0,engine_root_window_.getRangeValue)(grColor.opacity.value),
|
|
451
|
-
velocity: (0,engine_root_window_.getRangeValue)(grColor.opacity.animation.speed) /
|
|
452
|
-
decay:
|
|
453
|
-
delayTime: (0,engine_root_window_.getRangeValue)(grColor.opacity.animation.delay) *
|
|
369
|
+
velocity: (0,engine_root_window_.getRangeValue)(grColor.opacity.animation.speed) / engine_root_window_.percentDenominator * particle.container.retina.reduceFactor,
|
|
370
|
+
decay: delayOffset - (0,engine_root_window_.getRangeValue)(grColor.opacity.animation.decay),
|
|
371
|
+
delayTime: (0,engine_root_window_.getRangeValue)(grColor.opacity.animation.delay) * engine_root_window_.millisecondsToSeconds,
|
|
454
372
|
time: 0
|
|
455
373
|
} : undefined
|
|
456
374
|
};
|
|
@@ -474,7 +392,7 @@ class GradientUpdater {
|
|
|
474
392
|
case "random":
|
|
475
393
|
default:
|
|
476
394
|
addOpacity.value = (0,engine_root_window_.randomInRange)(addOpacity);
|
|
477
|
-
addOpacity.status = (0,engine_root_window_.getRandom)() >=
|
|
395
|
+
addOpacity.status = (0,engine_root_window_.getRandom)() >= engine_root_window_.halfRandom ? "increasing" : "decreasing";
|
|
478
396
|
break;
|
|
479
397
|
}
|
|
480
398
|
}
|
|
@@ -482,7 +400,7 @@ class GradientUpdater {
|
|
|
482
400
|
}
|
|
483
401
|
}
|
|
484
402
|
isEnabled(particle) {
|
|
485
|
-
return !particle.destroyed && !particle.spawning && (particle.gradient?.angle.enable || (particle.gradient?.colors.some(c => c.value.h.enable || c.value.s.enable || c.value.l.enable) ?? false));
|
|
403
|
+
return !particle.destroyed && !particle.spawning && (!!particle.gradient?.angle.enable || (particle.gradient?.colors.some(c => c.value.h.enable || c.value.s.enable || c.value.l.enable) ?? false));
|
|
486
404
|
}
|
|
487
405
|
loadOptions(options, ...sources) {
|
|
488
406
|
for (const source of sources) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see tsparticles.updater.gradient.min.js.LICENSE.txt */
|
|
2
|
-
!function(e,a){if("object"==typeof exports&&"object"==typeof module)module.exports=a(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],a);else{var t="object"==typeof exports?a(require("@tsparticles/engine")):a(e.window);for(var
|
|
2
|
+
!function(e,a){if("object"==typeof exports&&"object"==typeof module)module.exports=a(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],a);else{var t="object"==typeof exports?a(require("@tsparticles/engine")):a(e.window);for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(this,(e=>(()=>{"use strict";var a={533:a=>{a.exports=e}},t={};function n(e){var i=t[e];if(void 0!==i)return i.exports;var o=t[e]={exports:{}};return a[e](o,o.exports,n),o.exports}n.d=(e,a)=>{for(var t in a)n.o(a,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:a[t]})},n.o=(e,a)=>Object.prototype.hasOwnProperty.call(e,a),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{n.r(i),n.d(i,{loadGradientUpdater:()=>u});var e=n(533);class a{constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.delay=0,this.sync=!1,this.startValue="random"}load(a){a&&(void 0!==a.count&&(this.count=(0,e.setRangeValue)(a.count)),void 0!==a.enable&&(this.enable=a.enable),void 0!==a.speed&&(this.speed=(0,e.setRangeValue)(a.speed)),void 0!==a.sync&&(this.sync=a.sync),void 0!==a.startValue&&(this.startValue=a.startValue),void 0!==a.decay&&(this.decay=(0,e.setRangeValue)(a.decay)),void 0!==a.delay&&(this.delay=(0,e.setRangeValue)(a.delay)))}}class t{constructor(){this.value=0,this.animation=new a}load(a){a&&(this.animation.load(a.animation),void 0!==a.value&&(this.value=(0,e.setRangeValue)(a.value)))}}class o{constructor(){this.stop=0,this.value=new e.AnimatableColor}load(a){a&&(void 0!==a.stop&&(this.stop=a.stop),this.value=e.AnimatableColor.create(this.value,a.value),void 0!==a.opacity&&(this.opacity=new t,(0,e.isNumber)(a.opacity)?this.opacity.value=a.opacity:this.opacity.load(a.opacity)))}}class s{constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.delay=0,this.sync=!1}load(a){a&&(void 0!==a.count&&(this.count=(0,e.setRangeValue)(a.count)),void 0!==a.enable&&(this.enable=a.enable),void 0!==a.speed&&(this.speed=(0,e.setRangeValue)(a.speed)),void 0!==a.decay&&(this.decay=(0,e.setRangeValue)(a.decay)),void 0!==a.delay&&(this.delay=(0,e.setRangeValue)(a.delay)),void 0!==a.sync&&(this.sync=a.sync))}}class l{constructor(){this.value=0,this.animation=new s,this.direction="clockwise"}load(a){a&&(this.animation.load(a.animation),void 0!==a.value&&(this.value=(0,e.setRangeValue)(a.value)),void 0!==a.direction&&(this.direction=a.direction))}}class c{constructor(){this.angle=new l,this.colors=[],this.type="random"}load(e){e&&(this.angle.load(e.angle),void 0!==e.colors&&(this.colors=e.colors.map((e=>{const a=new o;return a.load(e),a}))),void 0!==e.type&&(this.type=e.type))}}const r=2*Math.PI;class d{getColorStyles(a,t,n,i){const o=a.gradient;if(!o)return{};const s=o.angle.value,l=0,c=0,r="radial"===o.type?t.createRadialGradient(l,c,0,l,c,n):t.createLinearGradient(Math.cos(s)*-n,Math.sin(s)*-n,Math.cos(s)*n,Math.sin(s)*n);for(const{stop:a,value:t,opacity:n}of o.colors)r.addColorStop(a,(0,e.getStyleFromHsl)({h:t.h.value,s:t.s.value,l:t.l.value},n?.value??i));return{fill:r}}init(a){const t=(0,e.itemFromSingleOrMultiple)(a.options.gradient);if(!t)return;const{angle:n}=t;a.gradient={angle:{value:(0,e.getRangeValue)(n.value),enable:n.animation.enable,velocity:(0,e.getRangeValue)(n.animation.speed)/360*a.container.retina.reduceFactor,decay:1-(0,e.getRangeValue)(n.animation.decay),delayTime:(0,e.getRangeValue)(n.animation.delay)*e.millisecondsToSeconds,max:r,min:0,time:0},type:t.type,colors:[]};let i=t.angle.direction;switch("random"===i&&(i=(0,e.getRandom)()>e.halfRandom?"counter-clockwise":"clockwise"),i){case"counter-clockwise":case"counterClockwise":a.gradient.angle.status="decreasing";break;case"clockwise":a.gradient.angle.status="increasing"}const o=a.options.reduceDuplicates;for(const n of t.colors){const t=(0,e.rangeColorToHsl)(n.value,a.id,o);if(!t)continue;const i=(0,e.getHslAnimationFromHsl)(t,n.value.animation,a.container.retina.reduceFactor),s={stop:n.stop,value:i,opacity:n.opacity?{enable:n.opacity.animation.enable,max:(0,e.getRangeMax)(n.opacity.value),min:(0,e.getRangeMin)(n.opacity.value),status:"increasing",value:(0,e.getRangeValue)(n.opacity.value),velocity:(0,e.getRangeValue)(n.opacity.animation.speed)/e.percentDenominator*a.container.retina.reduceFactor,decay:1-(0,e.getRangeValue)(n.opacity.animation.decay),delayTime:(0,e.getRangeValue)(n.opacity.animation.delay)*e.millisecondsToSeconds,time:0}:void 0},{opacity:l}=s;if(n.opacity&&l){const a=n.opacity.value;l.min=(0,e.getRangeMin)(a),l.max=(0,e.getRangeMax)(a);switch(n.opacity.animation.startValue){case"min":l.value=l.min,l.status="increasing";break;case"max":l.value=l.max,l.status="decreasing";break;default:l.value=(0,e.randomInRange)(l),l.status=(0,e.getRandom)()>=e.halfRandom?"increasing":"decreasing"}}a.gradient.colors.push(s)}}isEnabled(e){return!e.destroyed&&!e.spawning&&(!!e.gradient?.angle.enable||(e.gradient?.colors.some((e=>e.value.h.enable||e.value.s.enable||e.value.l.enable))??!1))}loadOptions(a,...t){for(const n of t){if(!n?.gradient)continue;const t=n.gradient;t&&(a.gradient=(0,e.executeOnSingleOrMultiple)(t,(e=>{const a=new c;return a.load(e),a})))}}update(a,t){!function(a,t){const{gradient:n}=a;if(n){(0,e.updateAnimation)(a,n.angle,!1,"none",t);for(const i of n.colors)(0,e.updateColor)(i.value,t),i.opacity&&(0,e.updateAnimation)(a,i.opacity,!0,"none",t)}}(a,t)}}async function u(e,a=!0){await e.addParticleUpdater("gradient",(()=>new d),a)}})(),i})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! tsParticles Gradient Updater v3.0
|
|
1
|
+
/*! tsParticles Gradient Updater v3.1.0 by Matteo Bruni */
|
package/types/Types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GradientType, IParticleHslAnimation, IParticleNumericValueAnimation,
|
|
1
|
+
import type { GradientType, IParticleHslAnimation, IParticleNumericValueAnimation, IParticlesOptions, Particle, ParticlesOptions, SingleOrMultiple } from "@tsparticles/engine";
|
|
2
2
|
import type { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
|
|
3
3
|
import type { IAnimatableGradient } from "./Options/Interfaces/IAnimatableGradient.js";
|
|
4
4
|
export interface IParticleGradientColorAnimation {
|
|
@@ -7,7 +7,7 @@ export interface IParticleGradientColorAnimation {
|
|
|
7
7
|
value: IParticleHslAnimation;
|
|
8
8
|
}
|
|
9
9
|
export interface IParticleGradientAnimation {
|
|
10
|
-
angle:
|
|
10
|
+
angle: IParticleNumericValueAnimation;
|
|
11
11
|
colors: IParticleGradientColorAnimation[];
|
|
12
12
|
type: GradientType;
|
|
13
13
|
}
|
package/umd/GradientUpdater.js
CHANGED
|
@@ -13,14 +13,15 @@
|
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const AnimatableGradient_js_1 = require("./Options/Classes/AnimatableGradient.js");
|
|
15
15
|
const Utils_js_1 = require("./Utils.js");
|
|
16
|
+
const double = 2, doublePI = Math.PI * double;
|
|
16
17
|
class GradientUpdater {
|
|
17
18
|
getColorStyles(particle, context, radius, opacity) {
|
|
18
19
|
const gradient = particle.gradient;
|
|
19
20
|
if (!gradient) {
|
|
20
21
|
return {};
|
|
21
22
|
}
|
|
22
|
-
const gradientAngle = gradient.angle.value, fillGradient = gradient.type === "radial"
|
|
23
|
-
? context.createRadialGradient(
|
|
23
|
+
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === "radial"
|
|
24
|
+
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
24
25
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
25
26
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
26
27
|
fillGradient.addColorStop(stop, (0, engine_1.getStyleFromHsl)({
|
|
@@ -36,14 +37,16 @@
|
|
|
36
37
|
if (!gradient) {
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
|
-
const { angle } = gradient;
|
|
40
|
+
const { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
40
41
|
particle.gradient = {
|
|
41
42
|
angle: {
|
|
42
43
|
value: (0, engine_1.getRangeValue)(angle.value),
|
|
43
44
|
enable: angle.animation.enable,
|
|
44
|
-
velocity: ((0, engine_1.getRangeValue)(angle.animation.speed) /
|
|
45
|
-
decay:
|
|
46
|
-
delayTime: (0, engine_1.getRangeValue)(angle.animation.delay) *
|
|
45
|
+
velocity: ((0, engine_1.getRangeValue)(angle.animation.speed) / speedFactor) * particle.container.retina.reduceFactor,
|
|
46
|
+
decay: delayOffset - (0, engine_1.getRangeValue)(angle.animation.decay),
|
|
47
|
+
delayTime: (0, engine_1.getRangeValue)(angle.animation.delay) * engine_1.millisecondsToSeconds,
|
|
48
|
+
max: doublePI,
|
|
49
|
+
min: 0,
|
|
47
50
|
time: 0,
|
|
48
51
|
},
|
|
49
52
|
type: gradient.type,
|
|
@@ -51,7 +54,7 @@
|
|
|
51
54
|
};
|
|
52
55
|
let rotateDirection = gradient.angle.direction;
|
|
53
56
|
if (rotateDirection === "random") {
|
|
54
|
-
rotateDirection = (0, engine_1.getRandom)() >
|
|
57
|
+
rotateDirection = (0, engine_1.getRandom)() > engine_1.halfRandom ? "counter-clockwise" : "clockwise";
|
|
55
58
|
}
|
|
56
59
|
switch (rotateDirection) {
|
|
57
60
|
case "counter-clockwise":
|
|
@@ -78,10 +81,10 @@
|
|
|
78
81
|
min: (0, engine_1.getRangeMin)(grColor.opacity.value),
|
|
79
82
|
status: "increasing",
|
|
80
83
|
value: (0, engine_1.getRangeValue)(grColor.opacity.value),
|
|
81
|
-
velocity: ((0, engine_1.getRangeValue)(grColor.opacity.animation.speed) /
|
|
84
|
+
velocity: ((0, engine_1.getRangeValue)(grColor.opacity.animation.speed) / engine_1.percentDenominator) *
|
|
82
85
|
particle.container.retina.reduceFactor,
|
|
83
|
-
decay:
|
|
84
|
-
delayTime: (0, engine_1.getRangeValue)(grColor.opacity.animation.delay) *
|
|
86
|
+
decay: delayOffset - (0, engine_1.getRangeValue)(grColor.opacity.animation.decay),
|
|
87
|
+
delayTime: (0, engine_1.getRangeValue)(grColor.opacity.animation.delay) * engine_1.millisecondsToSeconds,
|
|
85
88
|
time: 0,
|
|
86
89
|
}
|
|
87
90
|
: undefined,
|
|
@@ -105,7 +108,7 @@
|
|
|
105
108
|
default:
|
|
106
109
|
addOpacity.value = (0, engine_1.randomInRange)(addOpacity);
|
|
107
110
|
addOpacity.status =
|
|
108
|
-
(0, engine_1.getRandom)() >=
|
|
111
|
+
(0, engine_1.getRandom)() >= engine_1.halfRandom ? "increasing" : "decreasing";
|
|
109
112
|
break;
|
|
110
113
|
}
|
|
111
114
|
}
|
|
@@ -115,7 +118,7 @@
|
|
|
115
118
|
isEnabled(particle) {
|
|
116
119
|
return (!particle.destroyed &&
|
|
117
120
|
!particle.spawning &&
|
|
118
|
-
(particle.gradient?.angle.enable ||
|
|
121
|
+
(!!particle.gradient?.angle.enable ||
|
|
119
122
|
(particle.gradient?.colors.some((c) => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
120
123
|
false)));
|
|
121
124
|
}
|
package/umd/Utils.js
CHANGED
|
@@ -4,116 +4,23 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.updateGradient = void 0;
|
|
13
|
-
|
|
14
|
-
if (!value.enable) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const decay = value.decay ?? 1;
|
|
18
|
-
switch (value.status) {
|
|
19
|
-
case "increasing":
|
|
20
|
-
if (value.value >= value.max) {
|
|
21
|
-
value.status = "decreasing";
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
value.value += (value.velocity ?? 0) * delta.factor;
|
|
25
|
-
}
|
|
26
|
-
break;
|
|
27
|
-
case "decreasing":
|
|
28
|
-
if (value.value <= value.min) {
|
|
29
|
-
value.status = "increasing";
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
value.value -= (value.velocity ?? 0) * delta.factor;
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
if (value.velocity && decay !== 1) {
|
|
37
|
-
value.velocity *= decay;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function updateColorValue(delta, colorValue, max, decrease) {
|
|
41
|
-
if (!colorValue || !colorValue.enable) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (!colorValue.time) {
|
|
45
|
-
colorValue.time = 0;
|
|
46
|
-
}
|
|
47
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
48
|
-
colorValue.time += delta.value;
|
|
49
|
-
}
|
|
50
|
-
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const velocity = (colorValue.velocity ?? 0) * delta.factor, decay = colorValue.decay ?? 1;
|
|
54
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
55
|
-
colorValue.value += velocity;
|
|
56
|
-
if (decrease && colorValue.value > max) {
|
|
57
|
-
colorValue.status = "decreasing";
|
|
58
|
-
colorValue.value -= colorValue.value % max;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
colorValue.value -= velocity;
|
|
63
|
-
if (colorValue.value < 0) {
|
|
64
|
-
colorValue.status = "increasing";
|
|
65
|
-
colorValue.value += colorValue.value;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (colorValue.value > max) {
|
|
69
|
-
colorValue.value %= max;
|
|
70
|
-
}
|
|
71
|
-
if (colorValue.velocity && decay !== 1) {
|
|
72
|
-
colorValue.velocity *= decay;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function updateAngle(delta, angle) {
|
|
76
|
-
const speed = (angle.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = angle.decay ?? 1;
|
|
77
|
-
if (!angle.enable) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
switch (angle.status) {
|
|
81
|
-
case "increasing":
|
|
82
|
-
angle.value += speed;
|
|
83
|
-
if (angle.value > max) {
|
|
84
|
-
angle.value -= max;
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
case "decreasing":
|
|
88
|
-
default:
|
|
89
|
-
angle.value -= speed;
|
|
90
|
-
if (angle.value < 0) {
|
|
91
|
-
angle.value += max;
|
|
92
|
-
}
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (angle.velocity && decay !== 1) {
|
|
96
|
-
angle.velocity *= decay;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
99
14
|
function updateGradient(particle, delta) {
|
|
100
15
|
const { gradient } = particle;
|
|
101
16
|
if (!gradient) {
|
|
102
17
|
return;
|
|
103
18
|
}
|
|
104
|
-
|
|
19
|
+
(0, engine_1.updateAnimation)(particle, gradient.angle, false, "none", delta);
|
|
105
20
|
for (const color of gradient.colors) {
|
|
106
|
-
|
|
107
|
-
updateColorValue(delta, color.value.h, 360, false);
|
|
108
|
-
}
|
|
109
|
-
if (particle.color?.s !== undefined) {
|
|
110
|
-
updateColorValue(delta, color.value.s, 100, true);
|
|
111
|
-
}
|
|
112
|
-
if (particle.color?.l !== undefined) {
|
|
113
|
-
updateColorValue(delta, color.value.l, 100, true);
|
|
114
|
-
}
|
|
21
|
+
(0, engine_1.updateColor)(color.value, delta);
|
|
115
22
|
if (color.opacity) {
|
|
116
|
-
|
|
23
|
+
(0, engine_1.updateAnimation)(particle, color.opacity, true, "none", delta);
|
|
117
24
|
}
|
|
118
25
|
}
|
|
119
26
|
}
|