@tsparticles/updater-orbit 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/Options/Classes/Orbit.js +33 -0
- package/browser/Options/Classes/OrbitRotation.js +15 -0
- package/browser/Options/Interfaces/IOrbit.js +1 -0
- package/browser/OrbitUpdater.js +93 -0
- package/browser/index.js +4 -0
- package/cjs/Options/Classes/Orbit.js +37 -0
- package/cjs/Options/Classes/OrbitRotation.js +19 -0
- package/cjs/Options/Interfaces/IOrbit.js +2 -0
- package/cjs/OrbitUpdater.js +97 -0
- package/cjs/index.js +8 -0
- package/esm/Options/Classes/Orbit.js +33 -0
- package/esm/Options/Classes/OrbitRotation.js +15 -0
- package/esm/Options/Interfaces/IOrbit.js +1 -0
- package/esm/OrbitUpdater.js +93 -0
- package/esm/index.js +4 -0
- package/package.json +92 -0
- package/report.html +39 -0
- package/tsparticles.updater.orbit.js +252 -0
- package/tsparticles.updater.orbit.min.js +2 -0
- package/tsparticles.updater.orbit.min.js.LICENSE.txt +8 -0
- package/types/Options/Classes/Orbit.d.ts +15 -0
- package/types/Options/Classes/OrbitRotation.d.ts +6 -0
- package/types/Options/Interfaces/IOrbit.d.ts +9 -0
- package/types/OrbitUpdater.d.ts +42 -0
- package/types/index.d.ts +2 -0
- package/umd/Options/Classes/Orbit.js +47 -0
- package/umd/Options/Classes/OrbitRotation.js +29 -0
- package/umd/Options/Interfaces/IOrbit.js +12 -0
- package/umd/OrbitUpdater.js +107 -0
- package/umd/index.js +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Orbit Updater
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/tsparticles-updater-orbit)
|
|
6
|
+
[](https://www.npmjs.com/package/tsparticles-updater-orbit)
|
|
7
|
+
[](https://www.npmjs.com/package/tsparticles-updater-orbit) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) updater plugin for orbit animations.
|
|
10
|
+
|
|
11
|
+
## How to use it
|
|
12
|
+
|
|
13
|
+
### CDN / Vanilla JS / jQuery
|
|
14
|
+
|
|
15
|
+
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
16
|
+
|
|
17
|
+
Including the `tsparticles.updater.orbit.min.js` file will export the function to load the updater plugin:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
loadOrbitUpdater
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the updater plugin like this:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadOrbitUpdater();
|
|
30
|
+
|
|
31
|
+
await tsParticles.load({
|
|
32
|
+
id: "tsparticles",
|
|
33
|
+
options: {
|
|
34
|
+
/* options */
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
})();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### ESM / CommonJS
|
|
41
|
+
|
|
42
|
+
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
$ npm install tsparticles-updater-orbit
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add tsparticles-updater-orbit
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then you need to import it in the app, like this:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const { tsParticles } = require("tsparticles-engine");
|
|
58
|
+
const { loadOrbitUpdater } = require("tsparticles-updater-orbit");
|
|
59
|
+
|
|
60
|
+
loadOrbitUpdater(tsParticles);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { tsParticles } from "tsparticles-engine";
|
|
67
|
+
import { loadOrbitUpdater } from "tsparticles-updater-orbit";
|
|
68
|
+
|
|
69
|
+
loadOrbitUpdater(tsParticles);
|
|
70
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AnimationOptions, OptionsColor, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { OrbitRotation } from "./OrbitRotation";
|
|
3
|
+
export class Orbit {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.animation = new AnimationOptions();
|
|
6
|
+
this.enable = false;
|
|
7
|
+
this.opacity = 1;
|
|
8
|
+
this.rotation = new OrbitRotation();
|
|
9
|
+
this.width = 1;
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.animation.load(data.animation);
|
|
16
|
+
this.rotation.load(data.rotation);
|
|
17
|
+
if (data.enable !== undefined) {
|
|
18
|
+
this.enable = data.enable;
|
|
19
|
+
}
|
|
20
|
+
if (data.opacity !== undefined) {
|
|
21
|
+
this.opacity = setRangeValue(data.opacity);
|
|
22
|
+
}
|
|
23
|
+
if (data.width !== undefined) {
|
|
24
|
+
this.width = setRangeValue(data.width);
|
|
25
|
+
}
|
|
26
|
+
if (data.radius !== undefined) {
|
|
27
|
+
this.radius = setRangeValue(data.radius);
|
|
28
|
+
}
|
|
29
|
+
if (data.color !== undefined) {
|
|
30
|
+
this.color = OptionsColor.create(this.color, data.color);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
2
|
+
export class OrbitRotation extends ValueWithRandom {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this.value = 45;
|
|
6
|
+
this.random.enable = false;
|
|
7
|
+
this.random.minimumValue = 0;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (data === undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
super.load(data);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { getRangeValue, getStyleFromHsl, rangeColorToHsl } from "@tsparticles/engine";
|
|
2
|
+
import { Orbit } from "./Options/Classes/Orbit";
|
|
3
|
+
function drawEllipse(context, particle, fillColorValue, radius, opacity, width, rotation, start, end) {
|
|
4
|
+
if (width <= 0) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const pos = particle.getPosition();
|
|
8
|
+
if (fillColorValue) {
|
|
9
|
+
context.strokeStyle = getStyleFromHsl(fillColorValue, opacity);
|
|
10
|
+
}
|
|
11
|
+
context.lineWidth = width;
|
|
12
|
+
const rotationRadian = (rotation * Math.PI) / 180;
|
|
13
|
+
context.beginPath();
|
|
14
|
+
context.ellipse(pos.x, pos.y, radius / 2, radius * 2, rotationRadian, start, end);
|
|
15
|
+
context.stroke();
|
|
16
|
+
}
|
|
17
|
+
export class OrbitUpdater {
|
|
18
|
+
constructor(container) {
|
|
19
|
+
this.container = container;
|
|
20
|
+
}
|
|
21
|
+
afterDraw(particle) {
|
|
22
|
+
const orbitOptions = particle.options.orbit;
|
|
23
|
+
if (orbitOptions === null || orbitOptions === void 0 ? void 0 : orbitOptions.enable) {
|
|
24
|
+
this.drawOrbit(particle, "front");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
beforeDraw(particle) {
|
|
28
|
+
const orbitOptions = particle.options.orbit;
|
|
29
|
+
if (orbitOptions === null || orbitOptions === void 0 ? void 0 : orbitOptions.enable) {
|
|
30
|
+
this.drawOrbit(particle, "back");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
drawOrbit(particle, type) {
|
|
34
|
+
const container = this.container;
|
|
35
|
+
let start, end;
|
|
36
|
+
switch (type) {
|
|
37
|
+
case "back":
|
|
38
|
+
start = Math.PI / 2;
|
|
39
|
+
end = (Math.PI * 3) / 2;
|
|
40
|
+
break;
|
|
41
|
+
case "front":
|
|
42
|
+
start = (Math.PI * 3) / 2;
|
|
43
|
+
end = Math.PI / 2;
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
start = 0;
|
|
47
|
+
end = 2 * Math.PI;
|
|
48
|
+
}
|
|
49
|
+
container.canvas.draw((ctx) => {
|
|
50
|
+
var _a, _b, _c, _d, _e, _f;
|
|
51
|
+
drawEllipse(ctx, particle, (_a = particle.orbitColor) !== null && _a !== void 0 ? _a : particle.getFillColor(), (_c = (_b = particle.retina.orbitRadius) !== null && _b !== void 0 ? _b : container.retina.orbitRadius) !== null && _c !== void 0 ? _c : particle.getRadius(), (_d = particle.orbitOpacity) !== null && _d !== void 0 ? _d : 1, (_e = particle.orbitWidth) !== null && _e !== void 0 ? _e : 1, ((_f = particle.orbitRotation) !== null && _f !== void 0 ? _f : 0) * container.retina.pixelRatio, start, end);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
init(particle) {
|
|
55
|
+
const container = this.container, particlesOptions = particle.options, orbitOptions = particlesOptions.orbit;
|
|
56
|
+
if (!(orbitOptions === null || orbitOptions === void 0 ? void 0 : orbitOptions.enable)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
particle.orbitRotation = getRangeValue(orbitOptions.rotation.value);
|
|
60
|
+
particle.orbitColor = rangeColorToHsl(orbitOptions.color);
|
|
61
|
+
particle.retina.orbitRadius =
|
|
62
|
+
orbitOptions.radius !== undefined
|
|
63
|
+
? getRangeValue(orbitOptions.radius) * container.retina.pixelRatio
|
|
64
|
+
: undefined;
|
|
65
|
+
container.retina.orbitRadius = particle.retina.orbitRadius;
|
|
66
|
+
particle.orbitAnimationSpeed = orbitOptions.animation.enable ? getRangeValue(orbitOptions.animation.speed) : 0;
|
|
67
|
+
particle.orbitWidth = getRangeValue(orbitOptions.width);
|
|
68
|
+
particle.orbitOpacity = getRangeValue(orbitOptions.opacity);
|
|
69
|
+
}
|
|
70
|
+
isEnabled(particle) {
|
|
71
|
+
var _a;
|
|
72
|
+
const orbitAnimations = (_a = particle.options.orbit) === null || _a === void 0 ? void 0 : _a.animation;
|
|
73
|
+
return !particle.destroyed && !particle.spawning && !!(orbitAnimations === null || orbitAnimations === void 0 ? void 0 : orbitAnimations.enable);
|
|
74
|
+
}
|
|
75
|
+
loadOptions(options, ...sources) {
|
|
76
|
+
if (!options.orbit) {
|
|
77
|
+
options.orbit = new Orbit();
|
|
78
|
+
}
|
|
79
|
+
for (const source of sources) {
|
|
80
|
+
options.orbit.load(source === null || source === void 0 ? void 0 : source.orbit);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
update(particle, delta) {
|
|
84
|
+
var _a;
|
|
85
|
+
if (!this.isEnabled(particle)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (particle.orbitRotation === undefined) {
|
|
89
|
+
particle.orbitRotation = 0;
|
|
90
|
+
}
|
|
91
|
+
particle.orbitRotation += ((_a = particle.orbitAnimationSpeed) !== null && _a !== void 0 ? _a : 0 / (Math.PI * 2)) * delta.factor;
|
|
92
|
+
}
|
|
93
|
+
}
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Orbit = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const OrbitRotation_1 = require("./OrbitRotation");
|
|
6
|
+
class Orbit {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.animation = new engine_1.AnimationOptions();
|
|
9
|
+
this.enable = false;
|
|
10
|
+
this.opacity = 1;
|
|
11
|
+
this.rotation = new OrbitRotation_1.OrbitRotation();
|
|
12
|
+
this.width = 1;
|
|
13
|
+
}
|
|
14
|
+
load(data) {
|
|
15
|
+
if (!data) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
this.animation.load(data.animation);
|
|
19
|
+
this.rotation.load(data.rotation);
|
|
20
|
+
if (data.enable !== undefined) {
|
|
21
|
+
this.enable = data.enable;
|
|
22
|
+
}
|
|
23
|
+
if (data.opacity !== undefined) {
|
|
24
|
+
this.opacity = (0, engine_1.setRangeValue)(data.opacity);
|
|
25
|
+
}
|
|
26
|
+
if (data.width !== undefined) {
|
|
27
|
+
this.width = (0, engine_1.setRangeValue)(data.width);
|
|
28
|
+
}
|
|
29
|
+
if (data.radius !== undefined) {
|
|
30
|
+
this.radius = (0, engine_1.setRangeValue)(data.radius);
|
|
31
|
+
}
|
|
32
|
+
if (data.color !== undefined) {
|
|
33
|
+
this.color = engine_1.OptionsColor.create(this.color, data.color);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Orbit = Orbit;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrbitRotation = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
class OrbitRotation extends engine_1.ValueWithRandom {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.value = 45;
|
|
9
|
+
this.random.enable = false;
|
|
10
|
+
this.random.minimumValue = 0;
|
|
11
|
+
}
|
|
12
|
+
load(data) {
|
|
13
|
+
if (data === undefined) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
super.load(data);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.OrbitRotation = OrbitRotation;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrbitUpdater = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const Orbit_1 = require("./Options/Classes/Orbit");
|
|
6
|
+
function drawEllipse(context, particle, fillColorValue, radius, opacity, width, rotation, start, end) {
|
|
7
|
+
if (width <= 0) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const pos = particle.getPosition();
|
|
11
|
+
if (fillColorValue) {
|
|
12
|
+
context.strokeStyle = (0, engine_1.getStyleFromHsl)(fillColorValue, opacity);
|
|
13
|
+
}
|
|
14
|
+
context.lineWidth = width;
|
|
15
|
+
const rotationRadian = (rotation * Math.PI) / 180;
|
|
16
|
+
context.beginPath();
|
|
17
|
+
context.ellipse(pos.x, pos.y, radius / 2, radius * 2, rotationRadian, start, end);
|
|
18
|
+
context.stroke();
|
|
19
|
+
}
|
|
20
|
+
class OrbitUpdater {
|
|
21
|
+
constructor(container) {
|
|
22
|
+
this.container = container;
|
|
23
|
+
}
|
|
24
|
+
afterDraw(particle) {
|
|
25
|
+
const orbitOptions = particle.options.orbit;
|
|
26
|
+
if (orbitOptions === null || orbitOptions === void 0 ? void 0 : orbitOptions.enable) {
|
|
27
|
+
this.drawOrbit(particle, "front");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
beforeDraw(particle) {
|
|
31
|
+
const orbitOptions = particle.options.orbit;
|
|
32
|
+
if (orbitOptions === null || orbitOptions === void 0 ? void 0 : orbitOptions.enable) {
|
|
33
|
+
this.drawOrbit(particle, "back");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
drawOrbit(particle, type) {
|
|
37
|
+
const container = this.container;
|
|
38
|
+
let start, end;
|
|
39
|
+
switch (type) {
|
|
40
|
+
case "back":
|
|
41
|
+
start = Math.PI / 2;
|
|
42
|
+
end = (Math.PI * 3) / 2;
|
|
43
|
+
break;
|
|
44
|
+
case "front":
|
|
45
|
+
start = (Math.PI * 3) / 2;
|
|
46
|
+
end = Math.PI / 2;
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
start = 0;
|
|
50
|
+
end = 2 * Math.PI;
|
|
51
|
+
}
|
|
52
|
+
container.canvas.draw((ctx) => {
|
|
53
|
+
var _a, _b, _c, _d, _e, _f;
|
|
54
|
+
drawEllipse(ctx, particle, (_a = particle.orbitColor) !== null && _a !== void 0 ? _a : particle.getFillColor(), (_c = (_b = particle.retina.orbitRadius) !== null && _b !== void 0 ? _b : container.retina.orbitRadius) !== null && _c !== void 0 ? _c : particle.getRadius(), (_d = particle.orbitOpacity) !== null && _d !== void 0 ? _d : 1, (_e = particle.orbitWidth) !== null && _e !== void 0 ? _e : 1, ((_f = particle.orbitRotation) !== null && _f !== void 0 ? _f : 0) * container.retina.pixelRatio, start, end);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
init(particle) {
|
|
58
|
+
const container = this.container, particlesOptions = particle.options, orbitOptions = particlesOptions.orbit;
|
|
59
|
+
if (!(orbitOptions === null || orbitOptions === void 0 ? void 0 : orbitOptions.enable)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
particle.orbitRotation = (0, engine_1.getRangeValue)(orbitOptions.rotation.value);
|
|
63
|
+
particle.orbitColor = (0, engine_1.rangeColorToHsl)(orbitOptions.color);
|
|
64
|
+
particle.retina.orbitRadius =
|
|
65
|
+
orbitOptions.radius !== undefined
|
|
66
|
+
? (0, engine_1.getRangeValue)(orbitOptions.radius) * container.retina.pixelRatio
|
|
67
|
+
: undefined;
|
|
68
|
+
container.retina.orbitRadius = particle.retina.orbitRadius;
|
|
69
|
+
particle.orbitAnimationSpeed = orbitOptions.animation.enable ? (0, engine_1.getRangeValue)(orbitOptions.animation.speed) : 0;
|
|
70
|
+
particle.orbitWidth = (0, engine_1.getRangeValue)(orbitOptions.width);
|
|
71
|
+
particle.orbitOpacity = (0, engine_1.getRangeValue)(orbitOptions.opacity);
|
|
72
|
+
}
|
|
73
|
+
isEnabled(particle) {
|
|
74
|
+
var _a;
|
|
75
|
+
const orbitAnimations = (_a = particle.options.orbit) === null || _a === void 0 ? void 0 : _a.animation;
|
|
76
|
+
return !particle.destroyed && !particle.spawning && !!(orbitAnimations === null || orbitAnimations === void 0 ? void 0 : orbitAnimations.enable);
|
|
77
|
+
}
|
|
78
|
+
loadOptions(options, ...sources) {
|
|
79
|
+
if (!options.orbit) {
|
|
80
|
+
options.orbit = new Orbit_1.Orbit();
|
|
81
|
+
}
|
|
82
|
+
for (const source of sources) {
|
|
83
|
+
options.orbit.load(source === null || source === void 0 ? void 0 : source.orbit);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
update(particle, delta) {
|
|
87
|
+
var _a;
|
|
88
|
+
if (!this.isEnabled(particle)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (particle.orbitRotation === undefined) {
|
|
92
|
+
particle.orbitRotation = 0;
|
|
93
|
+
}
|
|
94
|
+
particle.orbitRotation += ((_a = particle.orbitAnimationSpeed) !== null && _a !== void 0 ? _a : 0 / (Math.PI * 2)) * delta.factor;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.OrbitUpdater = OrbitUpdater;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadOrbitUpdater = void 0;
|
|
4
|
+
const OrbitUpdater_1 = require("./OrbitUpdater");
|
|
5
|
+
function loadOrbitUpdater(engine) {
|
|
6
|
+
engine.addParticleUpdater("orbit", (container) => new OrbitUpdater_1.OrbitUpdater(container));
|
|
7
|
+
}
|
|
8
|
+
exports.loadOrbitUpdater = loadOrbitUpdater;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AnimationOptions, OptionsColor, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { OrbitRotation } from "./OrbitRotation";
|
|
3
|
+
export class Orbit {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.animation = new AnimationOptions();
|
|
6
|
+
this.enable = false;
|
|
7
|
+
this.opacity = 1;
|
|
8
|
+
this.rotation = new OrbitRotation();
|
|
9
|
+
this.width = 1;
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.animation.load(data.animation);
|
|
16
|
+
this.rotation.load(data.rotation);
|
|
17
|
+
if (data.enable !== undefined) {
|
|
18
|
+
this.enable = data.enable;
|
|
19
|
+
}
|
|
20
|
+
if (data.opacity !== undefined) {
|
|
21
|
+
this.opacity = setRangeValue(data.opacity);
|
|
22
|
+
}
|
|
23
|
+
if (data.width !== undefined) {
|
|
24
|
+
this.width = setRangeValue(data.width);
|
|
25
|
+
}
|
|
26
|
+
if (data.radius !== undefined) {
|
|
27
|
+
this.radius = setRangeValue(data.radius);
|
|
28
|
+
}
|
|
29
|
+
if (data.color !== undefined) {
|
|
30
|
+
this.color = OptionsColor.create(this.color, data.color);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
2
|
+
export class OrbitRotation extends ValueWithRandom {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this.value = 45;
|
|
6
|
+
this.random.enable = false;
|
|
7
|
+
this.random.minimumValue = 0;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (data === undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
super.load(data);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { getRangeValue, getStyleFromHsl, rangeColorToHsl } from "@tsparticles/engine";
|
|
2
|
+
import { Orbit } from "./Options/Classes/Orbit";
|
|
3
|
+
function drawEllipse(context, particle, fillColorValue, radius, opacity, width, rotation, start, end) {
|
|
4
|
+
if (width <= 0) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const pos = particle.getPosition();
|
|
8
|
+
if (fillColorValue) {
|
|
9
|
+
context.strokeStyle = getStyleFromHsl(fillColorValue, opacity);
|
|
10
|
+
}
|
|
11
|
+
context.lineWidth = width;
|
|
12
|
+
const rotationRadian = (rotation * Math.PI) / 180;
|
|
13
|
+
context.beginPath();
|
|
14
|
+
context.ellipse(pos.x, pos.y, radius / 2, radius * 2, rotationRadian, start, end);
|
|
15
|
+
context.stroke();
|
|
16
|
+
}
|
|
17
|
+
export class OrbitUpdater {
|
|
18
|
+
constructor(container) {
|
|
19
|
+
this.container = container;
|
|
20
|
+
}
|
|
21
|
+
afterDraw(particle) {
|
|
22
|
+
const orbitOptions = particle.options.orbit;
|
|
23
|
+
if (orbitOptions === null || orbitOptions === void 0 ? void 0 : orbitOptions.enable) {
|
|
24
|
+
this.drawOrbit(particle, "front");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
beforeDraw(particle) {
|
|
28
|
+
const orbitOptions = particle.options.orbit;
|
|
29
|
+
if (orbitOptions === null || orbitOptions === void 0 ? void 0 : orbitOptions.enable) {
|
|
30
|
+
this.drawOrbit(particle, "back");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
drawOrbit(particle, type) {
|
|
34
|
+
const container = this.container;
|
|
35
|
+
let start, end;
|
|
36
|
+
switch (type) {
|
|
37
|
+
case "back":
|
|
38
|
+
start = Math.PI / 2;
|
|
39
|
+
end = (Math.PI * 3) / 2;
|
|
40
|
+
break;
|
|
41
|
+
case "front":
|
|
42
|
+
start = (Math.PI * 3) / 2;
|
|
43
|
+
end = Math.PI / 2;
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
start = 0;
|
|
47
|
+
end = 2 * Math.PI;
|
|
48
|
+
}
|
|
49
|
+
container.canvas.draw((ctx) => {
|
|
50
|
+
var _a, _b, _c, _d, _e, _f;
|
|
51
|
+
drawEllipse(ctx, particle, (_a = particle.orbitColor) !== null && _a !== void 0 ? _a : particle.getFillColor(), (_c = (_b = particle.retina.orbitRadius) !== null && _b !== void 0 ? _b : container.retina.orbitRadius) !== null && _c !== void 0 ? _c : particle.getRadius(), (_d = particle.orbitOpacity) !== null && _d !== void 0 ? _d : 1, (_e = particle.orbitWidth) !== null && _e !== void 0 ? _e : 1, ((_f = particle.orbitRotation) !== null && _f !== void 0 ? _f : 0) * container.retina.pixelRatio, start, end);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
init(particle) {
|
|
55
|
+
const container = this.container, particlesOptions = particle.options, orbitOptions = particlesOptions.orbit;
|
|
56
|
+
if (!(orbitOptions === null || orbitOptions === void 0 ? void 0 : orbitOptions.enable)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
particle.orbitRotation = getRangeValue(orbitOptions.rotation.value);
|
|
60
|
+
particle.orbitColor = rangeColorToHsl(orbitOptions.color);
|
|
61
|
+
particle.retina.orbitRadius =
|
|
62
|
+
orbitOptions.radius !== undefined
|
|
63
|
+
? getRangeValue(orbitOptions.radius) * container.retina.pixelRatio
|
|
64
|
+
: undefined;
|
|
65
|
+
container.retina.orbitRadius = particle.retina.orbitRadius;
|
|
66
|
+
particle.orbitAnimationSpeed = orbitOptions.animation.enable ? getRangeValue(orbitOptions.animation.speed) : 0;
|
|
67
|
+
particle.orbitWidth = getRangeValue(orbitOptions.width);
|
|
68
|
+
particle.orbitOpacity = getRangeValue(orbitOptions.opacity);
|
|
69
|
+
}
|
|
70
|
+
isEnabled(particle) {
|
|
71
|
+
var _a;
|
|
72
|
+
const orbitAnimations = (_a = particle.options.orbit) === null || _a === void 0 ? void 0 : _a.animation;
|
|
73
|
+
return !particle.destroyed && !particle.spawning && !!(orbitAnimations === null || orbitAnimations === void 0 ? void 0 : orbitAnimations.enable);
|
|
74
|
+
}
|
|
75
|
+
loadOptions(options, ...sources) {
|
|
76
|
+
if (!options.orbit) {
|
|
77
|
+
options.orbit = new Orbit();
|
|
78
|
+
}
|
|
79
|
+
for (const source of sources) {
|
|
80
|
+
options.orbit.load(source === null || source === void 0 ? void 0 : source.orbit);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
update(particle, delta) {
|
|
84
|
+
var _a;
|
|
85
|
+
if (!this.isEnabled(particle)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (particle.orbitRotation === undefined) {
|
|
89
|
+
particle.orbitRotation = 0;
|
|
90
|
+
}
|
|
91
|
+
particle.orbitRotation += ((_a = particle.orbitAnimationSpeed) !== null && _a !== void 0 ? _a : 0 / (Math.PI * 2)) * delta.factor;
|
|
92
|
+
}
|
|
93
|
+
}
|
package/esm/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsparticles/updater-orbit",
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
|
+
"description": "tsParticles particles orbit updater",
|
|
5
|
+
"homepage": "https://particles.js.org",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/matteobruni/tsparticles.git",
|
|
9
|
+
"directory": "updaters/orbit"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"front-end",
|
|
13
|
+
"frontend",
|
|
14
|
+
"tsparticles",
|
|
15
|
+
"particles.js",
|
|
16
|
+
"particlesjs",
|
|
17
|
+
"particles",
|
|
18
|
+
"particle",
|
|
19
|
+
"canvas",
|
|
20
|
+
"jsparticles",
|
|
21
|
+
"xparticles",
|
|
22
|
+
"particles-js",
|
|
23
|
+
"particles-bg",
|
|
24
|
+
"particles-bg-vue",
|
|
25
|
+
"particles-ts",
|
|
26
|
+
"particles.ts",
|
|
27
|
+
"react-particles-js",
|
|
28
|
+
"react-particles.js",
|
|
29
|
+
"react-particles",
|
|
30
|
+
"react",
|
|
31
|
+
"reactjs",
|
|
32
|
+
"vue-particles",
|
|
33
|
+
"ngx-particles",
|
|
34
|
+
"angular-particles",
|
|
35
|
+
"particleground",
|
|
36
|
+
"vue",
|
|
37
|
+
"vuejs",
|
|
38
|
+
"preact",
|
|
39
|
+
"preactjs",
|
|
40
|
+
"jquery",
|
|
41
|
+
"angularjs",
|
|
42
|
+
"angular",
|
|
43
|
+
"typescript",
|
|
44
|
+
"javascript",
|
|
45
|
+
"animation",
|
|
46
|
+
"web",
|
|
47
|
+
"html5",
|
|
48
|
+
"web-design",
|
|
49
|
+
"webdesign",
|
|
50
|
+
"css",
|
|
51
|
+
"html",
|
|
52
|
+
"css3",
|
|
53
|
+
"animated",
|
|
54
|
+
"background",
|
|
55
|
+
"confetti",
|
|
56
|
+
"canvas",
|
|
57
|
+
"fireworks",
|
|
58
|
+
"fireworks-js",
|
|
59
|
+
"confetti-js",
|
|
60
|
+
"confettijs",
|
|
61
|
+
"fireworksjs",
|
|
62
|
+
"canvas-confetti",
|
|
63
|
+
"@tsparticles/plugin",
|
|
64
|
+
"@tsparticles/updater"
|
|
65
|
+
],
|
|
66
|
+
"author": "Matteo Bruni <matteo.bruni@me.com>",
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/matteobruni/tsparticles/issues"
|
|
70
|
+
},
|
|
71
|
+
"funding": [
|
|
72
|
+
{
|
|
73
|
+
"type": "github",
|
|
74
|
+
"url": "https://github.com/sponsors/matteobruni"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"type": "buymeacoffee",
|
|
78
|
+
"url": "https://www.buymeacoffee.com/matteobruni"
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
"main": "cjs/index.js",
|
|
82
|
+
"jsdelivr": "tsparticles.updater.orbit.min.js",
|
|
83
|
+
"unpkg": "tsparticles.updater.orbit.min.js",
|
|
84
|
+
"module": "esm/index.js",
|
|
85
|
+
"types": "types/index.d.ts",
|
|
86
|
+
"publishConfig": {
|
|
87
|
+
"access": "public"
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"@tsparticles/engine": "^3.0.0-alpha.0"
|
|
91
|
+
}
|
|
92
|
+
}
|