@tsparticles/interaction-particles-repulse 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 +69 -0
- package/browser/Options/Classes/ParticlesRepulse.js +32 -0
- package/browser/Options/Interfaces/IParticlesRepulse.js +1 -0
- package/browser/Repulser.js +57 -0
- package/browser/Types.js +1 -0
- package/browser/index.js +4 -0
- package/cjs/Options/Classes/ParticlesRepulse.js +36 -0
- package/cjs/Options/Interfaces/IParticlesRepulse.js +2 -0
- package/cjs/Repulser.js +72 -0
- package/cjs/Types.js +2 -0
- package/cjs/index.js +8 -0
- package/esm/Options/Classes/ParticlesRepulse.js +32 -0
- package/esm/Options/Interfaces/IParticlesRepulse.js +1 -0
- package/esm/Repulser.js +57 -0
- package/esm/Types.js +1 -0
- package/esm/index.js +4 -0
- package/package.json +92 -0
- package/report.html +39 -0
- package/tsparticles.interaction.particles.repulse.js +201 -0
- package/tsparticles.interaction.particles.repulse.min.js +2 -0
- package/tsparticles.interaction.particles.repulse.min.js.LICENSE.txt +8 -0
- package/types/Options/Classes/ParticlesRepulse.d.ts +12 -0
- package/types/Options/Interfaces/IParticlesRepulse.d.ts +8 -0
- package/types/Repulser.d.ts +21 -0
- package/types/Types.d.ts +9 -0
- package/types/index.d.ts +2 -0
- package/umd/Options/Classes/ParticlesRepulse.js +46 -0
- package/umd/Options/Interfaces/IParticlesRepulse.js +12 -0
- package/umd/Repulser.js +71 -0
- package/umd/Types.js +12 -0
- package/umd/index.js +18 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v3.0.0-alpha.0
|
|
8
|
+
*/
|
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
11
|
+
module.exports = factory(require("@tsparticles/engine"));
|
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
|
13
|
+
define(["@tsparticles/engine"], factory);
|
|
14
|
+
else {
|
|
15
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
16
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
17
|
+
}
|
|
18
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
|
|
19
|
+
return /******/ (() => { // webpackBootstrap
|
|
20
|
+
/******/ "use strict";
|
|
21
|
+
/******/ var __webpack_modules__ = ({
|
|
22
|
+
|
|
23
|
+
/***/ 533:
|
|
24
|
+
/***/ ((module) => {
|
|
25
|
+
|
|
26
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
|
|
27
|
+
|
|
28
|
+
/***/ })
|
|
29
|
+
|
|
30
|
+
/******/ });
|
|
31
|
+
/************************************************************************/
|
|
32
|
+
/******/ // The module cache
|
|
33
|
+
/******/ var __webpack_module_cache__ = {};
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // The require function
|
|
36
|
+
/******/ function __webpack_require__(moduleId) {
|
|
37
|
+
/******/ // Check if module is in cache
|
|
38
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
39
|
+
/******/ if (cachedModule !== undefined) {
|
|
40
|
+
/******/ return cachedModule.exports;
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ // Create a new module (and put it into the cache)
|
|
43
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
44
|
+
/******/ // no module.id needed
|
|
45
|
+
/******/ // no module.loaded needed
|
|
46
|
+
/******/ exports: {}
|
|
47
|
+
/******/ };
|
|
48
|
+
/******/
|
|
49
|
+
/******/ // Execute the module function
|
|
50
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // Return the exports of the module
|
|
53
|
+
/******/ return module.exports;
|
|
54
|
+
/******/ }
|
|
55
|
+
/******/
|
|
56
|
+
/************************************************************************/
|
|
57
|
+
/******/ /* webpack/runtime/define property getters */
|
|
58
|
+
/******/ (() => {
|
|
59
|
+
/******/ // define getter functions for harmony exports
|
|
60
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
61
|
+
/******/ for(var key in definition) {
|
|
62
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
63
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
64
|
+
/******/ }
|
|
65
|
+
/******/ }
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/ })();
|
|
68
|
+
/******/
|
|
69
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
70
|
+
/******/ (() => {
|
|
71
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
72
|
+
/******/ })();
|
|
73
|
+
/******/
|
|
74
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
75
|
+
/******/ (() => {
|
|
76
|
+
/******/ // define __esModule on exports
|
|
77
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
78
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
79
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
80
|
+
/******/ }
|
|
81
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
82
|
+
/******/ };
|
|
83
|
+
/******/ })();
|
|
84
|
+
/******/
|
|
85
|
+
/************************************************************************/
|
|
86
|
+
var __webpack_exports__ = {};
|
|
87
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
88
|
+
(() => {
|
|
89
|
+
// ESM COMPAT FLAG
|
|
90
|
+
__webpack_require__.r(__webpack_exports__);
|
|
91
|
+
|
|
92
|
+
// EXPORTS
|
|
93
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
94
|
+
"loadParticlesRepulseInteraction": () => (/* binding */ loadParticlesRepulseInteraction)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
98
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
99
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/ParticlesRepulse.js
|
|
100
|
+
|
|
101
|
+
class ParticlesRepulse extends engine_root_window_.ValueWithRandom {
|
|
102
|
+
constructor() {
|
|
103
|
+
super();
|
|
104
|
+
this.enabled = false;
|
|
105
|
+
this.distance = 1;
|
|
106
|
+
this.duration = 1;
|
|
107
|
+
this.factor = 1;
|
|
108
|
+
this.speed = 1;
|
|
109
|
+
}
|
|
110
|
+
load(data) {
|
|
111
|
+
super.load(data);
|
|
112
|
+
if (!data) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (data.enabled !== undefined) {
|
|
116
|
+
this.enabled = data.enabled;
|
|
117
|
+
}
|
|
118
|
+
if (data.distance !== undefined) {
|
|
119
|
+
this.distance = (0,engine_root_window_.setRangeValue)(data.distance);
|
|
120
|
+
}
|
|
121
|
+
if (data.duration !== undefined) {
|
|
122
|
+
this.duration = (0,engine_root_window_.setRangeValue)(data.duration);
|
|
123
|
+
}
|
|
124
|
+
if (data.factor !== undefined) {
|
|
125
|
+
this.factor = (0,engine_root_window_.setRangeValue)(data.factor);
|
|
126
|
+
}
|
|
127
|
+
if (data.speed !== undefined) {
|
|
128
|
+
this.speed = (0,engine_root_window_.setRangeValue)(data.speed);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
;// CONCATENATED MODULE: ./dist/browser/Repulser.js
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class Repulser extends engine_root_window_.ParticlesInteractorBase {
|
|
136
|
+
constructor(container) {
|
|
137
|
+
super(container);
|
|
138
|
+
}
|
|
139
|
+
clear() {}
|
|
140
|
+
init() {}
|
|
141
|
+
async interact(p1) {
|
|
142
|
+
const container = this.container;
|
|
143
|
+
if (!p1.repulse) {
|
|
144
|
+
const repulseOpt1 = p1.options.repulse;
|
|
145
|
+
if (!repulseOpt1) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
p1.repulse = {
|
|
149
|
+
distance: (0,engine_root_window_.getRangeValue)(repulseOpt1.distance) * container.retina.pixelRatio,
|
|
150
|
+
speed: (0,engine_root_window_.getRangeValue)(repulseOpt1.speed),
|
|
151
|
+
factor: (0,engine_root_window_.getRangeValue)(repulseOpt1.factor)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
const pos1 = p1.getPosition(),
|
|
155
|
+
query = container.particles.quadTree.queryCircle(pos1, p1.repulse.distance);
|
|
156
|
+
for (const p2 of query) {
|
|
157
|
+
if (p1 === p2 || p2.destroyed) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const pos2 = p2.getPosition();
|
|
161
|
+
const {
|
|
162
|
+
dx,
|
|
163
|
+
dy,
|
|
164
|
+
distance
|
|
165
|
+
} = (0,engine_root_window_.getDistances)(pos2, pos1);
|
|
166
|
+
const velocity = p1.repulse.speed * p1.repulse.factor;
|
|
167
|
+
if (distance > 0) {
|
|
168
|
+
const repulseFactor = (0,engine_root_window_.clamp)((1 - Math.pow(distance / p1.repulse.distance, 2)) * velocity, 0, velocity);
|
|
169
|
+
const normVec = engine_root_window_.Vector.create(dx / distance * repulseFactor, dy / distance * repulseFactor);
|
|
170
|
+
p2.position.addTo(normVec);
|
|
171
|
+
} else {
|
|
172
|
+
const velocityVec = engine_root_window_.Vector.create(velocity, velocity);
|
|
173
|
+
p2.position.addTo(velocityVec);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
isEnabled(particle) {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
return (_b = (_a = particle.options.repulse) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false;
|
|
180
|
+
}
|
|
181
|
+
loadParticlesOptions(options, ...sources) {
|
|
182
|
+
if (!options.repulse) {
|
|
183
|
+
options.repulse = new ParticlesRepulse();
|
|
184
|
+
}
|
|
185
|
+
for (const source of sources) {
|
|
186
|
+
options.repulse.load(source === null || source === void 0 ? void 0 : source.repulse);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
reset() {}
|
|
190
|
+
}
|
|
191
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
192
|
+
|
|
193
|
+
function loadParticlesRepulseInteraction(engine) {
|
|
194
|
+
engine.addInteractor("particlesRepulse", container => new Repulser(container));
|
|
195
|
+
}
|
|
196
|
+
})();
|
|
197
|
+
|
|
198
|
+
/******/ return __webpack_exports__;
|
|
199
|
+
/******/ })()
|
|
200
|
+
;
|
|
201
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.interaction.particles.repulse.min.js.LICENSE.txt */
|
|
2
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var o="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var r in o)("object"==typeof exports?exports:e)[r]=o[r]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},o={};function r(e){var s=o[e];if(void 0!==s)return s.exports;var n=o[e]={exports:{}};return t[e](n,n.exports,r),n.exports}r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};return(()=>{r.r(s),r.d(s,{loadParticlesRepulseInteraction:()=>n});var e=r(533);class t extends e.ValueWithRandom{constructor(){super(),this.enabled=!1,this.distance=1,this.duration=1,this.factor=1,this.speed=1}load(t){super.load(t),t&&(void 0!==t.enabled&&(this.enabled=t.enabled),void 0!==t.distance&&(this.distance=(0,e.setRangeValue)(t.distance)),void 0!==t.duration&&(this.duration=(0,e.setRangeValue)(t.duration)),void 0!==t.factor&&(this.factor=(0,e.setRangeValue)(t.factor)),void 0!==t.speed&&(this.speed=(0,e.setRangeValue)(t.speed)))}}class o extends e.ParticlesInteractorBase{constructor(e){super(e)}clear(){}init(){}async interact(t){const o=this.container;if(!t.repulse){const r=t.options.repulse;if(!r)return;t.repulse={distance:(0,e.getRangeValue)(r.distance)*o.retina.pixelRatio,speed:(0,e.getRangeValue)(r.speed),factor:(0,e.getRangeValue)(r.factor)}}const r=t.getPosition(),s=o.particles.quadTree.queryCircle(r,t.repulse.distance);for(const o of s){if(t===o||o.destroyed)continue;const s=o.getPosition(),{dx:n,dy:i,distance:a}=(0,e.getDistances)(s,r),d=t.repulse.speed*t.repulse.factor;if(a>0){const r=(0,e.clamp)((1-Math.pow(a/t.repulse.distance,2))*d,0,d),s=e.Vector.create(n/a*r,i/a*r);o.position.addTo(s)}else{const t=e.Vector.create(d,d);o.position.addTo(t)}}}isEnabled(e){var t,o;return null!==(o=null===(t=e.options.repulse)||void 0===t?void 0:t.enabled)&&void 0!==o&&o}loadParticlesOptions(e,...o){e.repulse||(e.repulse=new t);for(const t of o)e.repulse.load(null==t?void 0:t.repulse)}reset(){}}function n(e){e.addInteractor("particlesRepulse",(e=>new o(e)))}})(),s})()));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
3
|
+
import type { IParticlesRepulse } from "../Interfaces/IParticlesRepulse";
|
|
4
|
+
export declare class ParticlesRepulse extends ValueWithRandom implements IParticlesRepulse, IOptionLoader<IParticlesRepulse> {
|
|
5
|
+
distance: RangeValue;
|
|
6
|
+
duration: RangeValue;
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
factor: RangeValue;
|
|
9
|
+
speed: RangeValue;
|
|
10
|
+
constructor();
|
|
11
|
+
load(data?: RecursivePartial<IParticlesRepulse>): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Container, Particle, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { IRepulseParticlesOptions, RepulseParticlesOptions } from "./Types";
|
|
3
|
+
import { ParticlesInteractorBase } from "@tsparticles/engine";
|
|
4
|
+
type RepulseParticle = Particle & {
|
|
5
|
+
options: RepulseParticlesOptions;
|
|
6
|
+
repulse?: {
|
|
7
|
+
distance: number;
|
|
8
|
+
factor: number;
|
|
9
|
+
speed: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare class Repulser extends ParticlesInteractorBase {
|
|
13
|
+
constructor(container: Container);
|
|
14
|
+
clear(): void;
|
|
15
|
+
init(): void;
|
|
16
|
+
interact(p1: RepulseParticle): Promise<void>;
|
|
17
|
+
isEnabled(particle: RepulseParticle): boolean;
|
|
18
|
+
loadParticlesOptions?(options: RepulseParticlesOptions, ...sources: (RecursivePartial<IRepulseParticlesOptions> | undefined)[]): void;
|
|
19
|
+
reset(): void;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
package/types/Types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IParticlesOptions, ParticlesOptions } from "@tsparticles/engine";
|
|
2
|
+
import type { IParticlesRepulse } from "./Options/Interfaces/IParticlesRepulse";
|
|
3
|
+
import type { ParticlesRepulse } from "./Options/Classes/ParticlesRepulse";
|
|
4
|
+
export type RepulseParticlesOptions = ParticlesOptions & {
|
|
5
|
+
repulse?: ParticlesRepulse;
|
|
6
|
+
};
|
|
7
|
+
export type IRepulseParticlesOptions = IParticlesOptions & {
|
|
8
|
+
repulse?: IParticlesRepulse;
|
|
9
|
+
};
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ParticlesRepulse = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class ParticlesRepulse extends engine_1.ValueWithRandom {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.enabled = false;
|
|
18
|
+
this.distance = 1;
|
|
19
|
+
this.duration = 1;
|
|
20
|
+
this.factor = 1;
|
|
21
|
+
this.speed = 1;
|
|
22
|
+
}
|
|
23
|
+
load(data) {
|
|
24
|
+
super.load(data);
|
|
25
|
+
if (!data) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (data.enabled !== undefined) {
|
|
29
|
+
this.enabled = data.enabled;
|
|
30
|
+
}
|
|
31
|
+
if (data.distance !== undefined) {
|
|
32
|
+
this.distance = (0, engine_1.setRangeValue)(data.distance);
|
|
33
|
+
}
|
|
34
|
+
if (data.duration !== undefined) {
|
|
35
|
+
this.duration = (0, engine_1.setRangeValue)(data.duration);
|
|
36
|
+
}
|
|
37
|
+
if (data.factor !== undefined) {
|
|
38
|
+
this.factor = (0, engine_1.setRangeValue)(data.factor);
|
|
39
|
+
}
|
|
40
|
+
if (data.speed !== undefined) {
|
|
41
|
+
this.speed = (0, engine_1.setRangeValue)(data.speed);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.ParticlesRepulse = ParticlesRepulse;
|
|
46
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/Repulser.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/ParticlesRepulse"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Repulser = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const ParticlesRepulse_1 = require("./Options/Classes/ParticlesRepulse");
|
|
15
|
+
class Repulser extends engine_1.ParticlesInteractorBase {
|
|
16
|
+
constructor(container) {
|
|
17
|
+
super(container);
|
|
18
|
+
}
|
|
19
|
+
clear() {
|
|
20
|
+
}
|
|
21
|
+
init() {
|
|
22
|
+
}
|
|
23
|
+
async interact(p1) {
|
|
24
|
+
const container = this.container;
|
|
25
|
+
if (!p1.repulse) {
|
|
26
|
+
const repulseOpt1 = p1.options.repulse;
|
|
27
|
+
if (!repulseOpt1) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
p1.repulse = {
|
|
31
|
+
distance: (0, engine_1.getRangeValue)(repulseOpt1.distance) * container.retina.pixelRatio,
|
|
32
|
+
speed: (0, engine_1.getRangeValue)(repulseOpt1.speed),
|
|
33
|
+
factor: (0, engine_1.getRangeValue)(repulseOpt1.factor),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, p1.repulse.distance);
|
|
37
|
+
for (const p2 of query) {
|
|
38
|
+
if (p1 === p2 || p2.destroyed) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const pos2 = p2.getPosition();
|
|
42
|
+
const { dx, dy, distance } = (0, engine_1.getDistances)(pos2, pos1);
|
|
43
|
+
const velocity = p1.repulse.speed * p1.repulse.factor;
|
|
44
|
+
if (distance > 0) {
|
|
45
|
+
const repulseFactor = (0, engine_1.clamp)((1 - Math.pow(distance / p1.repulse.distance, 2)) * velocity, 0, velocity);
|
|
46
|
+
const normVec = engine_1.Vector.create((dx / distance) * repulseFactor, (dy / distance) * repulseFactor);
|
|
47
|
+
p2.position.addTo(normVec);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const velocityVec = engine_1.Vector.create(velocity, velocity);
|
|
51
|
+
p2.position.addTo(velocityVec);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
isEnabled(particle) {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
return (_b = (_a = particle.options.repulse) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false;
|
|
58
|
+
}
|
|
59
|
+
loadParticlesOptions(options, ...sources) {
|
|
60
|
+
if (!options.repulse) {
|
|
61
|
+
options.repulse = new ParticlesRepulse_1.ParticlesRepulse();
|
|
62
|
+
}
|
|
63
|
+
for (const source of sources) {
|
|
64
|
+
options.repulse.load(source === null || source === void 0 ? void 0 : source.repulse);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
reset() {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.Repulser = Repulser;
|
|
71
|
+
});
|
package/umd/Types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./Repulser"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadParticlesRepulseInteraction = void 0;
|
|
13
|
+
const Repulser_1 = require("./Repulser");
|
|
14
|
+
function loadParticlesRepulseInteraction(engine) {
|
|
15
|
+
engine.addInteractor("particlesRepulse", (container) => new Repulser_1.Repulser(container));
|
|
16
|
+
}
|
|
17
|
+
exports.loadParticlesRepulseInteraction = loadParticlesRepulseInteraction;
|
|
18
|
+
});
|