UNPKG

@tsparticles/path-curves

Version:
148 lines (135 loc) 11.4 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/Curves.js": /*!********************************!*\ !*** ./dist/browser/Curves.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 */ CurvesPathGen: () => (/* binding */ CurvesPathGen)\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\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}"); /***/ }), /***/ "./dist/browser/CurvesPathGenerator.js": /*!*********************************************!*\ !*** ./dist/browser/CurvesPathGenerator.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 */ 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 _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _Curves_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Curves.js */ \"./dist/browser/Curves.js\");\n\n\nconst double = 2,\n doublePI = Math.PI * double;\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)() * doublePI;\n } else {\n p.curveVelocity.length += 0.01;\n p.curveVelocity.angle = (p.curveVelocity.angle + p.pathGen()) % 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 = window[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}"); /***/ }), /***/ "./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 */ curvesPathName: () => (/* binding */ curvesPathName),\n/* harmony export */ loadCurvesPath: () => (/* binding */ loadCurvesPath)\n/* harmony export */ });\n/* harmony import */ var _CurvesPathGenerator_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./CurvesPathGenerator.js */ \"./dist/browser/CurvesPathGenerator.js\");\n\nconst curvesPathName = \"curvesPathGenerator\";\nasync function loadCurvesPath(engine, refresh = true) {\n engine.checkVersion(\"3.9.1\");\n await engine.addPathGenerator(curvesPathName, new _CurvesPathGenerator_js__WEBPACK_IMPORTED_MODULE_0__.CurvesPathGenerator(), refresh);\n}\n\n//# sourceURL=webpack://@tsparticles/path-curves/./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__; /******/ })() ; });