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