@tsparticles/updater-gradient 3.0.0-alpha.0 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -12
- package/browser/GradientUpdater.js +34 -132
- package/browser/Options/Classes/AnimatableGradientColor.js +2 -2
- package/browser/Options/Classes/GradientAngle.js +2 -1
- package/browser/Options/Classes/GradientAngleAnimation.js +5 -1
- package/browser/Options/Classes/GradientColorOpacity.js +1 -1
- package/browser/Options/Classes/GradientColorOpacityAnimation.js +8 -1
- package/browser/Types.js +1 -0
- package/browser/Utils.js +107 -0
- package/browser/index.js +2 -2
- package/cjs/GradientUpdater.js +35 -133
- package/cjs/Options/Classes/AnimatableGradientColor.js +1 -1
- package/cjs/Options/Classes/GradientAngle.js +2 -1
- package/cjs/Options/Classes/GradientAngleAnimation.js +4 -0
- package/cjs/Options/Classes/GradientColorOpacity.js +1 -1
- package/cjs/Options/Classes/GradientColorOpacityAnimation.js +7 -0
- package/cjs/Types.js +2 -0
- package/cjs/Utils.js +111 -0
- package/cjs/index.js +2 -2
- package/esm/GradientUpdater.js +34 -132
- package/esm/Options/Classes/AnimatableGradientColor.js +2 -2
- package/esm/Options/Classes/GradientAngle.js +2 -1
- package/esm/Options/Classes/GradientAngleAnimation.js +5 -1
- package/esm/Options/Classes/GradientColorOpacity.js +1 -1
- package/esm/Options/Classes/GradientColorOpacityAnimation.js +8 -1
- package/esm/Types.js +1 -0
- package/esm/Utils.js +107 -0
- package/esm/index.js +2 -2
- package/package.json +10 -5
- package/report.html +4 -4
- package/tsparticles.updater.gradient.js +87 -56
- package/tsparticles.updater.gradient.min.js +1 -1
- package/tsparticles.updater.gradient.min.js.LICENSE.txt +1 -8
- package/types/GradientUpdater.d.ts +2 -25
- package/types/Options/Classes/AnimatableGradient.d.ts +1 -2
- package/types/Options/Classes/AnimatableGradientColor.d.ts +1 -2
- package/types/Options/Classes/GradientAngle.d.ts +2 -3
- package/types/Options/Classes/GradientAngleAnimation.d.ts +2 -1
- package/types/Options/Classes/GradientColorOpacity.d.ts +1 -1
- package/types/Options/Classes/GradientColorOpacityAnimation.d.ts +2 -2
- package/types/Options/Interfaces/Gradients.d.ts +1 -1
- package/types/Types.d.ts +23 -0
- package/types/Utils.d.ts +3 -0
- package/types/index.d.ts +1 -1
- package/umd/GradientUpdater.js +36 -134
- package/umd/Options/Classes/AnimatableGradientColor.js +1 -1
- package/umd/Options/Classes/GradientAngle.js +3 -2
- package/umd/Options/Classes/GradientAngleAnimation.js +4 -0
- package/umd/Options/Classes/GradientColorOpacity.js +2 -2
- package/umd/Options/Classes/GradientColorOpacityAnimation.js +7 -0
- package/umd/Types.js +12 -0
- package/umd/Utils.js +121 -0
- package/umd/index.js +2 -2
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# tsParticles Gradient Updater
|
|
4
4
|
|
|
5
|
-
[](https://www.jsdelivr.com/package/npm/@tsparticles/updater-gradient)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/updater-gradient)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/updater-gradient) [](https://github.com/sponsors/matteobruni)
|
|
8
8
|
|
|
9
9
|
[tsParticles](https://github.com/matteobruni/tsparticles) updater plugin for gradient animations.
|
|
10
10
|
|
|
@@ -26,7 +26,7 @@ Once the scripts are loaded you can set up `tsParticles` and the updater plugin
|
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
28
|
(async () => {
|
|
29
|
-
await loadGradientUpdater();
|
|
29
|
+
await loadGradientUpdater(tsParticles);
|
|
30
30
|
|
|
31
31
|
await tsParticles.load({
|
|
32
32
|
id: "tsparticles",
|
|
@@ -42,29 +42,33 @@ Once the scripts are loaded you can set up `tsParticles` and the updater plugin
|
|
|
42
42
|
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
43
|
|
|
44
44
|
```shell
|
|
45
|
-
$ npm install tsparticles
|
|
45
|
+
$ npm install @tsparticles/updater-gradient
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
or
|
|
49
49
|
|
|
50
50
|
```shell
|
|
51
|
-
$ yarn add tsparticles
|
|
51
|
+
$ yarn add @tsparticles/updater-gradient
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Then you need to import it in the app, like this:
|
|
55
55
|
|
|
56
56
|
```javascript
|
|
57
|
-
const { tsParticles } = require("tsparticles
|
|
58
|
-
const { loadGradientUpdater } = require("tsparticles
|
|
57
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
58
|
+
const { loadGradientUpdater } = require("@tsparticles/updater-gradient");
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
(async () => {
|
|
61
|
+
await loadGradientUpdater(tsParticles);
|
|
62
|
+
})();
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
or
|
|
64
66
|
|
|
65
67
|
```javascript
|
|
66
|
-
import { tsParticles } from "tsparticles
|
|
67
|
-
import { loadGradientUpdater } from "tsparticles
|
|
68
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
69
|
+
import { loadGradientUpdater } from "@tsparticles/updater-gradient";
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
(async () => {
|
|
72
|
+
await loadGradientUpdater(tsParticles);
|
|
73
|
+
})();
|
|
70
74
|
```
|
|
@@ -1,111 +1,8 @@
|
|
|
1
1
|
import { executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
2
|
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient";
|
|
3
|
-
|
|
4
|
-
var _a, _b, _c;
|
|
5
|
-
if (!value.enable) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const decay = (_a = value.decay) !== null && _a !== void 0 ? _a : 1;
|
|
9
|
-
switch (value.status) {
|
|
10
|
-
case "increasing":
|
|
11
|
-
if (value.value >= value.max) {
|
|
12
|
-
value.status = "decreasing";
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
value.value += ((_b = value.velocity) !== null && _b !== void 0 ? _b : 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 -= ((_c = value.velocity) !== null && _c !== void 0 ? _c : 0) * delta.factor;
|
|
24
|
-
}
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
if (value.velocity && decay !== 1) {
|
|
28
|
-
value.velocity *= decay;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function updateColorValue(delta, value, max, decrease) {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
const colorValue = value;
|
|
34
|
-
if (!colorValue || !colorValue.enable) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
|
|
38
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
39
|
-
colorValue.value += velocity;
|
|
40
|
-
if (decrease && colorValue.value > max) {
|
|
41
|
-
colorValue.status = "decreasing";
|
|
42
|
-
colorValue.value -= colorValue.value % max;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
colorValue.value -= velocity;
|
|
47
|
-
if (colorValue.value < 0) {
|
|
48
|
-
colorValue.status = "increasing";
|
|
49
|
-
colorValue.value += colorValue.value;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (colorValue.value > max) {
|
|
53
|
-
colorValue.value %= max;
|
|
54
|
-
}
|
|
55
|
-
if (value.velocity && decay !== 1) {
|
|
56
|
-
value.velocity *= decay;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function updateAngle(delta, angle) {
|
|
60
|
-
var _a, _b;
|
|
61
|
-
const speed = ((_a = angle.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = angle.decay) !== null && _b !== void 0 ? _b : 1;
|
|
62
|
-
if (!angle.enable) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
switch (angle.status) {
|
|
66
|
-
case "increasing":
|
|
67
|
-
angle.value += speed;
|
|
68
|
-
if (angle.value > max) {
|
|
69
|
-
angle.value -= max;
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
case "decreasing":
|
|
73
|
-
default:
|
|
74
|
-
angle.value -= speed;
|
|
75
|
-
if (angle.value < 0) {
|
|
76
|
-
angle.value += max;
|
|
77
|
-
}
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
if (angle.velocity && decay !== 1) {
|
|
81
|
-
angle.velocity *= decay;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function updateGradient(particle, delta) {
|
|
85
|
-
var _a, _b, _c;
|
|
86
|
-
const gradient = particle.gradient;
|
|
87
|
-
if (!gradient) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
updateAngle(delta, gradient.angle);
|
|
91
|
-
for (const color of gradient.colors) {
|
|
92
|
-
if (((_a = particle.color) === null || _a === void 0 ? void 0 : _a.h) !== undefined) {
|
|
93
|
-
updateColorValue(delta, color.value.h, 360, false);
|
|
94
|
-
}
|
|
95
|
-
if (((_b = particle.color) === null || _b === void 0 ? void 0 : _b.s) !== undefined) {
|
|
96
|
-
updateColorValue(delta, color.value.s, 100, true);
|
|
97
|
-
}
|
|
98
|
-
if (((_c = particle.color) === null || _c === void 0 ? void 0 : _c.l) !== undefined) {
|
|
99
|
-
updateColorValue(delta, color.value.l, 100, true);
|
|
100
|
-
}
|
|
101
|
-
if (color.opacity) {
|
|
102
|
-
updateColorOpacity(delta, color.opacity);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
3
|
+
import { updateGradient } from "./Utils";
|
|
106
4
|
export class GradientUpdater {
|
|
107
5
|
getColorStyles(particle, context, radius, opacity) {
|
|
108
|
-
var _a, _b;
|
|
109
6
|
const gradient = particle.gradient;
|
|
110
7
|
if (!gradient) {
|
|
111
8
|
return {};
|
|
@@ -113,12 +10,12 @@ export class GradientUpdater {
|
|
|
113
10
|
const gradientAngle = gradient.angle.value, fillGradient = gradient.type === "radial"
|
|
114
11
|
? context.createRadialGradient(0, 0, 0, 0, 0, radius)
|
|
115
12
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
116
|
-
for (const
|
|
117
|
-
fillGradient.addColorStop(
|
|
118
|
-
h:
|
|
119
|
-
s:
|
|
120
|
-
l:
|
|
121
|
-
},
|
|
13
|
+
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
14
|
+
fillGradient.addColorStop(stop, getStyleFromHsl({
|
|
15
|
+
h: value.h.value,
|
|
16
|
+
s: value.s.value,
|
|
17
|
+
l: value.l.value,
|
|
18
|
+
}, cOpacity?.value ?? opacity));
|
|
122
19
|
}
|
|
123
20
|
return { fill: fillGradient };
|
|
124
21
|
}
|
|
@@ -127,20 +24,22 @@ export class GradientUpdater {
|
|
|
127
24
|
if (!gradient) {
|
|
128
25
|
return;
|
|
129
26
|
}
|
|
27
|
+
const { angle } = gradient;
|
|
130
28
|
particle.gradient = {
|
|
131
29
|
angle: {
|
|
132
|
-
value:
|
|
133
|
-
enable:
|
|
134
|
-
velocity: (getRangeValue(
|
|
135
|
-
decay: 1 - getRangeValue(
|
|
30
|
+
value: getRangeValue(angle.value),
|
|
31
|
+
enable: angle.animation.enable,
|
|
32
|
+
velocity: (getRangeValue(angle.animation.speed) / 360) * particle.container.retina.reduceFactor,
|
|
33
|
+
decay: 1 - getRangeValue(angle.animation.decay),
|
|
34
|
+
delayTime: getRangeValue(angle.animation.delay) * 1000,
|
|
35
|
+
time: 0,
|
|
136
36
|
},
|
|
137
37
|
type: gradient.type,
|
|
138
38
|
colors: [],
|
|
139
39
|
};
|
|
140
40
|
let rotateDirection = gradient.angle.direction;
|
|
141
41
|
if (rotateDirection === "random") {
|
|
142
|
-
|
|
143
|
-
rotateDirection = index > 0 ? "counter-clockwise" : "clockwise";
|
|
42
|
+
rotateDirection = getRandom() > 0.5 ? "counter-clockwise" : "clockwise";
|
|
144
43
|
}
|
|
145
44
|
switch (rotateDirection) {
|
|
146
45
|
case "counter-clockwise":
|
|
@@ -170,28 +69,31 @@ export class GradientUpdater {
|
|
|
170
69
|
velocity: (getRangeValue(grColor.opacity.animation.speed) / 100) *
|
|
171
70
|
particle.container.retina.reduceFactor,
|
|
172
71
|
decay: 1 - getRangeValue(grColor.opacity.animation.decay),
|
|
72
|
+
delayTime: getRangeValue(grColor.opacity.animation.delay) * 1000,
|
|
73
|
+
time: 0,
|
|
173
74
|
}
|
|
174
75
|
: undefined,
|
|
175
76
|
};
|
|
176
|
-
|
|
77
|
+
const { opacity: addOpacity } = addColor;
|
|
78
|
+
if (grColor.opacity && addOpacity) {
|
|
177
79
|
const opacityRange = grColor.opacity.value;
|
|
178
|
-
|
|
179
|
-
|
|
80
|
+
addOpacity.min = getRangeMin(opacityRange);
|
|
81
|
+
addOpacity.max = getRangeMax(opacityRange);
|
|
180
82
|
const opacityAnimation = grColor.opacity.animation;
|
|
181
83
|
switch (opacityAnimation.startValue) {
|
|
182
84
|
case "min":
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
break;
|
|
186
|
-
case "random":
|
|
187
|
-
addColor.opacity.value = randomInRange(addColor.opacity);
|
|
188
|
-
addColor.opacity.status =
|
|
189
|
-
getRandom() >= 0.5 ? "increasing" : "decreasing";
|
|
85
|
+
addOpacity.value = addOpacity.min;
|
|
86
|
+
addOpacity.status = "increasing";
|
|
190
87
|
break;
|
|
191
88
|
case "max":
|
|
89
|
+
addOpacity.value = addOpacity.max;
|
|
90
|
+
addOpacity.status = "decreasing";
|
|
91
|
+
break;
|
|
92
|
+
case "random":
|
|
192
93
|
default:
|
|
193
|
-
|
|
194
|
-
|
|
94
|
+
addOpacity.value = randomInRange(addOpacity);
|
|
95
|
+
addOpacity.status =
|
|
96
|
+
getRandom() >= 0.5 ? "increasing" : "decreasing";
|
|
195
97
|
break;
|
|
196
98
|
}
|
|
197
99
|
}
|
|
@@ -199,15 +101,15 @@ export class GradientUpdater {
|
|
|
199
101
|
}
|
|
200
102
|
}
|
|
201
103
|
isEnabled(particle) {
|
|
202
|
-
var _a, _b, _c;
|
|
203
104
|
return (!particle.destroyed &&
|
|
204
105
|
!particle.spawning &&
|
|
205
|
-
(
|
|
206
|
-
(
|
|
106
|
+
(particle.gradient?.angle.enable ||
|
|
107
|
+
(particle.gradient?.colors.some((c) => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
108
|
+
false)));
|
|
207
109
|
}
|
|
208
110
|
loadOptions(options, ...sources) {
|
|
209
111
|
for (const source of sources) {
|
|
210
|
-
if (!
|
|
112
|
+
if (!source?.gradient) {
|
|
211
113
|
continue;
|
|
212
114
|
}
|
|
213
115
|
const gradientToLoad = source.gradient;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnimatableColor } from "@tsparticles/engine";
|
|
1
|
+
import { AnimatableColor, isNumber } from "@tsparticles/engine";
|
|
2
2
|
import { GradientColorOpacity } from "./GradientColorOpacity";
|
|
3
3
|
export class AnimatableGradientColor {
|
|
4
4
|
constructor() {
|
|
@@ -15,7 +15,7 @@ export class AnimatableGradientColor {
|
|
|
15
15
|
this.value = AnimatableColor.create(this.value, data.value);
|
|
16
16
|
if (data.opacity !== undefined) {
|
|
17
17
|
this.opacity = new GradientColorOpacity();
|
|
18
|
-
if (
|
|
18
|
+
if (isNumber(data.opacity)) {
|
|
19
19
|
this.opacity.value = data.opacity;
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setRangeValue, } from "@tsparticles/engine";
|
|
1
2
|
import { GradientAngleAnimation } from "./GradientAngleAnimation";
|
|
2
3
|
export class GradientAngle {
|
|
3
4
|
constructor() {
|
|
@@ -11,7 +12,7 @@ export class GradientAngle {
|
|
|
11
12
|
}
|
|
12
13
|
this.animation.load(data.animation);
|
|
13
14
|
if (data.value !== undefined) {
|
|
14
|
-
this.value = data.value;
|
|
15
|
+
this.value = setRangeValue(data.value);
|
|
15
16
|
}
|
|
16
17
|
if (data.direction !== undefined) {
|
|
17
18
|
this.direction = data.direction;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { setRangeValue } from "@tsparticles/engine";
|
|
1
|
+
import { setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
export class GradientAngleAnimation {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.count = 0;
|
|
5
5
|
this.enable = false;
|
|
6
6
|
this.speed = 0;
|
|
7
7
|
this.decay = 0;
|
|
8
|
+
this.delay = 0;
|
|
8
9
|
this.sync = false;
|
|
9
10
|
}
|
|
10
11
|
load(data) {
|
|
@@ -23,6 +24,9 @@ export class GradientAngleAnimation {
|
|
|
23
24
|
if (data.decay !== undefined) {
|
|
24
25
|
this.decay = setRangeValue(data.decay);
|
|
25
26
|
}
|
|
27
|
+
if (data.delay !== undefined) {
|
|
28
|
+
this.delay = setRangeValue(data.delay);
|
|
29
|
+
}
|
|
26
30
|
if (data.sync !== undefined) {
|
|
27
31
|
this.sync = data.sync;
|
|
28
32
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { setRangeValue } from "@tsparticles/engine";
|
|
1
|
+
import { setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
export class GradientColorOpacityAnimation {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.count = 0;
|
|
5
5
|
this.enable = false;
|
|
6
6
|
this.speed = 0;
|
|
7
7
|
this.decay = 0;
|
|
8
|
+
this.delay = 0;
|
|
8
9
|
this.sync = false;
|
|
9
10
|
this.startValue = "random";
|
|
10
11
|
}
|
|
@@ -27,5 +28,11 @@ export class GradientColorOpacityAnimation {
|
|
|
27
28
|
if (data.startValue !== undefined) {
|
|
28
29
|
this.startValue = data.startValue;
|
|
29
30
|
}
|
|
31
|
+
if (data.decay !== undefined) {
|
|
32
|
+
this.decay = setRangeValue(data.decay);
|
|
33
|
+
}
|
|
34
|
+
if (data.delay !== undefined) {
|
|
35
|
+
this.delay = setRangeValue(data.delay);
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
38
|
}
|
package/browser/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/Utils.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
function updateColorOpacity(delta, value) {
|
|
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
|
+
}
|
|
87
|
+
export function updateGradient(particle, delta) {
|
|
88
|
+
const { gradient } = particle;
|
|
89
|
+
if (!gradient) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
updateAngle(delta, gradient.angle);
|
|
93
|
+
for (const color of gradient.colors) {
|
|
94
|
+
if (particle.color?.h !== undefined) {
|
|
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
|
+
}
|
|
103
|
+
if (color.opacity) {
|
|
104
|
+
updateColorOpacity(delta, color.opacity);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
package/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { GradientUpdater } from "./GradientUpdater";
|
|
2
|
-
export function loadGradientUpdater(engine) {
|
|
3
|
-
engine.addParticleUpdater("gradient", () => new GradientUpdater());
|
|
2
|
+
export async function loadGradientUpdater(engine, refresh = true) {
|
|
3
|
+
await engine.addParticleUpdater("gradient", () => new GradientUpdater(), refresh);
|
|
4
4
|
}
|