@tsparticles/interaction-particles-repulse 4.0.0-alpha.5 → 4.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/794.min.js +1 -0
- package/README.md +5 -0
- package/browser/Options/Classes/ParticlesRepulse.js +5 -0
- package/browser/Repulser.js +24 -7
- package/browser/index.js +3 -3
- package/cjs/Options/Classes/ParticlesRepulse.js +5 -0
- package/cjs/Repulser.js +24 -7
- package/cjs/index.js +3 -3
- package/dist_browser_Repulser_js.js +3 -3
- package/esm/Options/Classes/ParticlesRepulse.js +5 -0
- package/esm/Repulser.js +24 -7
- package/esm/index.js +3 -3
- package/package.json +3 -3
- package/report.html +3 -3
- package/tsparticles.interaction.particles.repulse.js +31 -19
- package/tsparticles.interaction.particles.repulse.min.js +2 -2
- package/types/Repulser.d.ts +4 -0
- package/umd/Options/Classes/ParticlesRepulse.js +5 -0
- package/umd/Repulser.js +24 -7
- package/umd/index.js +3 -3
- package/753.min.js +0 -2
- package/753.min.js.LICENSE.txt +0 -1
- package/tsparticles.interaction.particles.repulse.min.js.LICENSE.txt +0 -1
package/794.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_interaction_particles_repulse=this.webpackChunk_tsparticles_interaction_particles_repulse||[]).push([[794],{794(e,t,s){s.d(t,{Repulser:()=>n});var i=s(702),a=s(303);class r extends a.ValueWithRandom{distance;duration;enabled;factor;speed;constructor(){super(),this.enabled=!1,this.distance=1,this.duration=1,this.factor=1,this.speed=1}load(e){super.load(e),(0,a.isNull)(e)||(void 0!==e.enabled&&(this.enabled=e.enabled),void 0!==e.distance&&(this.distance=(0,a.setRangeValue)(e.distance)),void 0!==e.duration&&(this.duration=(0,a.setRangeValue)(e.duration)),void 0!==e.factor&&(this.factor=(0,a.setRangeValue)(e.factor)),void 0!==e.speed&&(this.speed=(0,a.setRangeValue)(e.speed)))}}class n extends i.ParticlesInteractorBase{_maxDistance;_normVec;_velocityVec;constructor(e){super(e),this._maxDistance=0,this._normVec=a.Vector.origin,this._velocityVec=a.Vector.origin}get maxDistance(){return this._maxDistance}clear(){}init(){}interact(e){let t=this.container;if(!e.repulse){let s=e.options.repulse;if(!s)return;let i=(0,a.getRangeValue)(s.distance);i>this.maxDistance&&(this._maxDistance=i),e.repulse={distance:i*t.retina.pixelRatio,speed:(0,a.getRangeValue)(s.speed),factor:(0,a.getRangeValue)(s.factor)}}let s=e.getPosition(),i=t.particles.grid.queryCircle(s,e.repulse.distance),r=1/e.repulse.distance;for(let t of i){if(e===t||t.destroyed)continue;let i=t.getPosition(),{dx:n,dy:o,distance:c}=(0,a.getDistances)(i,s),l=1/c,d=e.repulse.speed*e.repulse.factor;if(c>0){let e=(0,a.clamp)((1-Math.pow(c*r,2))*d,0,d)*l;this._normVec.x=n*e,this._normVec.y=o*e,t.position.addTo(this._normVec)}else this._velocityVec.x=d,this._velocityVec.y=d,t.position.addTo(this._velocityVec)}}isEnabled(e){return e.options.repulse?.enabled??!1}loadParticlesOptions(e,...t){for(let s of(e.repulse??=new r,t))e.repulse.load(s?.repulse)}reset(){}}}}]);
|
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ Once the scripts are loaded you can set up `tsParticles` and the interaction plu
|
|
|
27
27
|
|
|
28
28
|
```javascript
|
|
29
29
|
(async () => {
|
|
30
|
+
await loadInteractivityPlugin(tsParticles);
|
|
30
31
|
await loadParticlesRepulseInteraction(tsParticles);
|
|
31
32
|
|
|
32
33
|
await tsParticles.load({
|
|
@@ -56,9 +57,11 @@ Then you need to import it in the app, like this:
|
|
|
56
57
|
|
|
57
58
|
```javascript
|
|
58
59
|
const { tsParticles } = require("@tsparticles/engine");
|
|
60
|
+
const { loadInteractivityPlugin } = require("@tsparticles/plugin-interactivity");
|
|
59
61
|
const { loadParticlesRepulseInteraction } = require("@tsparticles/interaction-particles-repulse");
|
|
60
62
|
|
|
61
63
|
(async () => {
|
|
64
|
+
await loadInteractivityPlugin(tsParticles);
|
|
62
65
|
await loadParticlesRepulseInteraction(tsParticles);
|
|
63
66
|
})();
|
|
64
67
|
```
|
|
@@ -67,9 +70,11 @@ or
|
|
|
67
70
|
|
|
68
71
|
```javascript
|
|
69
72
|
import { tsParticles } from "@tsparticles/engine";
|
|
73
|
+
import { loadInteractivityPlugin } from "@tsparticles/plugin-interactivity";
|
|
70
74
|
import { loadParticlesRepulseInteraction } from "@tsparticles/interaction-particles-repulse";
|
|
71
75
|
|
|
72
76
|
(async () => {
|
|
77
|
+
await loadInteractivityPlugin(tsParticles);
|
|
73
78
|
await loadParticlesRepulseInteraction(tsParticles);
|
|
74
79
|
})();
|
|
75
80
|
```
|
package/browser/Repulser.js
CHANGED
|
@@ -3,8 +3,17 @@ import { Vector, clamp, getDistances, getRangeValue } from "@tsparticles/engine"
|
|
|
3
3
|
import { ParticlesRepulse } from "./Options/Classes/ParticlesRepulse.js";
|
|
4
4
|
const minDistance = 0, identity = 1, squareExp = 2, minVelocity = 0;
|
|
5
5
|
export class Repulser extends ParticlesInteractorBase {
|
|
6
|
+
_maxDistance;
|
|
7
|
+
_normVec;
|
|
8
|
+
_velocityVec;
|
|
6
9
|
constructor(container) {
|
|
7
10
|
super(container);
|
|
11
|
+
this._maxDistance = 0;
|
|
12
|
+
this._normVec = Vector.origin;
|
|
13
|
+
this._velocityVec = Vector.origin;
|
|
14
|
+
}
|
|
15
|
+
get maxDistance() {
|
|
16
|
+
return this._maxDistance;
|
|
8
17
|
}
|
|
9
18
|
clear() {
|
|
10
19
|
}
|
|
@@ -17,25 +26,33 @@ export class Repulser extends ParticlesInteractorBase {
|
|
|
17
26
|
if (!repulseOpt1) {
|
|
18
27
|
return;
|
|
19
28
|
}
|
|
29
|
+
const repulseDistance = getRangeValue(repulseOpt1.distance);
|
|
30
|
+
if (repulseDistance > this.maxDistance) {
|
|
31
|
+
this._maxDistance = repulseDistance;
|
|
32
|
+
}
|
|
20
33
|
p1.repulse = {
|
|
21
|
-
distance:
|
|
34
|
+
distance: repulseDistance * container.retina.pixelRatio,
|
|
22
35
|
speed: getRangeValue(repulseOpt1.speed),
|
|
23
36
|
factor: getRangeValue(repulseOpt1.factor),
|
|
24
37
|
};
|
|
25
38
|
}
|
|
26
|
-
const pos1 = p1.getPosition(), query = container.particles.
|
|
39
|
+
const pos1 = p1.getPosition(), query = container.particles.grid.queryCircle(pos1, p1.repulse.distance), p1DistanceFactor = identity / p1.repulse.distance;
|
|
27
40
|
for (const p2 of query) {
|
|
28
41
|
if (p1 === p2 || p2.destroyed) {
|
|
29
42
|
continue;
|
|
30
43
|
}
|
|
31
|
-
const pos2 = p2.getPosition(), { dx, dy, distance } = getDistances(pos2, pos1), velocity = p1.repulse.speed * p1.repulse.factor;
|
|
44
|
+
const pos2 = p2.getPosition(), { dx, dy, distance } = getDistances(pos2, pos1), distanceFactor = identity / distance, velocity = p1.repulse.speed * p1.repulse.factor;
|
|
32
45
|
if (distance > minDistance) {
|
|
33
|
-
const repulseFactor = clamp((identity - Math.pow(distance
|
|
34
|
-
|
|
46
|
+
const repulseFactor = clamp((identity - Math.pow(distance * p1DistanceFactor, squareExp)) * velocity, minVelocity, velocity) *
|
|
47
|
+
distanceFactor;
|
|
48
|
+
this._normVec.x = dx * repulseFactor;
|
|
49
|
+
this._normVec.y = dy * repulseFactor;
|
|
50
|
+
p2.position.addTo(this._normVec);
|
|
35
51
|
}
|
|
36
52
|
else {
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
this._velocityVec.x = velocity;
|
|
54
|
+
this._velocityVec.y = velocity;
|
|
55
|
+
p2.position.addTo(this._velocityVec);
|
|
39
56
|
}
|
|
40
57
|
}
|
|
41
58
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export async function loadParticlesRepulseInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
6
|
e.addInteractor?.("particlesRepulse", async (container) => {
|
|
7
7
|
const { Repulser } = await import("./Repulser.js");
|
|
8
8
|
return new Repulser(container);
|
package/cjs/Repulser.js
CHANGED
|
@@ -3,8 +3,17 @@ import { Vector, clamp, getDistances, getRangeValue } from "@tsparticles/engine"
|
|
|
3
3
|
import { ParticlesRepulse } from "./Options/Classes/ParticlesRepulse.js";
|
|
4
4
|
const minDistance = 0, identity = 1, squareExp = 2, minVelocity = 0;
|
|
5
5
|
export class Repulser extends ParticlesInteractorBase {
|
|
6
|
+
_maxDistance;
|
|
7
|
+
_normVec;
|
|
8
|
+
_velocityVec;
|
|
6
9
|
constructor(container) {
|
|
7
10
|
super(container);
|
|
11
|
+
this._maxDistance = 0;
|
|
12
|
+
this._normVec = Vector.origin;
|
|
13
|
+
this._velocityVec = Vector.origin;
|
|
14
|
+
}
|
|
15
|
+
get maxDistance() {
|
|
16
|
+
return this._maxDistance;
|
|
8
17
|
}
|
|
9
18
|
clear() {
|
|
10
19
|
}
|
|
@@ -17,25 +26,33 @@ export class Repulser extends ParticlesInteractorBase {
|
|
|
17
26
|
if (!repulseOpt1) {
|
|
18
27
|
return;
|
|
19
28
|
}
|
|
29
|
+
const repulseDistance = getRangeValue(repulseOpt1.distance);
|
|
30
|
+
if (repulseDistance > this.maxDistance) {
|
|
31
|
+
this._maxDistance = repulseDistance;
|
|
32
|
+
}
|
|
20
33
|
p1.repulse = {
|
|
21
|
-
distance:
|
|
34
|
+
distance: repulseDistance * container.retina.pixelRatio,
|
|
22
35
|
speed: getRangeValue(repulseOpt1.speed),
|
|
23
36
|
factor: getRangeValue(repulseOpt1.factor),
|
|
24
37
|
};
|
|
25
38
|
}
|
|
26
|
-
const pos1 = p1.getPosition(), query = container.particles.
|
|
39
|
+
const pos1 = p1.getPosition(), query = container.particles.grid.queryCircle(pos1, p1.repulse.distance), p1DistanceFactor = identity / p1.repulse.distance;
|
|
27
40
|
for (const p2 of query) {
|
|
28
41
|
if (p1 === p2 || p2.destroyed) {
|
|
29
42
|
continue;
|
|
30
43
|
}
|
|
31
|
-
const pos2 = p2.getPosition(), { dx, dy, distance } = getDistances(pos2, pos1), velocity = p1.repulse.speed * p1.repulse.factor;
|
|
44
|
+
const pos2 = p2.getPosition(), { dx, dy, distance } = getDistances(pos2, pos1), distanceFactor = identity / distance, velocity = p1.repulse.speed * p1.repulse.factor;
|
|
32
45
|
if (distance > minDistance) {
|
|
33
|
-
const repulseFactor = clamp((identity - Math.pow(distance
|
|
34
|
-
|
|
46
|
+
const repulseFactor = clamp((identity - Math.pow(distance * p1DistanceFactor, squareExp)) * velocity, minVelocity, velocity) *
|
|
47
|
+
distanceFactor;
|
|
48
|
+
this._normVec.x = dx * repulseFactor;
|
|
49
|
+
this._normVec.y = dy * repulseFactor;
|
|
50
|
+
p2.position.addTo(this._normVec);
|
|
35
51
|
}
|
|
36
52
|
else {
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
this._velocityVec.x = velocity;
|
|
54
|
+
this._velocityVec.y = velocity;
|
|
55
|
+
p2.position.addTo(this._velocityVec);
|
|
39
56
|
}
|
|
40
57
|
}
|
|
41
58
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export async function loadParticlesRepulseInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
6
|
e.addInteractor?.("particlesRepulse", async (container) => {
|
|
7
7
|
const { Repulser } = await import("./Repulser.js");
|
|
8
8
|
return new Repulser(container);
|
|
@@ -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-
|
|
7
|
+
* v4.0.0-beta.0
|
|
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 */ ParticlesRepulse: () => (/* binding */ ParticlesRepulse)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass ParticlesRepulse extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ValueWithRandom {\n
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ParticlesRepulse: () => (/* binding */ ParticlesRepulse)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass ParticlesRepulse extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ValueWithRandom {\n distance;\n duration;\n enabled;\n factor;\n speed;\n constructor(){\n super();\n this.enabled = false;\n this.distance = 1;\n this.duration = 1;\n this.factor = 1;\n this.speed = 1;\n }\n load(data) {\n super.load(data);\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.enabled !== undefined) {\n this.enabled = data.enabled;\n }\n if (data.distance !== undefined) {\n this.distance = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.distance);\n }\n if (data.duration !== undefined) {\n this.duration = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.duration);\n }\n if (data.factor !== undefined) {\n this.factor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.factor);\n }\n if (data.speed !== undefined) {\n this.speed = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.speed);\n }\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-repulse/./dist/browser/Options/Classes/ParticlesRepulse.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 */ Repulser: () => (/* binding */ Repulser)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_ParticlesRepulse_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/ParticlesRepulse.js */ \"./dist/browser/Options/Classes/ParticlesRepulse.js\");\n\n\n\nconst minDistance = 0
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Repulser: () => (/* binding */ Repulser)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_ParticlesRepulse_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/ParticlesRepulse.js */ \"./dist/browser/Options/Classes/ParticlesRepulse.js\");\n\n\n\nconst minDistance = 0, identity = 1, squareExp = 2, minVelocity = 0;\nclass Repulser extends _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__.ParticlesInteractorBase {\n _maxDistance;\n _normVec;\n _velocityVec;\n constructor(container){\n super(container);\n this._maxDistance = 0;\n this._normVec = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.Vector.origin;\n this._velocityVec = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.Vector.origin;\n }\n get maxDistance() {\n return this._maxDistance;\n }\n clear() {}\n init() {}\n interact(p1) {\n const container = this.container;\n if (!p1.repulse) {\n const repulseOpt1 = p1.options.repulse;\n if (!repulseOpt1) {\n return;\n }\n const repulseDistance = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(repulseOpt1.distance);\n if (repulseDistance > this.maxDistance) {\n this._maxDistance = repulseDistance;\n }\n p1.repulse = {\n distance: repulseDistance * container.retina.pixelRatio,\n speed: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(repulseOpt1.speed),\n factor: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(repulseOpt1.factor)\n };\n }\n const pos1 = p1.getPosition(), query = container.particles.grid.queryCircle(pos1, p1.repulse.distance), p1DistanceFactor = identity / p1.repulse.distance;\n for (const p2 of query){\n if (p1 === p2 || p2.destroyed) {\n continue;\n }\n const pos2 = p2.getPosition(), { dx, dy, distance } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.getDistances)(pos2, pos1), distanceFactor = identity / distance, velocity = p1.repulse.speed * p1.repulse.factor;\n if (distance > minDistance) {\n const repulseFactor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.clamp)((identity - Math.pow(distance * p1DistanceFactor, squareExp)) * velocity, minVelocity, velocity) * distanceFactor;\n this._normVec.x = dx * repulseFactor;\n this._normVec.y = dy * repulseFactor;\n p2.position.addTo(this._normVec);\n } else {\n this._velocityVec.x = velocity;\n this._velocityVec.y = velocity;\n p2.position.addTo(this._velocityVec);\n }\n }\n }\n isEnabled(particle) {\n return particle.options.repulse?.enabled ?? false;\n }\n loadParticlesOptions(options, ...sources) {\n options.repulse ??= new _Options_Classes_ParticlesRepulse_js__WEBPACK_IMPORTED_MODULE_2__.ParticlesRepulse();\n for (const source of sources){\n options.repulse.load(source?.repulse);\n }\n }\n reset() {}\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-repulse/./dist/browser/Repulser.js?\n}");
|
|
37
37
|
|
|
38
38
|
/***/ }
|
|
39
39
|
|
package/esm/Repulser.js
CHANGED
|
@@ -3,8 +3,17 @@ import { Vector, clamp, getDistances, getRangeValue } from "@tsparticles/engine"
|
|
|
3
3
|
import { ParticlesRepulse } from "./Options/Classes/ParticlesRepulse.js";
|
|
4
4
|
const minDistance = 0, identity = 1, squareExp = 2, minVelocity = 0;
|
|
5
5
|
export class Repulser extends ParticlesInteractorBase {
|
|
6
|
+
_maxDistance;
|
|
7
|
+
_normVec;
|
|
8
|
+
_velocityVec;
|
|
6
9
|
constructor(container) {
|
|
7
10
|
super(container);
|
|
11
|
+
this._maxDistance = 0;
|
|
12
|
+
this._normVec = Vector.origin;
|
|
13
|
+
this._velocityVec = Vector.origin;
|
|
14
|
+
}
|
|
15
|
+
get maxDistance() {
|
|
16
|
+
return this._maxDistance;
|
|
8
17
|
}
|
|
9
18
|
clear() {
|
|
10
19
|
}
|
|
@@ -17,25 +26,33 @@ export class Repulser extends ParticlesInteractorBase {
|
|
|
17
26
|
if (!repulseOpt1) {
|
|
18
27
|
return;
|
|
19
28
|
}
|
|
29
|
+
const repulseDistance = getRangeValue(repulseOpt1.distance);
|
|
30
|
+
if (repulseDistance > this.maxDistance) {
|
|
31
|
+
this._maxDistance = repulseDistance;
|
|
32
|
+
}
|
|
20
33
|
p1.repulse = {
|
|
21
|
-
distance:
|
|
34
|
+
distance: repulseDistance * container.retina.pixelRatio,
|
|
22
35
|
speed: getRangeValue(repulseOpt1.speed),
|
|
23
36
|
factor: getRangeValue(repulseOpt1.factor),
|
|
24
37
|
};
|
|
25
38
|
}
|
|
26
|
-
const pos1 = p1.getPosition(), query = container.particles.
|
|
39
|
+
const pos1 = p1.getPosition(), query = container.particles.grid.queryCircle(pos1, p1.repulse.distance), p1DistanceFactor = identity / p1.repulse.distance;
|
|
27
40
|
for (const p2 of query) {
|
|
28
41
|
if (p1 === p2 || p2.destroyed) {
|
|
29
42
|
continue;
|
|
30
43
|
}
|
|
31
|
-
const pos2 = p2.getPosition(), { dx, dy, distance } = getDistances(pos2, pos1), velocity = p1.repulse.speed * p1.repulse.factor;
|
|
44
|
+
const pos2 = p2.getPosition(), { dx, dy, distance } = getDistances(pos2, pos1), distanceFactor = identity / distance, velocity = p1.repulse.speed * p1.repulse.factor;
|
|
32
45
|
if (distance > minDistance) {
|
|
33
|
-
const repulseFactor = clamp((identity - Math.pow(distance
|
|
34
|
-
|
|
46
|
+
const repulseFactor = clamp((identity - Math.pow(distance * p1DistanceFactor, squareExp)) * velocity, minVelocity, velocity) *
|
|
47
|
+
distanceFactor;
|
|
48
|
+
this._normVec.x = dx * repulseFactor;
|
|
49
|
+
this._normVec.y = dy * repulseFactor;
|
|
50
|
+
p2.position.addTo(this._normVec);
|
|
35
51
|
}
|
|
36
52
|
else {
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
this._velocityVec.x = velocity;
|
|
54
|
+
this._velocityVec.y = velocity;
|
|
55
|
+
p2.position.addTo(this._velocityVec);
|
|
39
56
|
}
|
|
40
57
|
}
|
|
41
58
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export async function loadParticlesRepulseInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
6
|
e.addInteractor?.("particlesRepulse", async (container) => {
|
|
7
7
|
const { Repulser } = await import("./Repulser.js");
|
|
8
8
|
return new Repulser(container);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-particles-repulse",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
4
4
|
"description": "tsParticles repulse particles interaction",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -101,8 +101,8 @@
|
|
|
101
101
|
"./package.json": "./package.json"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@tsparticles/engine": "4.0.0-
|
|
105
|
-
"@tsparticles/plugin-interactivity": "4.0.0-
|
|
104
|
+
"@tsparticles/engine": "4.0.0-beta.0",
|
|
105
|
+
"@tsparticles/plugin-interactivity": "4.0.0-beta.0"
|
|
106
106
|
},
|
|
107
107
|
"publishConfig": {
|
|
108
108
|
"access": "public"
|