@tsparticles/path-perlin-noise 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 +70 -0
- package/browser/Grad.js +13 -0
- package/browser/IPerlinOptions.js +1 -0
- package/browser/PerlinNoise.js +74 -0
- package/browser/PerlinNoiseGenerator.js +99 -0
- package/browser/index.js +5 -0
- package/cjs/Grad.js +17 -0
- package/cjs/IPerlinOptions.js +2 -0
- package/cjs/PerlinNoise.js +78 -0
- package/cjs/PerlinNoiseGenerator.js +103 -0
- package/cjs/index.js +9 -0
- package/esm/Grad.js +13 -0
- package/esm/IPerlinOptions.js +1 -0
- package/esm/PerlinNoise.js +74 -0
- package/esm/PerlinNoiseGenerator.js +99 -0
- package/esm/index.js +5 -0
- package/package.json +92 -0
- package/report.html +39 -0
- package/tsparticles.path.perlin.noise.js +278 -0
- package/tsparticles.path.perlin.noise.min.js +2 -0
- package/tsparticles.path.perlin.noise.min.js.LICENSE.txt +8 -0
- package/types/Grad.d.ts +8 -0
- package/types/IPerlinOptions.d.ts +9 -0
- package/types/PerlinNoise.d.ts +4 -0
- package/types/PerlinNoiseGenerator.d.ts +21 -0
- package/types/index.d.ts +3 -0
- package/umd/Grad.js +27 -0
- package/umd/IPerlinOptions.js +12 -0
- package/umd/PerlinNoise.js +88 -0
- package/umd/PerlinNoiseGenerator.js +113 -0
- package/umd/index.js +19 -0
|
@@ -0,0 +1,278 @@
|
|
|
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
|
+
"loadPerlinNoisePath": () => (/* binding */ loadPerlinNoisePath),
|
|
95
|
+
"perlinNoisePathName": () => (/* binding */ perlinNoisePathName)
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
99
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
100
|
+
;// CONCATENATED MODULE: ./dist/browser/Grad.js
|
|
101
|
+
class Grad {
|
|
102
|
+
constructor(x, y, z) {
|
|
103
|
+
this.x = x;
|
|
104
|
+
this.y = y;
|
|
105
|
+
this.z = z;
|
|
106
|
+
}
|
|
107
|
+
dot2(x, y) {
|
|
108
|
+
return this.x * x + this.y * y;
|
|
109
|
+
}
|
|
110
|
+
dot3(x, y, z) {
|
|
111
|
+
return this.dot2(x, y) + this.z * z;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
;// CONCATENATED MODULE: ./dist/browser/PerlinNoise.js
|
|
115
|
+
|
|
116
|
+
const grad3 = [new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0), new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1), new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)];
|
|
117
|
+
const p = [151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180];
|
|
118
|
+
const perm = new Array(512);
|
|
119
|
+
const gradP = new Array(512);
|
|
120
|
+
function fade(t) {
|
|
121
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
122
|
+
}
|
|
123
|
+
function lerp(a, b, t) {
|
|
124
|
+
return (1 - t) * a + t * b;
|
|
125
|
+
}
|
|
126
|
+
class PerlinNoise {
|
|
127
|
+
noise(x, y, z) {
|
|
128
|
+
let X = Math.floor(x),
|
|
129
|
+
Y = Math.floor(y),
|
|
130
|
+
Z = Math.floor(z);
|
|
131
|
+
x = x - X;
|
|
132
|
+
y = y - Y;
|
|
133
|
+
z = z - Z;
|
|
134
|
+
X = X & 255;
|
|
135
|
+
Y = Y & 255;
|
|
136
|
+
Z = Z & 255;
|
|
137
|
+
const n000 = gradP[X + perm[Y + perm[Z]]].dot3(x, y, z);
|
|
138
|
+
const n001 = gradP[X + perm[Y + perm[Z + 1]]].dot3(x, y, z - 1);
|
|
139
|
+
const n010 = gradP[X + perm[Y + 1 + perm[Z]]].dot3(x, y - 1, z);
|
|
140
|
+
const n011 = gradP[X + perm[Y + 1 + perm[Z + 1]]].dot3(x, y - 1, z - 1);
|
|
141
|
+
const n100 = gradP[X + 1 + perm[Y + perm[Z]]].dot3(x - 1, y, z);
|
|
142
|
+
const n101 = gradP[X + 1 + perm[Y + perm[Z + 1]]].dot3(x - 1, y, z - 1);
|
|
143
|
+
const n110 = gradP[X + 1 + perm[Y + 1 + perm[Z]]].dot3(x - 1, y - 1, z);
|
|
144
|
+
const n111 = gradP[X + 1 + perm[Y + 1 + perm[Z + 1]]].dot3(x - 1, y - 1, z - 1);
|
|
145
|
+
const u = fade(x);
|
|
146
|
+
const v = fade(y);
|
|
147
|
+
const w = fade(z);
|
|
148
|
+
return lerp(lerp(lerp(n000, n100, u), lerp(n001, n101, u), w), lerp(lerp(n010, n110, u), lerp(n011, n111, u), w), v);
|
|
149
|
+
}
|
|
150
|
+
seed(inputSeed) {
|
|
151
|
+
let seed = inputSeed;
|
|
152
|
+
if (seed > 0 && seed < 1) {
|
|
153
|
+
seed *= 65536;
|
|
154
|
+
}
|
|
155
|
+
seed = Math.floor(seed);
|
|
156
|
+
if (seed < 256) {
|
|
157
|
+
seed |= seed << 8;
|
|
158
|
+
}
|
|
159
|
+
for (let i = 0; i < 256; i++) {
|
|
160
|
+
const v = i & 1 ? p[i] ^ seed & 255 : p[i] ^ seed >> 8 & 255;
|
|
161
|
+
perm[i] = perm[i + 256] = v;
|
|
162
|
+
gradP[i] = gradP[i + 256] = grad3[v % 12];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
;// CONCATENATED MODULE: ./dist/browser/PerlinNoiseGenerator.js
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class PerlinNoiseGenerator {
|
|
170
|
+
constructor() {
|
|
171
|
+
this.noiseGen = new PerlinNoise();
|
|
172
|
+
this.field = [];
|
|
173
|
+
this.noiseZ = 0;
|
|
174
|
+
this.options = {
|
|
175
|
+
draw: false,
|
|
176
|
+
size: 20,
|
|
177
|
+
increment: 0.004,
|
|
178
|
+
columns: 0,
|
|
179
|
+
rows: 0,
|
|
180
|
+
width: 0,
|
|
181
|
+
height: 0
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
generate(particle) {
|
|
185
|
+
const pos = particle.getPosition(),
|
|
186
|
+
point = {
|
|
187
|
+
x: Math.max(Math.floor(pos.x / this.options.size), 0),
|
|
188
|
+
y: Math.max(Math.floor(pos.y / this.options.size), 0)
|
|
189
|
+
},
|
|
190
|
+
v = engine_root_window_.Vector.origin;
|
|
191
|
+
if (!this.field || !this.field[point.x] || !this.field[point.x][point.y]) {
|
|
192
|
+
return v;
|
|
193
|
+
}
|
|
194
|
+
v.length = this.field[point.x][point.y][1];
|
|
195
|
+
v.angle = this.field[point.x][point.y][0];
|
|
196
|
+
return v;
|
|
197
|
+
}
|
|
198
|
+
init(container) {
|
|
199
|
+
this.container = container;
|
|
200
|
+
this.setup(container);
|
|
201
|
+
}
|
|
202
|
+
reset() {}
|
|
203
|
+
update() {
|
|
204
|
+
if (!this.container) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
this.calculateField();
|
|
208
|
+
this.noiseZ += this.options.increment;
|
|
209
|
+
if (this.options.draw) {
|
|
210
|
+
this.container.canvas.draw(ctx => this.drawField(ctx));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
calculateField() {
|
|
214
|
+
for (let x = 0; x < this.options.columns; x++) {
|
|
215
|
+
for (let y = 0; y < this.options.rows; y++) {
|
|
216
|
+
const angle = this.noiseGen.noise(x / 50, y / 50, this.noiseZ) * Math.PI * 2;
|
|
217
|
+
const length = this.noiseGen.noise(x / 100 + 40000, y / 100 + 40000, this.noiseZ);
|
|
218
|
+
this.field[x][y][0] = angle;
|
|
219
|
+
this.field[x][y][1] = length;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
drawField(ctx) {
|
|
224
|
+
for (let x = 0; x < this.options.columns; x++) {
|
|
225
|
+
for (let y = 0; y < this.options.rows; y++) {
|
|
226
|
+
const angle = this.field[x][y][0];
|
|
227
|
+
const length = this.field[x][y][1];
|
|
228
|
+
ctx.setTransform(1, 0, 0, 1, x * this.options.size, y * this.options.size);
|
|
229
|
+
ctx.rotate(angle);
|
|
230
|
+
ctx.strokeStyle = "white";
|
|
231
|
+
ctx.beginPath();
|
|
232
|
+
ctx.moveTo(0, 0);
|
|
233
|
+
ctx.lineTo(0, this.options.size * length);
|
|
234
|
+
ctx.stroke();
|
|
235
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
initField() {
|
|
240
|
+
this.field = new Array(this.options.columns);
|
|
241
|
+
for (let x = 0; x < this.options.columns; x++) {
|
|
242
|
+
this.field[x] = new Array(this.options.rows);
|
|
243
|
+
for (let y = 0; y < this.options.rows; y++) {
|
|
244
|
+
this.field[x][y] = [0, 0];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
resetField(container) {
|
|
249
|
+
var _a;
|
|
250
|
+
const sourceOptions = container.actualOptions.particles.move.path.options;
|
|
251
|
+
this.options.size = sourceOptions.size > 0 ? sourceOptions.size : 20;
|
|
252
|
+
this.options.increment = sourceOptions.increment > 0 ? sourceOptions.increment : 0.004;
|
|
253
|
+
this.options.draw = !!sourceOptions.draw;
|
|
254
|
+
this.options.width = container.canvas.size.width;
|
|
255
|
+
this.options.height = container.canvas.size.height;
|
|
256
|
+
this.noiseGen.seed((_a = sourceOptions.seed) !== null && _a !== void 0 ? _a : (0,engine_root_window_.getRandom)());
|
|
257
|
+
this.options.columns = Math.floor(this.options.width / this.options.size) + 1;
|
|
258
|
+
this.options.rows = Math.floor(this.options.height / this.options.size) + 1;
|
|
259
|
+
this.initField();
|
|
260
|
+
}
|
|
261
|
+
setup(container) {
|
|
262
|
+
this.noiseZ = 0;
|
|
263
|
+
this.resetField(container);
|
|
264
|
+
window.addEventListener("resize", () => this.resetField(container));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
268
|
+
|
|
269
|
+
const perlinNoisePathName = "perlinNoise";
|
|
270
|
+
function loadPerlinNoisePath(engine) {
|
|
271
|
+
engine.addPathGenerator(perlinNoisePathName, new PerlinNoiseGenerator());
|
|
272
|
+
}
|
|
273
|
+
})();
|
|
274
|
+
|
|
275
|
+
/******/ return __webpack_exports__;
|
|
276
|
+
/******/ })()
|
|
277
|
+
;
|
|
278
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.path.perlin.noise.min.js.LICENSE.txt */
|
|
2
|
+
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var o in i)("object"==typeof exports?exports:t)[o]=i[o]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},i={};function o(t){var s=i[t];if(void 0!==s)return s.exports;var n=i[t]={exports:{}};return e[t](n,n.exports,o),n.exports}o.d=(t,e)=>{for(var i in e)o.o(e,i)&&!o.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};return(()=>{o.r(s),o.d(s,{loadPerlinNoisePath:()=>f,perlinNoisePathName:()=>c});var t=o(533);class e{constructor(t,e,i){this.x=t,this.y=e,this.z=i}dot2(t,e){return this.x*t+this.y*e}dot3(t,e,i){return this.dot2(t,e)+this.z*i}}const i=[new e(1,1,0),new e(-1,1,0),new e(1,-1,0),new e(-1,-1,0),new e(1,0,1),new e(-1,0,1),new e(1,0,-1),new e(-1,0,-1),new e(0,1,1),new e(0,-1,1),new e(0,1,-1),new e(0,-1,-1)],n=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180],r=new Array(512),h=new Array(512);function l(t){return t*t*t*(t*(6*t-15)+10)}function a(t,e,i){return(1-i)*t+i*e}class d{noise(t,e,i){let o=Math.floor(t),s=Math.floor(e),n=Math.floor(i);t-=o,e-=s,i-=n,o&=255,s&=255,n&=255;const d=h[o+r[s+r[n]]].dot3(t,e,i),p=h[o+r[s+r[n+1]]].dot3(t,e,i-1),c=h[o+r[s+1+r[n]]].dot3(t,e-1,i),f=h[o+r[s+1+r[n+1]]].dot3(t,e-1,i-1),u=h[o+1+r[s+r[n]]].dot3(t-1,e,i),w=h[o+1+r[s+r[n+1]]].dot3(t-1,e,i-1),m=h[o+1+r[s+1+r[n]]].dot3(t-1,e-1,i),y=h[o+1+r[s+1+r[n+1]]].dot3(t-1,e-1,i-1),g=l(t),v=l(e),z=l(i);return a(a(a(d,u,g),a(p,w,g),z),a(a(c,m,g),a(f,y,g),z),v)}seed(t){let e=t;e>0&&e<1&&(e*=65536),e=Math.floor(e),e<256&&(e|=e<<8);for(let t=0;t<256;t++){const o=1&t?n[t]^255&e:n[t]^e>>8&255;r[t]=r[t+256]=o,h[t]=h[t+256]=i[o%12]}}}class p{constructor(){this.noiseGen=new d,this.field=[],this.noiseZ=0,this.options={draw:!1,size:20,increment:.004,columns:0,rows:0,width:0,height:0}}generate(e){const i=e.getPosition(),o=Math.max(Math.floor(i.x/this.options.size),0),s=Math.max(Math.floor(i.y/this.options.size),0),n=t.Vector.origin;return this.field&&this.field[o]&&this.field[o][s]?(n.length=this.field[o][s][1],n.angle=this.field[o][s][0],n):n}init(t){this.container=t,this.setup(t)}reset(){}update(){this.container&&(this.calculateField(),this.noiseZ+=this.options.increment,this.options.draw&&this.container.canvas.draw((t=>this.drawField(t))))}calculateField(){for(let t=0;t<this.options.columns;t++)for(let e=0;e<this.options.rows;e++){const i=this.noiseGen.noise(t/50,e/50,this.noiseZ)*Math.PI*2,o=this.noiseGen.noise(t/100+4e4,e/100+4e4,this.noiseZ);this.field[t][e][0]=i,this.field[t][e][1]=o}}drawField(t){for(let e=0;e<this.options.columns;e++)for(let i=0;i<this.options.rows;i++){const o=this.field[e][i][0],s=this.field[e][i][1];t.setTransform(1,0,0,1,e*this.options.size,i*this.options.size),t.rotate(o),t.strokeStyle="white",t.beginPath(),t.moveTo(0,0),t.lineTo(0,this.options.size*s),t.stroke(),t.setTransform(1,0,0,1,0,0)}}initField(){this.field=new Array(this.options.columns);for(let t=0;t<this.options.columns;t++){this.field[t]=new Array(this.options.rows);for(let e=0;e<this.options.rows;e++)this.field[t][e]=[0,0]}}resetField(e){var i;const o=e.actualOptions.particles.move.path.options;this.options.size=o.size>0?o.size:20,this.options.increment=o.increment>0?o.increment:.004,this.options.draw=!!o.draw,this.options.width=e.canvas.size.width,this.options.height=e.canvas.size.height,this.noiseGen.seed(null!==(i=o.seed)&&void 0!==i?i:(0,t.getRandom)()),this.options.columns=Math.floor(this.options.width/this.options.size)+1,this.options.rows=Math.floor(this.options.height/this.options.size)+1,this.initField()}setup(t){this.noiseZ=0,this.resetField(t),window.addEventListener("resize",(()=>this.resetField(t)))}}const c="perlinNoise";function f(t){t.addPathGenerator(c,new p)}})(),s})()));
|
package/types/Grad.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Container, IMovePathGenerator, Particle } from "@tsparticles/engine";
|
|
2
|
+
import { Vector } from "@tsparticles/engine";
|
|
3
|
+
import type { IPerlinOptions } from "./IPerlinOptions";
|
|
4
|
+
import { PerlinNoise } from "./PerlinNoise";
|
|
5
|
+
export declare class PerlinNoiseGenerator implements IMovePathGenerator {
|
|
6
|
+
container?: Container;
|
|
7
|
+
field: number[][][];
|
|
8
|
+
readonly noiseGen: PerlinNoise;
|
|
9
|
+
noiseZ: number;
|
|
10
|
+
readonly options: IPerlinOptions;
|
|
11
|
+
constructor();
|
|
12
|
+
generate(particle: Particle): Vector;
|
|
13
|
+
init(container: Container): void;
|
|
14
|
+
reset(): void;
|
|
15
|
+
update(): void;
|
|
16
|
+
private calculateField;
|
|
17
|
+
private drawField;
|
|
18
|
+
private initField;
|
|
19
|
+
private resetField;
|
|
20
|
+
private setup;
|
|
21
|
+
}
|
package/types/index.d.ts
ADDED
package/umd/Grad.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
exports.Grad = void 0;
|
|
13
|
+
class Grad {
|
|
14
|
+
constructor(x, y, z) {
|
|
15
|
+
this.x = x;
|
|
16
|
+
this.y = y;
|
|
17
|
+
this.z = z;
|
|
18
|
+
}
|
|
19
|
+
dot2(x, y) {
|
|
20
|
+
return this.x * x + this.y * y;
|
|
21
|
+
}
|
|
22
|
+
dot3(x, y, z) {
|
|
23
|
+
return this.dot2(x, y) + this.z * z;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.Grad = Grad;
|
|
27
|
+
});
|
|
@@ -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,88 @@
|
|
|
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", "./Grad"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PerlinNoise = void 0;
|
|
13
|
+
const Grad_1 = require("./Grad");
|
|
14
|
+
const grad3 = [
|
|
15
|
+
new Grad_1.Grad(1, 1, 0),
|
|
16
|
+
new Grad_1.Grad(-1, 1, 0),
|
|
17
|
+
new Grad_1.Grad(1, -1, 0),
|
|
18
|
+
new Grad_1.Grad(-1, -1, 0),
|
|
19
|
+
new Grad_1.Grad(1, 0, 1),
|
|
20
|
+
new Grad_1.Grad(-1, 0, 1),
|
|
21
|
+
new Grad_1.Grad(1, 0, -1),
|
|
22
|
+
new Grad_1.Grad(-1, 0, -1),
|
|
23
|
+
new Grad_1.Grad(0, 1, 1),
|
|
24
|
+
new Grad_1.Grad(0, -1, 1),
|
|
25
|
+
new Grad_1.Grad(0, 1, -1),
|
|
26
|
+
new Grad_1.Grad(0, -1, -1),
|
|
27
|
+
];
|
|
28
|
+
const p = [
|
|
29
|
+
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240,
|
|
30
|
+
21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88,
|
|
31
|
+
237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83,
|
|
32
|
+
111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80,
|
|
33
|
+
73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64,
|
|
34
|
+
52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182,
|
|
35
|
+
189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22,
|
|
36
|
+
39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210,
|
|
37
|
+
144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84,
|
|
38
|
+
204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78,
|
|
39
|
+
66, 215, 61, 156, 180,
|
|
40
|
+
];
|
|
41
|
+
const perm = new Array(512);
|
|
42
|
+
const gradP = new Array(512);
|
|
43
|
+
function fade(t) {
|
|
44
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
45
|
+
}
|
|
46
|
+
function lerp(a, b, t) {
|
|
47
|
+
return (1 - t) * a + t * b;
|
|
48
|
+
}
|
|
49
|
+
class PerlinNoise {
|
|
50
|
+
noise(x, y, z) {
|
|
51
|
+
let X = Math.floor(x), Y = Math.floor(y), Z = Math.floor(z);
|
|
52
|
+
x = x - X;
|
|
53
|
+
y = y - Y;
|
|
54
|
+
z = z - Z;
|
|
55
|
+
X = X & 255;
|
|
56
|
+
Y = Y & 255;
|
|
57
|
+
Z = Z & 255;
|
|
58
|
+
const n000 = gradP[X + perm[Y + perm[Z]]].dot3(x, y, z);
|
|
59
|
+
const n001 = gradP[X + perm[Y + perm[Z + 1]]].dot3(x, y, z - 1);
|
|
60
|
+
const n010 = gradP[X + perm[Y + 1 + perm[Z]]].dot3(x, y - 1, z);
|
|
61
|
+
const n011 = gradP[X + perm[Y + 1 + perm[Z + 1]]].dot3(x, y - 1, z - 1);
|
|
62
|
+
const n100 = gradP[X + 1 + perm[Y + perm[Z]]].dot3(x - 1, y, z);
|
|
63
|
+
const n101 = gradP[X + 1 + perm[Y + perm[Z + 1]]].dot3(x - 1, y, z - 1);
|
|
64
|
+
const n110 = gradP[X + 1 + perm[Y + 1 + perm[Z]]].dot3(x - 1, y - 1, z);
|
|
65
|
+
const n111 = gradP[X + 1 + perm[Y + 1 + perm[Z + 1]]].dot3(x - 1, y - 1, z - 1);
|
|
66
|
+
const u = fade(x);
|
|
67
|
+
const v = fade(y);
|
|
68
|
+
const w = fade(z);
|
|
69
|
+
return lerp(lerp(lerp(n000, n100, u), lerp(n001, n101, u), w), lerp(lerp(n010, n110, u), lerp(n011, n111, u), w), v);
|
|
70
|
+
}
|
|
71
|
+
seed(inputSeed) {
|
|
72
|
+
let seed = inputSeed;
|
|
73
|
+
if (seed > 0 && seed < 1) {
|
|
74
|
+
seed *= 65536;
|
|
75
|
+
}
|
|
76
|
+
seed = Math.floor(seed);
|
|
77
|
+
if (seed < 256) {
|
|
78
|
+
seed |= seed << 8;
|
|
79
|
+
}
|
|
80
|
+
for (let i = 0; i < 256; i++) {
|
|
81
|
+
const v = i & 1 ? p[i] ^ (seed & 255) : p[i] ^ ((seed >> 8) & 255);
|
|
82
|
+
perm[i] = perm[i + 256] = v;
|
|
83
|
+
gradP[i] = gradP[i + 256] = grad3[v % 12];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.PerlinNoise = PerlinNoise;
|
|
88
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
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", "./PerlinNoise"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PerlinNoiseGenerator = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const PerlinNoise_1 = require("./PerlinNoise");
|
|
15
|
+
class PerlinNoiseGenerator {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.noiseGen = new PerlinNoise_1.PerlinNoise();
|
|
18
|
+
this.field = [];
|
|
19
|
+
this.noiseZ = 0;
|
|
20
|
+
this.options = {
|
|
21
|
+
draw: false,
|
|
22
|
+
size: 20,
|
|
23
|
+
increment: 0.004,
|
|
24
|
+
columns: 0,
|
|
25
|
+
rows: 0,
|
|
26
|
+
width: 0,
|
|
27
|
+
height: 0,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
generate(particle) {
|
|
31
|
+
const pos = particle.getPosition(), point = {
|
|
32
|
+
x: Math.max(Math.floor(pos.x / this.options.size), 0),
|
|
33
|
+
y: Math.max(Math.floor(pos.y / this.options.size), 0),
|
|
34
|
+
}, v = engine_1.Vector.origin;
|
|
35
|
+
if (!this.field || !this.field[point.x] || !this.field[point.x][point.y]) {
|
|
36
|
+
return v;
|
|
37
|
+
}
|
|
38
|
+
v.length = this.field[point.x][point.y][1];
|
|
39
|
+
v.angle = this.field[point.x][point.y][0];
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
init(container) {
|
|
43
|
+
this.container = container;
|
|
44
|
+
this.setup(container);
|
|
45
|
+
}
|
|
46
|
+
reset() {
|
|
47
|
+
}
|
|
48
|
+
update() {
|
|
49
|
+
if (!this.container) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.calculateField();
|
|
53
|
+
this.noiseZ += this.options.increment;
|
|
54
|
+
if (this.options.draw) {
|
|
55
|
+
this.container.canvas.draw((ctx) => this.drawField(ctx));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
calculateField() {
|
|
59
|
+
for (let x = 0; x < this.options.columns; x++) {
|
|
60
|
+
for (let y = 0; y < this.options.rows; y++) {
|
|
61
|
+
const angle = this.noiseGen.noise(x / 50, y / 50, this.noiseZ) * Math.PI * 2;
|
|
62
|
+
const length = this.noiseGen.noise(x / 100 + 40000, y / 100 + 40000, this.noiseZ);
|
|
63
|
+
this.field[x][y][0] = angle;
|
|
64
|
+
this.field[x][y][1] = length;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
drawField(ctx) {
|
|
69
|
+
for (let x = 0; x < this.options.columns; x++) {
|
|
70
|
+
for (let y = 0; y < this.options.rows; y++) {
|
|
71
|
+
const angle = this.field[x][y][0];
|
|
72
|
+
const length = this.field[x][y][1];
|
|
73
|
+
ctx.setTransform(1, 0, 0, 1, x * this.options.size, y * this.options.size);
|
|
74
|
+
ctx.rotate(angle);
|
|
75
|
+
ctx.strokeStyle = "white";
|
|
76
|
+
ctx.beginPath();
|
|
77
|
+
ctx.moveTo(0, 0);
|
|
78
|
+
ctx.lineTo(0, this.options.size * length);
|
|
79
|
+
ctx.stroke();
|
|
80
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
initField() {
|
|
85
|
+
this.field = new Array(this.options.columns);
|
|
86
|
+
for (let x = 0; x < this.options.columns; x++) {
|
|
87
|
+
this.field[x] = new Array(this.options.rows);
|
|
88
|
+
for (let y = 0; y < this.options.rows; y++) {
|
|
89
|
+
this.field[x][y] = [0, 0];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
resetField(container) {
|
|
94
|
+
var _a;
|
|
95
|
+
const sourceOptions = container.actualOptions.particles.move.path.options;
|
|
96
|
+
this.options.size = sourceOptions.size > 0 ? sourceOptions.size : 20;
|
|
97
|
+
this.options.increment = sourceOptions.increment > 0 ? sourceOptions.increment : 0.004;
|
|
98
|
+
this.options.draw = !!sourceOptions.draw;
|
|
99
|
+
this.options.width = container.canvas.size.width;
|
|
100
|
+
this.options.height = container.canvas.size.height;
|
|
101
|
+
this.noiseGen.seed((_a = sourceOptions.seed) !== null && _a !== void 0 ? _a : (0, engine_1.getRandom)());
|
|
102
|
+
this.options.columns = Math.floor(this.options.width / this.options.size) + 1;
|
|
103
|
+
this.options.rows = Math.floor(this.options.height / this.options.size) + 1;
|
|
104
|
+
this.initField();
|
|
105
|
+
}
|
|
106
|
+
setup(container) {
|
|
107
|
+
this.noiseZ = 0;
|
|
108
|
+
this.resetField(container);
|
|
109
|
+
window.addEventListener("resize", () => this.resetField(container));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.PerlinNoiseGenerator = PerlinNoiseGenerator;
|
|
113
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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", "./PerlinNoiseGenerator"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadPerlinNoisePath = exports.perlinNoisePathName = void 0;
|
|
13
|
+
const PerlinNoiseGenerator_1 = require("./PerlinNoiseGenerator");
|
|
14
|
+
exports.perlinNoisePathName = "perlinNoise";
|
|
15
|
+
function loadPerlinNoisePath(engine) {
|
|
16
|
+
engine.addPathGenerator(exports.perlinNoisePathName, new PerlinNoiseGenerator_1.PerlinNoiseGenerator());
|
|
17
|
+
}
|
|
18
|
+
exports.loadPerlinNoisePath = loadPerlinNoisePath;
|
|
19
|
+
});
|