@tsparticles/noise-field 4.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 +74 -0
- package/browser/IFactorOffsetValues.js +1 -0
- package/browser/INoiseFieldOptions.js +1 -0
- package/browser/INoiseGenerator.js +1 -0
- package/browser/NoiseFieldGenerator.js +164 -0
- package/browser/index.js +1 -0
- package/browser/package.json +1 -0
- package/cjs/IFactorOffsetValues.js +1 -0
- package/cjs/INoiseFieldOptions.js +1 -0
- package/cjs/INoiseGenerator.js +1 -0
- package/cjs/NoiseFieldGenerator.js +164 -0
- package/cjs/index.js +1 -0
- package/cjs/package.json +1 -0
- package/esm/IFactorOffsetValues.js +1 -0
- package/esm/INoiseFieldOptions.js +1 -0
- package/esm/INoiseGenerator.js +1 -0
- package/esm/NoiseFieldGenerator.js +164 -0
- package/esm/index.js +1 -0
- package/esm/package.json +1 -0
- package/package.json +109 -0
- package/report.html +40 -0
- package/tsparticles.noise.field.js +132 -0
- package/tsparticles.noise.field.min.js +2 -0
- package/tsparticles.noise.field.min.js.LICENSE.txt +1 -0
- package/types/IFactorOffsetValues.d.ts +9 -0
- package/types/INoiseFieldOptions.d.ts +14 -0
- package/types/INoiseGenerator.d.ts +4 -0
- package/types/NoiseFieldGenerator.d.ts +20 -0
- package/types/index.d.ts +4 -0
- package/umd/IFactorOffsetValues.js +12 -0
- package/umd/INoiseFieldOptions.js +12 -0
- package/umd/INoiseGenerator.js +12 -0
- package/umd/NoiseFieldGenerator.js +178 -0
- package/umd/index.js +15 -0
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
* v4.0.0-alpha.0
|
|
8
|
+
*/
|
|
9
|
+
/*
|
|
10
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
11
|
+
* This devtool is neither made for production nor for readable output files.
|
|
12
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
13
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
14
|
+
* or disable the default devtool with "devtool: false".
|
|
15
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
16
|
+
*/
|
|
17
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
18
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
19
|
+
module.exports = factory(require("@tsparticles/engine"));
|
|
20
|
+
else if(typeof define === 'function' && define.amd)
|
|
21
|
+
define(["@tsparticles/engine"], factory);
|
|
22
|
+
else {
|
|
23
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
24
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
25
|
+
}
|
|
26
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => {
|
|
27
|
+
return /******/ (() => { // webpackBootstrap
|
|
28
|
+
/******/ "use strict";
|
|
29
|
+
/******/ var __webpack_modules__ = ({
|
|
30
|
+
|
|
31
|
+
/***/ "./dist/browser/NoiseFieldGenerator.js"
|
|
32
|
+
/*!*********************************************!*\
|
|
33
|
+
!*** ./dist/browser/NoiseFieldGenerator.js ***!
|
|
34
|
+
\*********************************************/
|
|
35
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
36
|
+
|
|
37
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ NoiseFieldGenerator: () => (/* binding */ NoiseFieldGenerator)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst originCoordinate = 0,\n firstIndex = 0,\n empty = 0,\n optionsSizeOffset = 1,\n transformDefaultValues = {\n a: 1,\n b: 0,\n c: 0,\n d: 1,\n e: 0,\n f: 0\n },\n double = 2,\n doublePI = Math.PI * double,\n defaultOptions = {\n draw: false,\n size: 20,\n increment: 0.004,\n columns: 0,\n rows: 0,\n layers: 0,\n width: 0,\n height: 0,\n factor: {\n angle: 0.02,\n length: 0.01\n },\n offset: {\n x: 40000,\n y: 40000,\n z: 40000\n }\n };\nclass NoiseFieldGenerator {\n constructor(noiseGen) {\n this.noiseGen = noiseGen;\n this.field = [];\n this.noiseW = 0;\n this.options = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, defaultOptions);\n }\n generate(particle) {\n const pos = particle.getPosition(),\n {\n size\n } = this.options,\n point = {\n x: Math.max(Math.floor(pos.x / size), originCoordinate),\n y: Math.max(Math.floor(pos.y / size), originCoordinate),\n z: Math.max(Math.floor(pos.z / size), originCoordinate)\n },\n {\n field\n } = this,\n fieldPoint = field[point.x]?.[point.y]?.[point.z];\n return fieldPoint ? fieldPoint.copy() : _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin;\n }\n init(container) {\n this.container = container;\n this._setup();\n }\n reset() {}\n update() {\n if (!this.container) {\n return;\n }\n this._calculateField();\n this.noiseW += this.options.increment;\n if (!this.options.draw) {\n return;\n }\n this.container.canvas.draw(ctx => {\n this._drawField(ctx);\n });\n }\n _calculateField() {\n const {\n field,\n noiseGen,\n options,\n noiseW\n } = this,\n lengthFactor = options.factor.length,\n angleFactor = options.factor.angle;\n for (let x = 0; x < options.columns; x++) {\n const xColumn = field[x];\n if (!xColumn) {\n continue;\n }\n for (let y = 0; y < options.rows; y++) {\n const yColumn = xColumn[y];\n if (!yColumn) {\n continue;\n }\n for (let z = 0; z < options.layers; z++) {\n const cell = yColumn[z];\n if (!cell) {\n continue;\n }\n cell.length = noiseGen.noise4d(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, z * lengthFactor + options.offset.z, noiseW);\n cell.angle = noiseGen.noise4d(x * angleFactor, y * angleFactor, z * angleFactor, noiseW) * doublePI;\n }\n }\n }\n }\n _drawField(ctx) {\n const {\n field,\n options\n } = this;\n for (let x = 0; x < options.columns; x++) {\n const xColumn = field[x];\n if (!xColumn) {\n continue;\n }\n for (let y = 0; y < options.rows; y++) {\n const yColumn = xColumn[y];\n if (!yColumn) {\n continue;\n }\n const cell = yColumn[firstIndex];\n if (!cell) {\n continue;\n }\n const {\n angle,\n length\n } = cell;\n ctx.setTransform(transformDefaultValues.a, transformDefaultValues.b, transformDefaultValues.c, transformDefaultValues.d, x * this.options.size, y * this.options.size);\n ctx.rotate(angle);\n ctx.strokeStyle = \"white\";\n ctx.beginPath();\n ctx.moveTo(originCoordinate, originCoordinate);\n ctx.lineTo(originCoordinate, this.options.size * length);\n ctx.stroke();\n ctx.setTransform(transformDefaultValues.a, transformDefaultValues.b, transformDefaultValues.c, transformDefaultValues.d, transformDefaultValues.e, transformDefaultValues.f);\n }\n }\n }\n _initField() {\n const {\n columns,\n rows,\n layers\n } = this.options;\n this.field = new Array(columns);\n for (let x = 0; x < columns; x++) {\n const newX = new Array(rows);\n for (let y = 0; y < rows; y++) {\n const newY = new Array(layers);\n for (let z = 0; z < layers; z++) {\n newY[z] = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin;\n }\n newX[y] = newY;\n }\n this.field[x] = newX;\n }\n }\n _resetField() {\n const container = this.container;\n if (!container) {\n return;\n }\n const sourceOptions = container.actualOptions.particles.move.path.options,\n {\n options\n } = this;\n options.width = container.canvas.size.width;\n options.height = container.canvas.size.height;\n options.size = sourceOptions[\"size\"] > empty ? sourceOptions[\"size\"] : defaultOptions.size;\n options.increment = sourceOptions[\"increment\"] > empty ? sourceOptions[\"increment\"] : defaultOptions.increment;\n options.draw = !!sourceOptions[\"draw\"];\n const offset = sourceOptions[\"offset\"];\n options.offset.x = offset?.x ?? defaultOptions.offset.x;\n options.offset.y = offset?.y ?? defaultOptions.offset.y;\n options.offset.z = offset?.z ?? defaultOptions.offset.z;\n const factor = sourceOptions[\"factor\"];\n options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;\n options.factor.length = factor?.length ?? defaultOptions.factor.length;\n options.seed = sourceOptions[\"seed\"];\n this.noiseGen.seed(options.seed ?? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)());\n options.columns = Math.floor(options.width / options.size) + optionsSizeOffset;\n options.rows = Math.floor(options.height / options.size) + optionsSizeOffset;\n options.layers = Math.floor(container.zLayers / options.size) + optionsSizeOffset;\n this._initField();\n }\n _setup() {\n this.noiseW = 0;\n this._resetField();\n addEventListener(\"resize\", () => {\n this._resetField();\n });\n }\n}\n\n//# sourceURL=webpack://@tsparticles/noise-field/./dist/browser/NoiseFieldGenerator.js?\n}");
|
|
38
|
+
|
|
39
|
+
/***/ },
|
|
40
|
+
|
|
41
|
+
/***/ "./dist/browser/index.js"
|
|
42
|
+
/*!*******************************!*\
|
|
43
|
+
!*** ./dist/browser/index.js ***!
|
|
44
|
+
\*******************************/
|
|
45
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
46
|
+
|
|
47
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ NoiseFieldGenerator: () => (/* reexport safe */ _NoiseFieldGenerator_js__WEBPACK_IMPORTED_MODULE_0__.NoiseFieldGenerator)\n/* harmony export */ });\n/* harmony import */ var _NoiseFieldGenerator_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./NoiseFieldGenerator.js */ \"./dist/browser/NoiseFieldGenerator.js\");\n\n\n//# sourceURL=webpack://@tsparticles/noise-field/./dist/browser/index.js?\n}");
|
|
48
|
+
|
|
49
|
+
/***/ },
|
|
50
|
+
|
|
51
|
+
/***/ "@tsparticles/engine"
|
|
52
|
+
/*!*********************************************************************************************************************************!*\
|
|
53
|
+
!*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
|
|
54
|
+
\*********************************************************************************************************************************/
|
|
55
|
+
(module) {
|
|
56
|
+
|
|
57
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
58
|
+
|
|
59
|
+
/***/ }
|
|
60
|
+
|
|
61
|
+
/******/ });
|
|
62
|
+
/************************************************************************/
|
|
63
|
+
/******/ // The module cache
|
|
64
|
+
/******/ var __webpack_module_cache__ = {};
|
|
65
|
+
/******/
|
|
66
|
+
/******/ // The require function
|
|
67
|
+
/******/ function __webpack_require__(moduleId) {
|
|
68
|
+
/******/ // Check if module is in cache
|
|
69
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
70
|
+
/******/ if (cachedModule !== undefined) {
|
|
71
|
+
/******/ return cachedModule.exports;
|
|
72
|
+
/******/ }
|
|
73
|
+
/******/ // Check if module exists (development only)
|
|
74
|
+
/******/ if (__webpack_modules__[moduleId] === undefined) {
|
|
75
|
+
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
|
|
76
|
+
/******/ e.code = 'MODULE_NOT_FOUND';
|
|
77
|
+
/******/ throw e;
|
|
78
|
+
/******/ }
|
|
79
|
+
/******/ // Create a new module (and put it into the cache)
|
|
80
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
81
|
+
/******/ // no module.id needed
|
|
82
|
+
/******/ // no module.loaded needed
|
|
83
|
+
/******/ exports: {}
|
|
84
|
+
/******/ };
|
|
85
|
+
/******/
|
|
86
|
+
/******/ // Execute the module function
|
|
87
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
88
|
+
/******/
|
|
89
|
+
/******/ // Return the exports of the module
|
|
90
|
+
/******/ return module.exports;
|
|
91
|
+
/******/ }
|
|
92
|
+
/******/
|
|
93
|
+
/************************************************************************/
|
|
94
|
+
/******/ /* webpack/runtime/define property getters */
|
|
95
|
+
/******/ (() => {
|
|
96
|
+
/******/ // define getter functions for harmony exports
|
|
97
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
98
|
+
/******/ for(var key in definition) {
|
|
99
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
100
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
101
|
+
/******/ }
|
|
102
|
+
/******/ }
|
|
103
|
+
/******/ };
|
|
104
|
+
/******/ })();
|
|
105
|
+
/******/
|
|
106
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
107
|
+
/******/ (() => {
|
|
108
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
109
|
+
/******/ })();
|
|
110
|
+
/******/
|
|
111
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
112
|
+
/******/ (() => {
|
|
113
|
+
/******/ // define __esModule on exports
|
|
114
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
115
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
116
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
117
|
+
/******/ }
|
|
118
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
119
|
+
/******/ };
|
|
120
|
+
/******/ })();
|
|
121
|
+
/******/
|
|
122
|
+
/************************************************************************/
|
|
123
|
+
/******/
|
|
124
|
+
/******/ // startup
|
|
125
|
+
/******/ // Load entry module and return exports
|
|
126
|
+
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
127
|
+
/******/ var __webpack_exports__ = __webpack_require__("./dist/browser/index.js");
|
|
128
|
+
/******/
|
|
129
|
+
/******/ return __webpack_exports__;
|
|
130
|
+
/******/ })()
|
|
131
|
+
;
|
|
132
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.noise.field.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 s in o)("object"==typeof exports?exports:e)[s]=o[s]}}(this,(e=>(()=>{var t={303(t){t.exports=e}},o={};function s(e){var i=o[e];if(void 0!==i)return i.exports;var n=o[e]={exports:{}};return t[e](n,n.exports,s),n.exports}s.d=(e,t)=>{for(var o in t)s.o(t,o)&&!s.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};s.r(i),s.d(i,{NoiseFieldGenerator:()=>g});var n=s(303);const r=1,a=0,f=0,l=1,c=0,h=0,d=2*Math.PI,p={draw:!1,size:20,increment:.004,columns:0,rows:0,layers:0,width:0,height:0,factor:{angle:.02,length:.01},offset:{x:4e4,y:4e4,z:4e4}};class g{constructor(e){this.noiseGen=e,this.field=[],this.noiseW=0,this.options=(0,n.deepExtend)({},p)}generate(e){const t=e.getPosition(),{size:o}=this.options,s=Math.max(Math.floor(t.x/o),0),i=Math.max(Math.floor(t.y/o),0),r=Math.max(Math.floor(t.z/o),0),{field:a}=this,f=a[s]?.[i]?.[r];return f?f.copy():n.Vector.origin}init(e){this.container=e,this._setup()}reset(){}update(){this.container&&(this._calculateField(),this.noiseW+=this.options.increment,this.options.draw&&this.container.canvas.draw((e=>{this._drawField(e)})))}_calculateField(){const{field:e,noiseGen:t,options:o,noiseW:s}=this,i=o.factor.length,n=o.factor.angle;for(let r=0;r<o.columns;r++){const a=e[r];if(a)for(let e=0;e<o.rows;e++){const f=a[e];if(f)for(let a=0;a<o.layers;a++){const l=f[a];l&&(l.length=t.noise4d(r*i+o.offset.x,e*i+o.offset.y,a*i+o.offset.z,s),l.angle=t.noise4d(r*n,e*n,a*n,s)*d)}}}}_drawField(e){const{field:t,options:o}=this;for(let s=0;s<o.columns;s++){const i=t[s];if(i)for(let t=0;t<o.rows;t++){const o=i[t];if(!o)continue;const n=o[0];if(!n)continue;const{angle:d,length:p}=n;e.setTransform(r,a,f,l,s*this.options.size,t*this.options.size),e.rotate(d),e.strokeStyle="white",e.beginPath(),e.moveTo(0,0),e.lineTo(0,this.options.size*p),e.stroke(),e.setTransform(r,a,f,l,c,h)}}}_initField(){const{columns:e,rows:t,layers:o}=this.options;this.field=new Array(e);for(let s=0;s<e;s++){const e=new Array(t);for(let s=0;s<t;s++){const t=new Array(o);for(let e=0;e<o;e++)t[e]=n.Vector.origin;e[s]=t}this.field[s]=e}}_resetField(){const e=this.container;if(!e)return;const t=e.actualOptions.particles.move.path.options,{options:o}=this;o.width=e.canvas.size.width,o.height=e.canvas.size.height,o.size=t.size>0?t.size:p.size,o.increment=t.increment>0?t.increment:p.increment,o.draw=!!t.draw;const s=t.offset;o.offset.x=s?.x??p.offset.x,o.offset.y=s?.y??p.offset.y,o.offset.z=s?.z??p.offset.z;const i=t.factor;o.factor.angle=i?.angle??p.factor.angle,o.factor.length=i?.length??p.factor.length,o.seed=t.seed,this.noiseGen.seed(o.seed??(0,n.getRandom)()),o.columns=Math.floor(o.width/o.size)+1,o.rows=Math.floor(o.height/o.size)+1,o.layers=Math.floor(e.zLayers/o.size)+1,this._initField()}_setup(){this.noiseW=0,this._resetField(),addEventListener("resize",(()=>{this._resetField()}))}}return i})()));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Noise Field v4.0.0-alpha.0 by Matteo Bruni */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IFactorValues, IOffsetValues } from "./IFactorOffsetValues.js";
|
|
2
|
+
export interface INoiseFieldOptions {
|
|
3
|
+
columns: number;
|
|
4
|
+
draw: boolean;
|
|
5
|
+
factor: IFactorValues;
|
|
6
|
+
height: number;
|
|
7
|
+
increment: number;
|
|
8
|
+
layers: number;
|
|
9
|
+
offset: IOffsetValues;
|
|
10
|
+
rows: number;
|
|
11
|
+
seed?: number;
|
|
12
|
+
size: number;
|
|
13
|
+
width: number;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Container, type IMovePathGenerator, type Particle, Vector } from "@tsparticles/engine";
|
|
2
|
+
import type { INoiseFieldOptions } from "./INoiseFieldOptions.js";
|
|
3
|
+
import type { INoiseGenerator } from "./INoiseGenerator.js";
|
|
4
|
+
export declare abstract class NoiseFieldGenerator implements IMovePathGenerator {
|
|
5
|
+
container?: Container;
|
|
6
|
+
field: Vector[][][];
|
|
7
|
+
readonly noiseGen: INoiseGenerator;
|
|
8
|
+
noiseW: number;
|
|
9
|
+
readonly options: INoiseFieldOptions;
|
|
10
|
+
protected constructor(noiseGen: INoiseGenerator);
|
|
11
|
+
generate(particle: Particle): Vector;
|
|
12
|
+
init(container: Container): void;
|
|
13
|
+
reset(): void;
|
|
14
|
+
update(): void;
|
|
15
|
+
private _calculateField;
|
|
16
|
+
private _drawField;
|
|
17
|
+
private _initField;
|
|
18
|
+
private _resetField;
|
|
19
|
+
private _setup;
|
|
20
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { IFactorValues, IOffsetValues } from "./IFactorOffsetValues.js";
|
|
2
|
+
export type { INoiseFieldOptions } from "./INoiseFieldOptions.js";
|
|
3
|
+
export type { INoiseGenerator } from "./INoiseGenerator.js";
|
|
4
|
+
export { NoiseFieldGenerator } from "./NoiseFieldGenerator.js";
|
|
@@ -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
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
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.NoiseFieldGenerator = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const originCoordinate = 0, firstIndex = 0, empty = 0, optionsSizeOffset = 1, transformDefaultValues = {
|
|
15
|
+
a: 1,
|
|
16
|
+
b: 0,
|
|
17
|
+
c: 0,
|
|
18
|
+
d: 1,
|
|
19
|
+
e: 0,
|
|
20
|
+
f: 0,
|
|
21
|
+
}, double = 2, doublePI = Math.PI * double, defaultOptions = {
|
|
22
|
+
draw: false,
|
|
23
|
+
size: 20,
|
|
24
|
+
increment: 0.004,
|
|
25
|
+
columns: 0,
|
|
26
|
+
rows: 0,
|
|
27
|
+
layers: 0,
|
|
28
|
+
width: 0,
|
|
29
|
+
height: 0,
|
|
30
|
+
factor: {
|
|
31
|
+
angle: 0.02,
|
|
32
|
+
length: 0.01,
|
|
33
|
+
},
|
|
34
|
+
offset: {
|
|
35
|
+
x: 40000,
|
|
36
|
+
y: 40000,
|
|
37
|
+
z: 40000,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
class NoiseFieldGenerator {
|
|
41
|
+
constructor(noiseGen) {
|
|
42
|
+
this.noiseGen = noiseGen;
|
|
43
|
+
this.field = [];
|
|
44
|
+
this.noiseW = 0;
|
|
45
|
+
this.options = (0, engine_1.deepExtend)({}, defaultOptions);
|
|
46
|
+
}
|
|
47
|
+
generate(particle) {
|
|
48
|
+
const pos = particle.getPosition(), { size } = this.options, point = {
|
|
49
|
+
x: Math.max(Math.floor(pos.x / size), originCoordinate),
|
|
50
|
+
y: Math.max(Math.floor(pos.y / size), originCoordinate),
|
|
51
|
+
z: Math.max(Math.floor(pos.z / size), originCoordinate),
|
|
52
|
+
}, { field } = this, fieldPoint = field[point.x]?.[point.y]?.[point.z];
|
|
53
|
+
return fieldPoint ? fieldPoint.copy() : engine_1.Vector.origin;
|
|
54
|
+
}
|
|
55
|
+
init(container) {
|
|
56
|
+
this.container = container;
|
|
57
|
+
this._setup();
|
|
58
|
+
}
|
|
59
|
+
reset() {
|
|
60
|
+
}
|
|
61
|
+
update() {
|
|
62
|
+
if (!this.container) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this._calculateField();
|
|
66
|
+
this.noiseW += this.options.increment;
|
|
67
|
+
if (!this.options.draw) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.container.canvas.draw(ctx => {
|
|
71
|
+
this._drawField(ctx);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
_calculateField() {
|
|
75
|
+
const { field, noiseGen, options, noiseW } = this, lengthFactor = options.factor.length, angleFactor = options.factor.angle;
|
|
76
|
+
for (let x = 0; x < options.columns; x++) {
|
|
77
|
+
const xColumn = field[x];
|
|
78
|
+
if (!xColumn) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
for (let y = 0; y < options.rows; y++) {
|
|
82
|
+
const yColumn = xColumn[y];
|
|
83
|
+
if (!yColumn) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
for (let z = 0; z < options.layers; z++) {
|
|
87
|
+
const cell = yColumn[z];
|
|
88
|
+
if (!cell) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
cell.length = noiseGen.noise4d(x * lengthFactor + options.offset.x, y * lengthFactor + options.offset.y, z * lengthFactor + options.offset.z, noiseW);
|
|
92
|
+
cell.angle = noiseGen.noise4d(x * angleFactor, y * angleFactor, z * angleFactor, noiseW) * doublePI;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
_drawField(ctx) {
|
|
98
|
+
const { field, options } = this;
|
|
99
|
+
for (let x = 0; x < options.columns; x++) {
|
|
100
|
+
const xColumn = field[x];
|
|
101
|
+
if (!xColumn) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
for (let y = 0; y < options.rows; y++) {
|
|
105
|
+
const yColumn = xColumn[y];
|
|
106
|
+
if (!yColumn) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const cell = yColumn[firstIndex];
|
|
110
|
+
if (!cell) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const { angle, length } = cell;
|
|
114
|
+
ctx.setTransform(transformDefaultValues.a, transformDefaultValues.b, transformDefaultValues.c, transformDefaultValues.d, x * this.options.size, y * this.options.size);
|
|
115
|
+
ctx.rotate(angle);
|
|
116
|
+
ctx.strokeStyle = "white";
|
|
117
|
+
ctx.beginPath();
|
|
118
|
+
ctx.moveTo(originCoordinate, originCoordinate);
|
|
119
|
+
ctx.lineTo(originCoordinate, this.options.size * length);
|
|
120
|
+
ctx.stroke();
|
|
121
|
+
ctx.setTransform(transformDefaultValues.a, transformDefaultValues.b, transformDefaultValues.c, transformDefaultValues.d, transformDefaultValues.e, transformDefaultValues.f);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
_initField() {
|
|
126
|
+
const { columns, rows, layers } = this.options;
|
|
127
|
+
this.field = new Array(columns);
|
|
128
|
+
for (let x = 0; x < columns; x++) {
|
|
129
|
+
const newX = new Array(rows);
|
|
130
|
+
for (let y = 0; y < rows; y++) {
|
|
131
|
+
const newY = new Array(layers);
|
|
132
|
+
for (let z = 0; z < layers; z++) {
|
|
133
|
+
newY[z] = engine_1.Vector.origin;
|
|
134
|
+
}
|
|
135
|
+
newX[y] = newY;
|
|
136
|
+
}
|
|
137
|
+
this.field[x] = newX;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
_resetField() {
|
|
141
|
+
const container = this.container;
|
|
142
|
+
if (!container) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const sourceOptions = container.actualOptions.particles.move.path.options, { options } = this;
|
|
146
|
+
options.width = container.canvas.size.width;
|
|
147
|
+
options.height = container.canvas.size.height;
|
|
148
|
+
options.size =
|
|
149
|
+
sourceOptions["size"] > empty ? sourceOptions["size"] : defaultOptions.size;
|
|
150
|
+
options.increment =
|
|
151
|
+
sourceOptions["increment"] > empty
|
|
152
|
+
? sourceOptions["increment"]
|
|
153
|
+
: defaultOptions.increment;
|
|
154
|
+
options.draw = !!sourceOptions["draw"];
|
|
155
|
+
const offset = sourceOptions["offset"];
|
|
156
|
+
options.offset.x = offset?.x ?? defaultOptions.offset.x;
|
|
157
|
+
options.offset.y = offset?.y ?? defaultOptions.offset.y;
|
|
158
|
+
options.offset.z = offset?.z ?? defaultOptions.offset.z;
|
|
159
|
+
const factor = sourceOptions["factor"];
|
|
160
|
+
options.factor.angle = factor?.angle ?? defaultOptions.factor.angle;
|
|
161
|
+
options.factor.length = factor?.length ?? defaultOptions.factor.length;
|
|
162
|
+
options.seed = sourceOptions["seed"];
|
|
163
|
+
this.noiseGen.seed(options.seed ?? (0, engine_1.getRandom)());
|
|
164
|
+
options.columns = Math.floor(options.width / options.size) + optionsSizeOffset;
|
|
165
|
+
options.rows = Math.floor(options.height / options.size) + optionsSizeOffset;
|
|
166
|
+
options.layers = Math.floor(container.zLayers / options.size) + optionsSizeOffset;
|
|
167
|
+
this._initField();
|
|
168
|
+
}
|
|
169
|
+
_setup() {
|
|
170
|
+
this.noiseW = 0;
|
|
171
|
+
this._resetField();
|
|
172
|
+
addEventListener("resize", () => {
|
|
173
|
+
this._resetField();
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.NoiseFieldGenerator = NoiseFieldGenerator;
|
|
178
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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", "./NoiseFieldGenerator.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NoiseFieldGenerator = void 0;
|
|
13
|
+
var NoiseFieldGenerator_js_1 = require("./NoiseFieldGenerator.js");
|
|
14
|
+
Object.defineProperty(exports, "NoiseFieldGenerator", { enumerable: true, get: function () { return NoiseFieldGenerator_js_1.NoiseFieldGenerator; } });
|
|
15
|
+
});
|