@tsparticles/path-curves 4.0.0-alpha.1 → 4.0.0-alpha.14

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/406.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_path_curves=this.webpackChunk_tsparticles_path_curves||[]).push([[406],{406(t,e,n){n.d(e,{CurvesPathGenerator:()=>s});var i=n(303);let o={rndFunc:null,period:100,nbHarmonics:2,attenHarmonics:.8,lowValue:-.03,highValue:.03};class s{options;_container;constructor(t){this._container=t,this.options=(0,i.deepExtend)({},o)}generate(t){if(!t.pathGen){let{options:e}=this;t.pathGen=function(t,e,n,o,s=0,r=1){let c=[],a=[],l=[],u=[],h=[],p=t??i.getRandom,d=0;n<1&&(n=1);for(let t=1;t<=n;++t)c[t]=p(),a[t]=p(),l[t]=1===t?1:l[t-1]*o,d+=l[t],u[t]=t/e,h[t]=p();return l.forEach((t,e)=>l[e]=t/d*(r-s)),()=>{let t,e,i=0;for(let o=n;o>=1;--o)t=h[o]+=u[o],h[o]>=1&&(t=h[o]-=1,c[o]=a[o],a[o]=p()),e=t**2*(3-2*t),i+=(c[o]*(1-e)+a[o]*e)*l[o];return i+s}}(e.rndFunc,e.period,e.nbHarmonics,e.attenHarmonics,e.lowValue,e.highValue)}return t.curveVelocity?(t.curveVelocity.length+=.01,t.curveVelocity.angle=(t.curveVelocity.angle+t.pathGen())%i.doublePI):(t.curveVelocity=i.Vector.origin,t.curveVelocity.length=.6*(0,i.getRandom)()+.8,t.curveVelocity.angle=(0,i.getRandom)()*i.doublePI),t.velocity.x=0,t.velocity.y=0,t.curveVelocity}init(){let t=this._container.actualOptions.particles.move.path.options;(0,i.isFunction)(t.rndFunc)?this.options.rndFunc=t.rndFunc:(0,i.isString)(t.rndFunc)&&(this.options.rndFunc=globalThis[t.rndFunc]??this.options.rndFunc),this.options.period=t.period??this.options.period,this.options.nbHarmonics=t.nbHarmonics??this.options.nbHarmonics,this.options.attenHarmonics=t.attenHarmonics??this.options.attenHarmonics,this.options.lowValue=t.lowValue??this.options.lowValue,this.options.highValue=t.highValue??this.options.highValue}reset(t){delete t.pathGen,delete t.curveVelocity}update(){}}}}]);
@@ -1,52 +1,58 @@
1
- import { Vector, doublePI, getRandom, isFunction, isString, } from "@tsparticles/engine";
1
+ import { Vector, deepExtend, doublePI, getRandom, isFunction, isString, } from "@tsparticles/engine";
2
2
  import { CurvesPathGen } from "./Curves.js";
3
+ const defaultOptions = {
4
+ rndFunc: null,
5
+ period: 100,
6
+ nbHarmonics: 2,
7
+ attenHarmonics: 0.8,
8
+ lowValue: -0.03,
9
+ highValue: 0.03,
10
+ };
3
11
  function randomVelocity() {
4
12
  const offset = 0.8, factor = 0.6;
5
13
  return getRandom() * factor + offset;
6
14
  }
7
15
  export class CurvesPathGenerator {
8
- constructor() {
9
- this.options = {
10
- rndFunc: null,
11
- period: 100,
12
- nbHarmonics: 2,
13
- attenHarmonics: 0.8,
14
- lowValue: -0.03,
15
- highValue: 0.03,
16
- };
16
+ options;
17
+ _container;
18
+ constructor(container) {
19
+ this._container = container;
20
+ this.options = deepExtend({}, defaultOptions);
17
21
  }
18
- generate(p) {
19
- if (!p.pathGen) {
20
- const options = this.options;
21
- p.pathGen = CurvesPathGen(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
22
+ generate(particle) {
23
+ if (!particle.pathGen) {
24
+ const { options } = this;
25
+ particle.pathGen = CurvesPathGen(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
22
26
  }
23
- if (!p.curveVelocity) {
24
- p.curveVelocity = Vector.origin;
25
- p.curveVelocity.length = randomVelocity();
26
- p.curveVelocity.angle = getRandom() * doublePI;
27
+ if (particle.curveVelocity) {
28
+ particle.curveVelocity.length += 0.01;
29
+ particle.curveVelocity.angle = (particle.curveVelocity.angle + particle.pathGen()) % doublePI;
27
30
  }
28
31
  else {
29
- p.curveVelocity.length += 0.01;
30
- p.curveVelocity.angle = (p.curveVelocity.angle + p.pathGen()) % doublePI;
32
+ particle.curveVelocity = Vector.origin;
33
+ particle.curveVelocity.length = randomVelocity();
34
+ particle.curveVelocity.angle = getRandom() * doublePI;
31
35
  }
32
- p.velocity.x = 0;
33
- p.velocity.y = 0;
34
- return p.curveVelocity;
36
+ particle.velocity.x = 0;
37
+ particle.velocity.y = 0;
38
+ return particle.curveVelocity;
35
39
  }
36
- init(container) {
37
- const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
40
+ init() {
41
+ const sourceOptions = this._container.actualOptions.particles.move.path.options;
38
42
  if (isFunction(sourceOptions["rndFunc"])) {
39
- options.rndFunc = sourceOptions["rndFunc"];
43
+ this.options.rndFunc = sourceOptions["rndFunc"];
40
44
  }
41
45
  else if (isString(sourceOptions["rndFunc"])) {
42
- options.rndFunc =
43
- globalThis[sourceOptions["rndFunc"]] ?? this.options.rndFunc;
46
+ this.options.rndFunc =
47
+ globalThis[sourceOptions["rndFunc"]] ??
48
+ this.options.rndFunc;
44
49
  }
45
- options.period = sourceOptions["period"] ?? options.period;
46
- options.nbHarmonics = sourceOptions["nbHarmonics"] ?? options.nbHarmonics;
47
- options.attenHarmonics = sourceOptions["attenHarmonics"] ?? options.attenHarmonics;
48
- options.lowValue = sourceOptions["lowValue"] ?? options.lowValue;
49
- options.highValue = sourceOptions["highValue"] ?? options.highValue;
50
+ this.options.period = sourceOptions["period"] ?? this.options.period;
51
+ this.options.nbHarmonics = sourceOptions["nbHarmonics"] ?? this.options.nbHarmonics;
52
+ this.options.attenHarmonics =
53
+ sourceOptions["attenHarmonics"] ?? this.options.attenHarmonics;
54
+ this.options.lowValue = sourceOptions["lowValue"] ?? this.options.lowValue;
55
+ this.options.highValue = sourceOptions["highValue"] ?? this.options.highValue;
50
56
  }
51
57
  reset(particle) {
52
58
  delete particle.pathGen;
package/browser/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export const curvesPathName = "curvesPathGenerator";
2
- export function loadCurvesPath(engine) {
3
- engine.checkVersion("4.0.0-alpha.1");
4
- engine.register(async (e) => {
5
- const { CurvesPathGenerator } = await import("./CurvesPathGenerator.js");
6
- e.addPathGenerator(curvesPathName, new CurvesPathGenerator());
2
+ export async function loadCurvesPath(engine) {
3
+ engine.checkVersion("4.0.0-alpha.14");
4
+ await engine.register(e => {
5
+ e.addPathGenerator(curvesPathName, async (container) => {
6
+ const { CurvesPathGenerator } = await import("./CurvesPathGenerator.js");
7
+ return new CurvesPathGenerator(container);
8
+ });
7
9
  });
8
10
  }
@@ -1,52 +1,58 @@
1
- import { Vector, doublePI, getRandom, isFunction, isString, } from "@tsparticles/engine";
1
+ import { Vector, deepExtend, doublePI, getRandom, isFunction, isString, } from "@tsparticles/engine";
2
2
  import { CurvesPathGen } from "./Curves.js";
3
+ const defaultOptions = {
4
+ rndFunc: null,
5
+ period: 100,
6
+ nbHarmonics: 2,
7
+ attenHarmonics: 0.8,
8
+ lowValue: -0.03,
9
+ highValue: 0.03,
10
+ };
3
11
  function randomVelocity() {
4
12
  const offset = 0.8, factor = 0.6;
5
13
  return getRandom() * factor + offset;
6
14
  }
7
15
  export class CurvesPathGenerator {
8
- constructor() {
9
- this.options = {
10
- rndFunc: null,
11
- period: 100,
12
- nbHarmonics: 2,
13
- attenHarmonics: 0.8,
14
- lowValue: -0.03,
15
- highValue: 0.03,
16
- };
16
+ options;
17
+ _container;
18
+ constructor(container) {
19
+ this._container = container;
20
+ this.options = deepExtend({}, defaultOptions);
17
21
  }
18
- generate(p) {
19
- if (!p.pathGen) {
20
- const options = this.options;
21
- p.pathGen = CurvesPathGen(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
22
+ generate(particle) {
23
+ if (!particle.pathGen) {
24
+ const { options } = this;
25
+ particle.pathGen = CurvesPathGen(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
22
26
  }
23
- if (!p.curveVelocity) {
24
- p.curveVelocity = Vector.origin;
25
- p.curveVelocity.length = randomVelocity();
26
- p.curveVelocity.angle = getRandom() * doublePI;
27
+ if (particle.curveVelocity) {
28
+ particle.curveVelocity.length += 0.01;
29
+ particle.curveVelocity.angle = (particle.curveVelocity.angle + particle.pathGen()) % doublePI;
27
30
  }
28
31
  else {
29
- p.curveVelocity.length += 0.01;
30
- p.curveVelocity.angle = (p.curveVelocity.angle + p.pathGen()) % doublePI;
32
+ particle.curveVelocity = Vector.origin;
33
+ particle.curveVelocity.length = randomVelocity();
34
+ particle.curveVelocity.angle = getRandom() * doublePI;
31
35
  }
32
- p.velocity.x = 0;
33
- p.velocity.y = 0;
34
- return p.curveVelocity;
36
+ particle.velocity.x = 0;
37
+ particle.velocity.y = 0;
38
+ return particle.curveVelocity;
35
39
  }
36
- init(container) {
37
- const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
40
+ init() {
41
+ const sourceOptions = this._container.actualOptions.particles.move.path.options;
38
42
  if (isFunction(sourceOptions["rndFunc"])) {
39
- options.rndFunc = sourceOptions["rndFunc"];
43
+ this.options.rndFunc = sourceOptions["rndFunc"];
40
44
  }
41
45
  else if (isString(sourceOptions["rndFunc"])) {
42
- options.rndFunc =
43
- globalThis[sourceOptions["rndFunc"]] ?? this.options.rndFunc;
46
+ this.options.rndFunc =
47
+ globalThis[sourceOptions["rndFunc"]] ??
48
+ this.options.rndFunc;
44
49
  }
45
- options.period = sourceOptions["period"] ?? options.period;
46
- options.nbHarmonics = sourceOptions["nbHarmonics"] ?? options.nbHarmonics;
47
- options.attenHarmonics = sourceOptions["attenHarmonics"] ?? options.attenHarmonics;
48
- options.lowValue = sourceOptions["lowValue"] ?? options.lowValue;
49
- options.highValue = sourceOptions["highValue"] ?? options.highValue;
50
+ this.options.period = sourceOptions["period"] ?? this.options.period;
51
+ this.options.nbHarmonics = sourceOptions["nbHarmonics"] ?? this.options.nbHarmonics;
52
+ this.options.attenHarmonics =
53
+ sourceOptions["attenHarmonics"] ?? this.options.attenHarmonics;
54
+ this.options.lowValue = sourceOptions["lowValue"] ?? this.options.lowValue;
55
+ this.options.highValue = sourceOptions["highValue"] ?? this.options.highValue;
50
56
  }
51
57
  reset(particle) {
52
58
  delete particle.pathGen;
package/cjs/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export const curvesPathName = "curvesPathGenerator";
2
- export function loadCurvesPath(engine) {
3
- engine.checkVersion("4.0.0-alpha.1");
4
- engine.register(async (e) => {
5
- const { CurvesPathGenerator } = await import("./CurvesPathGenerator.js");
6
- e.addPathGenerator(curvesPathName, new CurvesPathGenerator());
2
+ export async function loadCurvesPath(engine) {
3
+ engine.checkVersion("4.0.0-alpha.14");
4
+ await engine.register(e => {
5
+ e.addPathGenerator(curvesPathName, async (container) => {
6
+ const { CurvesPathGenerator } = await import("./CurvesPathGenerator.js");
7
+ return new CurvesPathGenerator(container);
8
+ });
7
9
  });
8
10
  }
@@ -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
- * v4.0.0-alpha.1
7
+ * v4.0.0-alpha.14
8
8
  */
9
9
  "use strict";
10
10
  /*
@@ -23,7 +23,7 @@
23
23
  \********************************/
24
24
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
25
25
 
26
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ CurvesPathGen: () => (/* binding */ CurvesPathGen)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nfunction CurvesPathGen(rndFunc, period, nbHarmonics, attenHarmonics, lowValue = 0, highValue = 1) {\n const arP0 = [],\n arP1 = [],\n amplitudes = [],\n increments = [],\n phases = [],\n randomFunc = rndFunc ?? _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom;\n let globAmplitude = 0;\n if (nbHarmonics < 1) nbHarmonics = 1;\n for (let kh = 1; kh <= nbHarmonics; ++kh) {\n arP0[kh] = randomFunc();\n arP1[kh] = randomFunc();\n amplitudes[kh] = kh === 1 ? 1 : amplitudes[kh - 1] * attenHarmonics;\n globAmplitude += amplitudes[kh];\n increments[kh] = kh / period;\n phases[kh] = randomFunc();\n }\n amplitudes.forEach((value, kh) => amplitudes[kh] = value / globAmplitude * (highValue - lowValue));\n return () => {\n let pf,\n pfl,\n signal = 0;\n for (let kh = nbHarmonics; kh >= 1; --kh) {\n pf = phases[kh] += increments[kh];\n if (phases[kh] >= 1) {\n pf = phases[kh] -= 1;\n arP0[kh] = arP1[kh];\n arP1[kh] = randomFunc();\n }\n pfl = pf ** 2 * (3 - 2 * pf);\n signal += (arP0[kh] * (1 - pfl) + arP1[kh] * pfl) * amplitudes[kh];\n }\n return signal + lowValue;\n };\n}\n\n//# sourceURL=webpack://@tsparticles/path-curves/./dist/browser/Curves.js?\n}");
26
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ CurvesPathGen: () => (/* binding */ CurvesPathGen)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nfunction CurvesPathGen(rndFunc, period, nbHarmonics, attenHarmonics, lowValue = 0, highValue = 1) {\n const arP0 = [], arP1 = [], amplitudes = [], increments = [], phases = [], randomFunc = rndFunc ?? _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom;\n let globAmplitude = 0;\n if (nbHarmonics < 1) nbHarmonics = 1;\n for(let kh = 1; kh <= nbHarmonics; ++kh){\n arP0[kh] = randomFunc();\n arP1[kh] = randomFunc();\n amplitudes[kh] = kh === 1 ? 1 : amplitudes[kh - 1] * attenHarmonics;\n globAmplitude += amplitudes[kh];\n increments[kh] = kh / period;\n phases[kh] = randomFunc();\n }\n amplitudes.forEach((value, kh)=>amplitudes[kh] = value / globAmplitude * (highValue - lowValue));\n return ()=>{\n let pf, pfl, signal = 0;\n for(let kh = nbHarmonics; kh >= 1; --kh){\n pf = phases[kh] += increments[kh];\n if (phases[kh] >= 1) {\n pf = phases[kh] -= 1;\n arP0[kh] = arP1[kh];\n arP1[kh] = randomFunc();\n }\n pfl = pf ** 2 * (3 - 2 * pf);\n signal += (arP0[kh] * (1 - pfl) + arP1[kh] * pfl) * amplitudes[kh];\n }\n return signal + lowValue;\n };\n}\n\n\n//# sourceURL=webpack://@tsparticles/path-curves/./dist/browser/Curves.js?\n}");
27
27
 
28
28
  /***/ },
29
29
 
@@ -33,7 +33,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
33
33
  \*********************************************/
34
34
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
35
35
 
36
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ CurvesPathGenerator: () => (/* binding */ CurvesPathGenerator)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Curves_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Curves.js */ \"./dist/browser/Curves.js\");\n\n\nfunction randomVelocity() {\n const offset = 0.8,\n factor = 0.6;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * factor + offset;\n}\nclass CurvesPathGenerator {\n constructor() {\n this.options = {\n rndFunc: null,\n period: 100,\n nbHarmonics: 2,\n attenHarmonics: 0.8,\n lowValue: -0.03,\n highValue: 0.03\n };\n }\n generate(p) {\n if (!p.pathGen) {\n const options = this.options;\n p.pathGen = (0,_Curves_js__WEBPACK_IMPORTED_MODULE_1__.CurvesPathGen)(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);\n }\n if (!p.curveVelocity) {\n p.curveVelocity = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin;\n p.curveVelocity.length = randomVelocity();\n p.curveVelocity.angle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.doublePI;\n } else {\n p.curveVelocity.length += 0.01;\n p.curveVelocity.angle = (p.curveVelocity.angle + p.pathGen()) % _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.doublePI;\n }\n p.velocity.x = 0;\n p.velocity.y = 0;\n return p.curveVelocity;\n }\n init(container) {\n const sourceOptions = container.actualOptions.particles.move.path.options,\n {\n options\n } = this;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isFunction)(sourceOptions[\"rndFunc\"])) {\n options.rndFunc = sourceOptions[\"rndFunc\"];\n } else if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isString)(sourceOptions[\"rndFunc\"])) {\n options.rndFunc = globalThis[sourceOptions[\"rndFunc\"]] ?? this.options.rndFunc;\n }\n options.period = sourceOptions[\"period\"] ?? options.period;\n options.nbHarmonics = sourceOptions[\"nbHarmonics\"] ?? options.nbHarmonics;\n options.attenHarmonics = sourceOptions[\"attenHarmonics\"] ?? options.attenHarmonics;\n options.lowValue = sourceOptions[\"lowValue\"] ?? options.lowValue;\n options.highValue = sourceOptions[\"highValue\"] ?? options.highValue;\n }\n reset(particle) {\n delete particle.pathGen;\n delete particle.curveVelocity;\n }\n update() {}\n}\n\n//# sourceURL=webpack://@tsparticles/path-curves/./dist/browser/CurvesPathGenerator.js?\n}");
36
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ CurvesPathGenerator: () => (/* binding */ CurvesPathGenerator)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Curves_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Curves.js */ \"./dist/browser/Curves.js\");\n\n\nconst defaultOptions = {\n rndFunc: null,\n period: 100,\n nbHarmonics: 2,\n attenHarmonics: 0.8,\n lowValue: -0.03,\n highValue: 0.03\n};\nfunction randomVelocity() {\n const offset = 0.8, factor = 0.6;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * factor + offset;\n}\nclass CurvesPathGenerator {\n options;\n _container;\n constructor(container){\n this._container = container;\n this.options = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, defaultOptions);\n }\n generate(particle) {\n if (!particle.pathGen) {\n const { options } = this;\n particle.pathGen = (0,_Curves_js__WEBPACK_IMPORTED_MODULE_1__.CurvesPathGen)(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);\n }\n if (particle.curveVelocity) {\n particle.curveVelocity.length += 0.01;\n particle.curveVelocity.angle = (particle.curveVelocity.angle + particle.pathGen()) % _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.doublePI;\n } else {\n particle.curveVelocity = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin;\n particle.curveVelocity.length = randomVelocity();\n particle.curveVelocity.angle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.doublePI;\n }\n particle.velocity.x = 0;\n particle.velocity.y = 0;\n return particle.curveVelocity;\n }\n init() {\n const sourceOptions = this._container.actualOptions.particles.move.path.options;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isFunction)(sourceOptions[\"rndFunc\"])) {\n this.options.rndFunc = sourceOptions[\"rndFunc\"];\n } else if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isString)(sourceOptions[\"rndFunc\"])) {\n this.options.rndFunc = globalThis[sourceOptions[\"rndFunc\"]] ?? this.options.rndFunc;\n }\n this.options.period = sourceOptions[\"period\"] ?? this.options.period;\n this.options.nbHarmonics = sourceOptions[\"nbHarmonics\"] ?? this.options.nbHarmonics;\n this.options.attenHarmonics = sourceOptions[\"attenHarmonics\"] ?? this.options.attenHarmonics;\n this.options.lowValue = sourceOptions[\"lowValue\"] ?? this.options.lowValue;\n this.options.highValue = sourceOptions[\"highValue\"] ?? this.options.highValue;\n }\n reset(particle) {\n delete particle.pathGen;\n delete particle.curveVelocity;\n }\n update() {}\n}\n\n\n//# sourceURL=webpack://@tsparticles/path-curves/./dist/browser/CurvesPathGenerator.js?\n}");
37
37
 
38
38
  /***/ }
39
39
 
@@ -1,52 +1,58 @@
1
- import { Vector, doublePI, getRandom, isFunction, isString, } from "@tsparticles/engine";
1
+ import { Vector, deepExtend, doublePI, getRandom, isFunction, isString, } from "@tsparticles/engine";
2
2
  import { CurvesPathGen } from "./Curves.js";
3
+ const defaultOptions = {
4
+ rndFunc: null,
5
+ period: 100,
6
+ nbHarmonics: 2,
7
+ attenHarmonics: 0.8,
8
+ lowValue: -0.03,
9
+ highValue: 0.03,
10
+ };
3
11
  function randomVelocity() {
4
12
  const offset = 0.8, factor = 0.6;
5
13
  return getRandom() * factor + offset;
6
14
  }
7
15
  export class CurvesPathGenerator {
8
- constructor() {
9
- this.options = {
10
- rndFunc: null,
11
- period: 100,
12
- nbHarmonics: 2,
13
- attenHarmonics: 0.8,
14
- lowValue: -0.03,
15
- highValue: 0.03,
16
- };
16
+ options;
17
+ _container;
18
+ constructor(container) {
19
+ this._container = container;
20
+ this.options = deepExtend({}, defaultOptions);
17
21
  }
18
- generate(p) {
19
- if (!p.pathGen) {
20
- const options = this.options;
21
- p.pathGen = CurvesPathGen(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
22
+ generate(particle) {
23
+ if (!particle.pathGen) {
24
+ const { options } = this;
25
+ particle.pathGen = CurvesPathGen(options.rndFunc, options.period, options.nbHarmonics, options.attenHarmonics, options.lowValue, options.highValue);
22
26
  }
23
- if (!p.curveVelocity) {
24
- p.curveVelocity = Vector.origin;
25
- p.curveVelocity.length = randomVelocity();
26
- p.curveVelocity.angle = getRandom() * doublePI;
27
+ if (particle.curveVelocity) {
28
+ particle.curveVelocity.length += 0.01;
29
+ particle.curveVelocity.angle = (particle.curveVelocity.angle + particle.pathGen()) % doublePI;
27
30
  }
28
31
  else {
29
- p.curveVelocity.length += 0.01;
30
- p.curveVelocity.angle = (p.curveVelocity.angle + p.pathGen()) % doublePI;
32
+ particle.curveVelocity = Vector.origin;
33
+ particle.curveVelocity.length = randomVelocity();
34
+ particle.curveVelocity.angle = getRandom() * doublePI;
31
35
  }
32
- p.velocity.x = 0;
33
- p.velocity.y = 0;
34
- return p.curveVelocity;
36
+ particle.velocity.x = 0;
37
+ particle.velocity.y = 0;
38
+ return particle.curveVelocity;
35
39
  }
36
- init(container) {
37
- const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
40
+ init() {
41
+ const sourceOptions = this._container.actualOptions.particles.move.path.options;
38
42
  if (isFunction(sourceOptions["rndFunc"])) {
39
- options.rndFunc = sourceOptions["rndFunc"];
43
+ this.options.rndFunc = sourceOptions["rndFunc"];
40
44
  }
41
45
  else if (isString(sourceOptions["rndFunc"])) {
42
- options.rndFunc =
43
- globalThis[sourceOptions["rndFunc"]] ?? this.options.rndFunc;
46
+ this.options.rndFunc =
47
+ globalThis[sourceOptions["rndFunc"]] ??
48
+ this.options.rndFunc;
44
49
  }
45
- options.period = sourceOptions["period"] ?? options.period;
46
- options.nbHarmonics = sourceOptions["nbHarmonics"] ?? options.nbHarmonics;
47
- options.attenHarmonics = sourceOptions["attenHarmonics"] ?? options.attenHarmonics;
48
- options.lowValue = sourceOptions["lowValue"] ?? options.lowValue;
49
- options.highValue = sourceOptions["highValue"] ?? options.highValue;
50
+ this.options.period = sourceOptions["period"] ?? this.options.period;
51
+ this.options.nbHarmonics = sourceOptions["nbHarmonics"] ?? this.options.nbHarmonics;
52
+ this.options.attenHarmonics =
53
+ sourceOptions["attenHarmonics"] ?? this.options.attenHarmonics;
54
+ this.options.lowValue = sourceOptions["lowValue"] ?? this.options.lowValue;
55
+ this.options.highValue = sourceOptions["highValue"] ?? this.options.highValue;
50
56
  }
51
57
  reset(particle) {
52
58
  delete particle.pathGen;
package/esm/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export const curvesPathName = "curvesPathGenerator";
2
- export function loadCurvesPath(engine) {
3
- engine.checkVersion("4.0.0-alpha.1");
4
- engine.register(async (e) => {
5
- const { CurvesPathGenerator } = await import("./CurvesPathGenerator.js");
6
- e.addPathGenerator(curvesPathName, new CurvesPathGenerator());
2
+ export async function loadCurvesPath(engine) {
3
+ engine.checkVersion("4.0.0-alpha.14");
4
+ await engine.register(e => {
5
+ e.addPathGenerator(curvesPathName, async (container) => {
6
+ const { CurvesPathGenerator } = await import("./CurvesPathGenerator.js");
7
+ return new CurvesPathGenerator(container);
8
+ });
7
9
  });
8
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/path-curves",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.14",
4
4
  "description": "tsParticles curves path",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -104,7 +104,7 @@
104
104
  "./package.json": "./package.json"
105
105
  },
106
106
  "dependencies": {
107
- "@tsparticles/engine": "4.0.0-alpha.1"
107
+ "@tsparticles/engine": "4.0.0-alpha.14"
108
108
  },
109
109
  "type": "module"
110
110
  }