UNPKG

@tsparticles/interaction-particles-repulse

Version:

tsParticles repulse particles interaction

148 lines (135 loc) 11.6 kB
/*! * Author : Matteo Bruni * MIT license: https://opensource.org/licenses/MIT * Demo / Generator : https://particles.js.org/ * GitHub : https://www.github.com/matteobruni/tsparticles * How to use? : Check the GitHub README * v3.9.1 */ /* * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). * This devtool is neither made for production nor for readable output files. * It uses "eval()" calls to create a separate source file in the browser devtools. * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) * or disable the default devtool with "devtool: false". * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("@tsparticles/engine")); else if(typeof define === 'function' && define.amd) define(["@tsparticles/engine"], factory); else { var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]); for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; } })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./dist/browser/Options/Classes/ParticlesRepulse.js": /*!**********************************************************!*\ !*** ./dist/browser/Options/Classes/ParticlesRepulse.js ***! \**********************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 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/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nclass ParticlesRepulse extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ValueWithRandom {\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//# sourceURL=webpack://@tsparticles/interaction-particles-repulse/./dist/browser/Options/Classes/ParticlesRepulse.js?\n}"); /***/ }), /***/ "./dist/browser/Repulser.js": /*!**********************************!*\ !*** ./dist/browser/Repulser.js ***! \**********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 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_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _Options_Classes_ParticlesRepulse_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/ParticlesRepulse.js */ \"./dist/browser/Options/Classes/ParticlesRepulse.js\");\n\n\nconst minDistance = 0,\n identity = 1,\n squareExp = 2,\n minVelocity = 0;\nclass Repulser extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ParticlesInteractorBase {\n constructor(container) {\n super(container);\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 p1.repulse = {\n distance: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(repulseOpt1.distance) * container.retina.pixelRatio,\n speed: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(repulseOpt1.speed),\n factor: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(repulseOpt1.factor)\n };\n }\n const pos1 = p1.getPosition(),\n query = container.particles.quadTree.queryCircle(pos1, p1.repulse.distance);\n for (const p2 of query) {\n if (p1 === p2 || p2.destroyed) {\n continue;\n }\n const pos2 = p2.getPosition(),\n {\n dx,\n dy,\n distance\n } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(pos2, pos1),\n velocity = p1.repulse.speed * p1.repulse.factor;\n if (distance > minDistance) {\n const repulseFactor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.clamp)((identity - Math.pow(distance / p1.repulse.distance, squareExp)) * velocity, minVelocity, velocity),\n normVec = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.create(dx / distance * repulseFactor, dy / distance * repulseFactor);\n p2.position.addTo(normVec);\n } else {\n const velocityVec = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.create(velocity, velocity);\n p2.position.addTo(velocityVec);\n }\n }\n }\n isEnabled(particle) {\n return particle.options.repulse?.enabled ?? false;\n }\n loadParticlesOptions(options, ...sources) {\n if (!options.repulse) {\n options.repulse = new _Options_Classes_ParticlesRepulse_js__WEBPACK_IMPORTED_MODULE_1__.ParticlesRepulse();\n }\n for (const source of sources) {\n options.repulse.load(source?.repulse);\n }\n }\n reset() {}\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-repulse/./dist/browser/Repulser.js?\n}"); /***/ }), /***/ "./dist/browser/index.js": /*!*******************************!*\ !*** ./dist/browser/index.js ***! \*******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadParticlesRepulseInteraction: () => (/* binding */ loadParticlesRepulseInteraction)\n/* harmony export */ });\n/* harmony import */ var _Repulser_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Repulser.js */ \"./dist/browser/Repulser.js\");\n\nasync function loadParticlesRepulseInteraction(engine, refresh = true) {\n engine.checkVersion(\"3.9.1\");\n await engine.addInteractor(\"particlesRepulse\", container => {\n return Promise.resolve(new _Repulser_js__WEBPACK_IMPORTED_MODULE_0__.Repulser(container));\n }, refresh);\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-repulse/./dist/browser/index.js?\n}"); /***/ }), /***/ "@tsparticles/engine": /*!*********************************************************************************************************************************!*\ !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***! \*********************************************************************************************************************************/ /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ (() => { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = (module) => { /******/ var getter = module && module.__esModule ? /******/ () => (module['default']) : /******/ () => (module); /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ /******/ /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module can't be inlined because the eval devtool is used. /******/ var __webpack_exports__ = __webpack_require__("./dist/browser/index.js"); /******/ /******/ return __webpack_exports__; /******/ })() ; });