@tsparticles/perlin-noise 3.8.1 → 3.9.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/browser/Grad.js CHANGED
@@ -1,8 +1,9 @@
1
1
  export class Grad {
2
- constructor(x, y, z) {
2
+ constructor(x, y, z, w) {
3
3
  this.x = x;
4
4
  this.y = y;
5
5
  this.z = z;
6
+ this.w = w;
6
7
  }
7
8
  dot2(x, y) {
8
9
  return this.x * x + this.y * y;
@@ -10,4 +11,7 @@ export class Grad {
10
11
  dot3(x, y, z) {
11
12
  return this.dot2(x, y) + this.z * z;
12
13
  }
14
+ dot4(x, y, z, w) {
15
+ return this.dot3(x, y, z) + this.w * w;
16
+ }
13
17
  }
@@ -1,19 +1,39 @@
1
1
  import { Grad } from "./Grad.js";
2
2
  export class PerlinNoise {
3
3
  constructor() {
4
- this._grad3 = [
5
- new Grad(1, 1, 0),
6
- new Grad(-1, 1, 0),
7
- new Grad(1, -1, 0),
8
- new Grad(-1, -1, 0),
9
- new Grad(1, 0, 1),
10
- new Grad(-1, 0, 1),
11
- new Grad(1, 0, -1),
12
- new Grad(-1, 0, -1),
13
- new Grad(0, 1, 1),
14
- new Grad(0, -1, 1),
15
- new Grad(0, 1, -1),
16
- new Grad(0, -1, -1),
4
+ this._grad4 = [
5
+ new Grad(0, 1, 1, 1),
6
+ new Grad(0, 1, 1, -1),
7
+ new Grad(0, 1, -1, 1),
8
+ new Grad(0, 1, -1, -1),
9
+ new Grad(0, -1, 1, 1),
10
+ new Grad(0, -1, 1, -1),
11
+ new Grad(0, -1, -1, 1),
12
+ new Grad(0, -1, -1, -1),
13
+ new Grad(1, 0, 1, 1),
14
+ new Grad(1, 0, 1, -1),
15
+ new Grad(1, 0, -1, 1),
16
+ new Grad(1, 0, -1, -1),
17
+ new Grad(-1, 0, 1, 1),
18
+ new Grad(-1, 0, 1, -1),
19
+ new Grad(-1, 0, -1, 1),
20
+ new Grad(-1, 0, -1, -1),
21
+ new Grad(1, 1, 0, 1),
22
+ new Grad(1, 1, 0, -1),
23
+ new Grad(1, -1, 0, 1),
24
+ new Grad(1, -1, 0, -1),
25
+ new Grad(-1, 1, 0, 1),
26
+ new Grad(-1, 1, 0, -1),
27
+ new Grad(-1, -1, 0, 1),
28
+ new Grad(-1, -1, 0, -1),
29
+ new Grad(1, 1, 1, 0),
30
+ new Grad(1, 1, -1, 0),
31
+ new Grad(1, -1, 1, 0),
32
+ new Grad(1, -1, -1, 0),
33
+ new Grad(-1, 1, 1, 0),
34
+ new Grad(-1, 1, -1, 0),
35
+ new Grad(-1, -1, 1, 0),
36
+ new Grad(-1, -1, -1, 0),
17
37
  ];
18
38
  this._p = [
19
39
  151,
@@ -279,12 +299,11 @@ export class PerlinNoise {
279
299
  noise2d(x, y) {
280
300
  const { _gradP, _perm } = this;
281
301
  let X = Math.floor(x), Y = Math.floor(y);
282
- x = x - X;
283
- y = y - Y;
284
- X = X & 255;
285
- Y = Y & 255;
286
- const n00 = _gradP[X + _perm[Y]].dot2(x, y), n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1), n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y), n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1);
287
- const u = this._fade(x);
302
+ x -= X;
303
+ y -= Y;
304
+ X &= 255;
305
+ Y &= 255;
306
+ const n00 = _gradP[X + _perm[Y]].dot2(x, y), n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1), n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y), n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1), u = this._fade(x);
288
307
  return this._lerp(this._lerp(n00, n10, u), this._lerp(n01, n11, u), this._fade(y));
289
308
  }
290
309
  noise3d(x, y, z) {
@@ -299,8 +318,22 @@ export class PerlinNoise {
299
318
  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 = this._fade(x), v = this._fade(y), w = this._fade(z);
300
319
  return this._lerp(this._lerp(this._lerp(n000, n100, u), this._lerp(n001, n101, u), w), this._lerp(this._lerp(n010, n110, u), this._lerp(n011, n111, u), w), v);
301
320
  }
321
+ noise4d(x, y, z, w) {
322
+ const { _gradP: gradP, _perm: perm } = this;
323
+ let X = Math.floor(x), Y = Math.floor(y), Z = Math.floor(z), W = Math.floor(w);
324
+ x -= X;
325
+ y -= Y;
326
+ z -= Z;
327
+ w -= W;
328
+ X &= 255;
329
+ Y &= 255;
330
+ Z &= 255;
331
+ W &= 255;
332
+ const u = this._fade(x), v = this._fade(y), s = this._fade(z), t = this._fade(w), gi = (i, j, k, l) => gradP[X + i + perm[Y + j + perm[Z + k + perm[W + l]]]], n0000 = gi(0, 0, 0, 0).dot4(x, y, z, w), n0001 = gi(0, 0, 0, 1).dot4(x, y, z, w - 1), n0010 = gi(0, 0, 1, 0).dot4(x, y, z - 1, w), n0011 = gi(0, 0, 1, 1).dot4(x, y, z - 1, w - 1), n0100 = gi(0, 1, 0, 0).dot4(x, y - 1, z, w), n0101 = gi(0, 1, 0, 1).dot4(x, y - 1, z, w - 1), n0110 = gi(0, 1, 1, 0).dot4(x, y - 1, z - 1, w), n0111 = gi(0, 1, 1, 1).dot4(x, y - 1, z - 1, w - 1), n1000 = gi(1, 0, 0, 0).dot4(x - 1, y, z, w), n1001 = gi(1, 0, 0, 1).dot4(x - 1, y, z, w - 1), n1010 = gi(1, 0, 1, 0).dot4(x - 1, y, z - 1, w), n1011 = gi(1, 0, 1, 1).dot4(x - 1, y, z - 1, w - 1), n1100 = gi(1, 1, 0, 0).dot4(x - 1, y - 1, z, w), n1101 = gi(1, 1, 0, 1).dot4(x - 1, y - 1, z, w - 1), n1110 = gi(1, 1, 1, 0).dot4(x - 1, y - 1, z - 1, w), n1111 = gi(1, 1, 1, 1).dot4(x - 1, y - 1, z - 1, w - 1), x00 = this._lerp(n0000, n1000, u), x01 = this._lerp(n0001, n1001, u), x10 = this._lerp(n0010, n1010, u), x11 = this._lerp(n0011, n1011, u), y00 = this._lerp(x00, x10, s), y01 = this._lerp(x01, x11, s), x20 = this._lerp(n0100, n1100, u), x21 = this._lerp(n0101, n1101, u), x30 = this._lerp(n0110, n1110, u), x31 = this._lerp(n0111, n1111, u), y10 = this._lerp(x20, x30, s), y11 = this._lerp(x21, x31, s), z0 = this._lerp(y00, y10, v), z1 = this._lerp(y01, y11, v);
333
+ return this._lerp(z0, z1, t);
334
+ }
302
335
  seed(inputSeed) {
303
- const { _grad3: grad3, _gradP: gradP, _perm: perm, _p: p } = this;
336
+ const { _grad4: grad4, _gradP: gradP, _perm: perm, _p: p } = this;
304
337
  let seed = inputSeed;
305
338
  if (seed > 0 && seed < 1) {
306
339
  seed *= 65536;
@@ -309,10 +342,11 @@ export class PerlinNoise {
309
342
  if (seed < 256) {
310
343
  seed |= seed << 8;
311
344
  }
345
+ const grad4Length = grad4.length;
312
346
  for (let i = 0; i < 256; i++) {
313
347
  const v = i & 1 ? p[i] ^ (seed & 255) : p[i] ^ ((seed >> 8) & 255);
314
348
  perm[i] = perm[i + 256] = v;
315
- gradP[i] = gradP[i + 256] = grad3[v % 12];
349
+ gradP[i] = gradP[i + 256] = grad4[v % grad4Length];
316
350
  }
317
351
  }
318
352
  _fade(t) {
package/cjs/Grad.js CHANGED
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Grad = void 0;
4
4
  class Grad {
5
- constructor(x, y, z) {
5
+ constructor(x, y, z, w) {
6
6
  this.x = x;
7
7
  this.y = y;
8
8
  this.z = z;
9
+ this.w = w;
9
10
  }
10
11
  dot2(x, y) {
11
12
  return this.x * x + this.y * y;
@@ -13,5 +14,8 @@ class Grad {
13
14
  dot3(x, y, z) {
14
15
  return this.dot2(x, y) + this.z * z;
15
16
  }
17
+ dot4(x, y, z, w) {
18
+ return this.dot3(x, y, z) + this.w * w;
19
+ }
16
20
  }
17
21
  exports.Grad = Grad;
@@ -4,19 +4,39 @@ exports.PerlinNoise = void 0;
4
4
  const Grad_js_1 = require("./Grad.js");
5
5
  class PerlinNoise {
6
6
  constructor() {
7
- this._grad3 = [
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, -1, 0),
11
- new Grad_js_1.Grad(-1, -1, 0),
12
- new Grad_js_1.Grad(1, 0, 1),
13
- new Grad_js_1.Grad(-1, 0, 1),
14
- new Grad_js_1.Grad(1, 0, -1),
15
- new Grad_js_1.Grad(-1, 0, -1),
16
- new Grad_js_1.Grad(0, 1, 1),
17
- new Grad_js_1.Grad(0, -1, 1),
18
- new Grad_js_1.Grad(0, 1, -1),
19
- new Grad_js_1.Grad(0, -1, -1),
7
+ this._grad4 = [
8
+ new Grad_js_1.Grad(0, 1, 1, 1),
9
+ new Grad_js_1.Grad(0, 1, 1, -1),
10
+ new Grad_js_1.Grad(0, 1, -1, 1),
11
+ new Grad_js_1.Grad(0, 1, -1, -1),
12
+ new Grad_js_1.Grad(0, -1, 1, 1),
13
+ new Grad_js_1.Grad(0, -1, 1, -1),
14
+ new Grad_js_1.Grad(0, -1, -1, 1),
15
+ new Grad_js_1.Grad(0, -1, -1, -1),
16
+ new Grad_js_1.Grad(1, 0, 1, 1),
17
+ new Grad_js_1.Grad(1, 0, 1, -1),
18
+ new Grad_js_1.Grad(1, 0, -1, 1),
19
+ new Grad_js_1.Grad(1, 0, -1, -1),
20
+ new Grad_js_1.Grad(-1, 0, 1, 1),
21
+ new Grad_js_1.Grad(-1, 0, 1, -1),
22
+ new Grad_js_1.Grad(-1, 0, -1, 1),
23
+ new Grad_js_1.Grad(-1, 0, -1, -1),
24
+ new Grad_js_1.Grad(1, 1, 0, 1),
25
+ new Grad_js_1.Grad(1, 1, 0, -1),
26
+ new Grad_js_1.Grad(1, -1, 0, 1),
27
+ new Grad_js_1.Grad(1, -1, 0, -1),
28
+ new Grad_js_1.Grad(-1, 1, 0, 1),
29
+ new Grad_js_1.Grad(-1, 1, 0, -1),
30
+ new Grad_js_1.Grad(-1, -1, 0, 1),
31
+ new Grad_js_1.Grad(-1, -1, 0, -1),
32
+ new Grad_js_1.Grad(1, 1, 1, 0),
33
+ new Grad_js_1.Grad(1, 1, -1, 0),
34
+ new Grad_js_1.Grad(1, -1, 1, 0),
35
+ new Grad_js_1.Grad(1, -1, -1, 0),
36
+ new Grad_js_1.Grad(-1, 1, 1, 0),
37
+ new Grad_js_1.Grad(-1, 1, -1, 0),
38
+ new Grad_js_1.Grad(-1, -1, 1, 0),
39
+ new Grad_js_1.Grad(-1, -1, -1, 0),
20
40
  ];
21
41
  this._p = [
22
42
  151,
@@ -282,12 +302,11 @@ class PerlinNoise {
282
302
  noise2d(x, y) {
283
303
  const { _gradP, _perm } = this;
284
304
  let X = Math.floor(x), Y = Math.floor(y);
285
- x = x - X;
286
- y = y - Y;
287
- X = X & 255;
288
- Y = Y & 255;
289
- const n00 = _gradP[X + _perm[Y]].dot2(x, y), n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1), n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y), n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1);
290
- const u = this._fade(x);
305
+ x -= X;
306
+ y -= Y;
307
+ X &= 255;
308
+ Y &= 255;
309
+ const n00 = _gradP[X + _perm[Y]].dot2(x, y), n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1), n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y), n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1), u = this._fade(x);
291
310
  return this._lerp(this._lerp(n00, n10, u), this._lerp(n01, n11, u), this._fade(y));
292
311
  }
293
312
  noise3d(x, y, z) {
@@ -302,8 +321,22 @@ class PerlinNoise {
302
321
  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 = this._fade(x), v = this._fade(y), w = this._fade(z);
303
322
  return this._lerp(this._lerp(this._lerp(n000, n100, u), this._lerp(n001, n101, u), w), this._lerp(this._lerp(n010, n110, u), this._lerp(n011, n111, u), w), v);
304
323
  }
324
+ noise4d(x, y, z, w) {
325
+ const { _gradP: gradP, _perm: perm } = this;
326
+ let X = Math.floor(x), Y = Math.floor(y), Z = Math.floor(z), W = Math.floor(w);
327
+ x -= X;
328
+ y -= Y;
329
+ z -= Z;
330
+ w -= W;
331
+ X &= 255;
332
+ Y &= 255;
333
+ Z &= 255;
334
+ W &= 255;
335
+ const u = this._fade(x), v = this._fade(y), s = this._fade(z), t = this._fade(w), gi = (i, j, k, l) => gradP[X + i + perm[Y + j + perm[Z + k + perm[W + l]]]], n0000 = gi(0, 0, 0, 0).dot4(x, y, z, w), n0001 = gi(0, 0, 0, 1).dot4(x, y, z, w - 1), n0010 = gi(0, 0, 1, 0).dot4(x, y, z - 1, w), n0011 = gi(0, 0, 1, 1).dot4(x, y, z - 1, w - 1), n0100 = gi(0, 1, 0, 0).dot4(x, y - 1, z, w), n0101 = gi(0, 1, 0, 1).dot4(x, y - 1, z, w - 1), n0110 = gi(0, 1, 1, 0).dot4(x, y - 1, z - 1, w), n0111 = gi(0, 1, 1, 1).dot4(x, y - 1, z - 1, w - 1), n1000 = gi(1, 0, 0, 0).dot4(x - 1, y, z, w), n1001 = gi(1, 0, 0, 1).dot4(x - 1, y, z, w - 1), n1010 = gi(1, 0, 1, 0).dot4(x - 1, y, z - 1, w), n1011 = gi(1, 0, 1, 1).dot4(x - 1, y, z - 1, w - 1), n1100 = gi(1, 1, 0, 0).dot4(x - 1, y - 1, z, w), n1101 = gi(1, 1, 0, 1).dot4(x - 1, y - 1, z, w - 1), n1110 = gi(1, 1, 1, 0).dot4(x - 1, y - 1, z - 1, w), n1111 = gi(1, 1, 1, 1).dot4(x - 1, y - 1, z - 1, w - 1), x00 = this._lerp(n0000, n1000, u), x01 = this._lerp(n0001, n1001, u), x10 = this._lerp(n0010, n1010, u), x11 = this._lerp(n0011, n1011, u), y00 = this._lerp(x00, x10, s), y01 = this._lerp(x01, x11, s), x20 = this._lerp(n0100, n1100, u), x21 = this._lerp(n0101, n1101, u), x30 = this._lerp(n0110, n1110, u), x31 = this._lerp(n0111, n1111, u), y10 = this._lerp(x20, x30, s), y11 = this._lerp(x21, x31, s), z0 = this._lerp(y00, y10, v), z1 = this._lerp(y01, y11, v);
336
+ return this._lerp(z0, z1, t);
337
+ }
305
338
  seed(inputSeed) {
306
- const { _grad3: grad3, _gradP: gradP, _perm: perm, _p: p } = this;
339
+ const { _grad4: grad4, _gradP: gradP, _perm: perm, _p: p } = this;
307
340
  let seed = inputSeed;
308
341
  if (seed > 0 && seed < 1) {
309
342
  seed *= 65536;
@@ -312,10 +345,11 @@ class PerlinNoise {
312
345
  if (seed < 256) {
313
346
  seed |= seed << 8;
314
347
  }
348
+ const grad4Length = grad4.length;
315
349
  for (let i = 0; i < 256; i++) {
316
350
  const v = i & 1 ? p[i] ^ (seed & 255) : p[i] ^ ((seed >> 8) & 255);
317
351
  perm[i] = perm[i + 256] = v;
318
- gradP[i] = gradP[i + 256] = grad3[v % 12];
352
+ gradP[i] = gradP[i + 256] = grad4[v % grad4Length];
319
353
  }
320
354
  }
321
355
  _fade(t) {
package/esm/Grad.js CHANGED
@@ -1,8 +1,9 @@
1
1
  export class Grad {
2
- constructor(x, y, z) {
2
+ constructor(x, y, z, w) {
3
3
  this.x = x;
4
4
  this.y = y;
5
5
  this.z = z;
6
+ this.w = w;
6
7
  }
7
8
  dot2(x, y) {
8
9
  return this.x * x + this.y * y;
@@ -10,4 +11,7 @@ export class Grad {
10
11
  dot3(x, y, z) {
11
12
  return this.dot2(x, y) + this.z * z;
12
13
  }
14
+ dot4(x, y, z, w) {
15
+ return this.dot3(x, y, z) + this.w * w;
16
+ }
13
17
  }
@@ -1,19 +1,39 @@
1
1
  import { Grad } from "./Grad.js";
2
2
  export class PerlinNoise {
3
3
  constructor() {
4
- this._grad3 = [
5
- new Grad(1, 1, 0),
6
- new Grad(-1, 1, 0),
7
- new Grad(1, -1, 0),
8
- new Grad(-1, -1, 0),
9
- new Grad(1, 0, 1),
10
- new Grad(-1, 0, 1),
11
- new Grad(1, 0, -1),
12
- new Grad(-1, 0, -1),
13
- new Grad(0, 1, 1),
14
- new Grad(0, -1, 1),
15
- new Grad(0, 1, -1),
16
- new Grad(0, -1, -1),
4
+ this._grad4 = [
5
+ new Grad(0, 1, 1, 1),
6
+ new Grad(0, 1, 1, -1),
7
+ new Grad(0, 1, -1, 1),
8
+ new Grad(0, 1, -1, -1),
9
+ new Grad(0, -1, 1, 1),
10
+ new Grad(0, -1, 1, -1),
11
+ new Grad(0, -1, -1, 1),
12
+ new Grad(0, -1, -1, -1),
13
+ new Grad(1, 0, 1, 1),
14
+ new Grad(1, 0, 1, -1),
15
+ new Grad(1, 0, -1, 1),
16
+ new Grad(1, 0, -1, -1),
17
+ new Grad(-1, 0, 1, 1),
18
+ new Grad(-1, 0, 1, -1),
19
+ new Grad(-1, 0, -1, 1),
20
+ new Grad(-1, 0, -1, -1),
21
+ new Grad(1, 1, 0, 1),
22
+ new Grad(1, 1, 0, -1),
23
+ new Grad(1, -1, 0, 1),
24
+ new Grad(1, -1, 0, -1),
25
+ new Grad(-1, 1, 0, 1),
26
+ new Grad(-1, 1, 0, -1),
27
+ new Grad(-1, -1, 0, 1),
28
+ new Grad(-1, -1, 0, -1),
29
+ new Grad(1, 1, 1, 0),
30
+ new Grad(1, 1, -1, 0),
31
+ new Grad(1, -1, 1, 0),
32
+ new Grad(1, -1, -1, 0),
33
+ new Grad(-1, 1, 1, 0),
34
+ new Grad(-1, 1, -1, 0),
35
+ new Grad(-1, -1, 1, 0),
36
+ new Grad(-1, -1, -1, 0),
17
37
  ];
18
38
  this._p = [
19
39
  151,
@@ -279,12 +299,11 @@ export class PerlinNoise {
279
299
  noise2d(x, y) {
280
300
  const { _gradP, _perm } = this;
281
301
  let X = Math.floor(x), Y = Math.floor(y);
282
- x = x - X;
283
- y = y - Y;
284
- X = X & 255;
285
- Y = Y & 255;
286
- const n00 = _gradP[X + _perm[Y]].dot2(x, y), n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1), n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y), n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1);
287
- const u = this._fade(x);
302
+ x -= X;
303
+ y -= Y;
304
+ X &= 255;
305
+ Y &= 255;
306
+ const n00 = _gradP[X + _perm[Y]].dot2(x, y), n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1), n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y), n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1), u = this._fade(x);
288
307
  return this._lerp(this._lerp(n00, n10, u), this._lerp(n01, n11, u), this._fade(y));
289
308
  }
290
309
  noise3d(x, y, z) {
@@ -299,8 +318,22 @@ export class PerlinNoise {
299
318
  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 = this._fade(x), v = this._fade(y), w = this._fade(z);
300
319
  return this._lerp(this._lerp(this._lerp(n000, n100, u), this._lerp(n001, n101, u), w), this._lerp(this._lerp(n010, n110, u), this._lerp(n011, n111, u), w), v);
301
320
  }
321
+ noise4d(x, y, z, w) {
322
+ const { _gradP: gradP, _perm: perm } = this;
323
+ let X = Math.floor(x), Y = Math.floor(y), Z = Math.floor(z), W = Math.floor(w);
324
+ x -= X;
325
+ y -= Y;
326
+ z -= Z;
327
+ w -= W;
328
+ X &= 255;
329
+ Y &= 255;
330
+ Z &= 255;
331
+ W &= 255;
332
+ const u = this._fade(x), v = this._fade(y), s = this._fade(z), t = this._fade(w), gi = (i, j, k, l) => gradP[X + i + perm[Y + j + perm[Z + k + perm[W + l]]]], n0000 = gi(0, 0, 0, 0).dot4(x, y, z, w), n0001 = gi(0, 0, 0, 1).dot4(x, y, z, w - 1), n0010 = gi(0, 0, 1, 0).dot4(x, y, z - 1, w), n0011 = gi(0, 0, 1, 1).dot4(x, y, z - 1, w - 1), n0100 = gi(0, 1, 0, 0).dot4(x, y - 1, z, w), n0101 = gi(0, 1, 0, 1).dot4(x, y - 1, z, w - 1), n0110 = gi(0, 1, 1, 0).dot4(x, y - 1, z - 1, w), n0111 = gi(0, 1, 1, 1).dot4(x, y - 1, z - 1, w - 1), n1000 = gi(1, 0, 0, 0).dot4(x - 1, y, z, w), n1001 = gi(1, 0, 0, 1).dot4(x - 1, y, z, w - 1), n1010 = gi(1, 0, 1, 0).dot4(x - 1, y, z - 1, w), n1011 = gi(1, 0, 1, 1).dot4(x - 1, y, z - 1, w - 1), n1100 = gi(1, 1, 0, 0).dot4(x - 1, y - 1, z, w), n1101 = gi(1, 1, 0, 1).dot4(x - 1, y - 1, z, w - 1), n1110 = gi(1, 1, 1, 0).dot4(x - 1, y - 1, z - 1, w), n1111 = gi(1, 1, 1, 1).dot4(x - 1, y - 1, z - 1, w - 1), x00 = this._lerp(n0000, n1000, u), x01 = this._lerp(n0001, n1001, u), x10 = this._lerp(n0010, n1010, u), x11 = this._lerp(n0011, n1011, u), y00 = this._lerp(x00, x10, s), y01 = this._lerp(x01, x11, s), x20 = this._lerp(n0100, n1100, u), x21 = this._lerp(n0101, n1101, u), x30 = this._lerp(n0110, n1110, u), x31 = this._lerp(n0111, n1111, u), y10 = this._lerp(x20, x30, s), y11 = this._lerp(x21, x31, s), z0 = this._lerp(y00, y10, v), z1 = this._lerp(y01, y11, v);
333
+ return this._lerp(z0, z1, t);
334
+ }
302
335
  seed(inputSeed) {
303
- const { _grad3: grad3, _gradP: gradP, _perm: perm, _p: p } = this;
336
+ const { _grad4: grad4, _gradP: gradP, _perm: perm, _p: p } = this;
304
337
  let seed = inputSeed;
305
338
  if (seed > 0 && seed < 1) {
306
339
  seed *= 65536;
@@ -309,10 +342,11 @@ export class PerlinNoise {
309
342
  if (seed < 256) {
310
343
  seed |= seed << 8;
311
344
  }
345
+ const grad4Length = grad4.length;
312
346
  for (let i = 0; i < 256; i++) {
313
347
  const v = i & 1 ? p[i] ^ (seed & 255) : p[i] ^ ((seed >> 8) & 255);
314
348
  perm[i] = perm[i + 256] = v;
315
- gradP[i] = gradP[i + 256] = grad3[v % 12];
349
+ gradP[i] = gradP[i + 256] = grad4[v % grad4Length];
316
350
  }
317
351
  }
318
352
  _fade(t) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/perlin-noise",
3
- "version": "3.8.1",
3
+ "version": "3.9.0",
4
4
  "description": "tsParticles perlin noise library",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
package/report.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="UTF-8"/>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
- <title>@tsparticles/perlin-noise [31 Jan 2025 at 09:04]</title>
6
+ <title>@tsparticles/perlin-noise [1 Aug 2025 at 08:39]</title>
7
7
  <link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
8
8
 
9
9
  <script>
@@ -4,7 +4,7 @@
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.8.1
7
+ * v3.9.0
8
8
  */
9
9
  /*
10
10
  * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
@@ -34,7 +34,7 @@ return /******/ (() => { // webpackBootstrap
34
34
  \******************************/
35
35
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
36
36
 
37
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Grad: () => (/* binding */ Grad)\n/* harmony export */ });\nclass Grad {\n constructor(x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n }\n dot2(x, y) {\n return this.x * x + this.y * y;\n }\n dot3(x, y, z) {\n return this.dot2(x, y) + this.z * z;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/perlin-noise/./dist/browser/Grad.js?");
37
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Grad: () => (/* binding */ Grad)\n/* harmony export */ });\nclass Grad {\n constructor(x, y, z, w) {\n this.x = x;\n this.y = y;\n this.z = z;\n this.w = w;\n }\n dot2(x, y) {\n return this.x * x + this.y * y;\n }\n dot3(x, y, z) {\n return this.dot2(x, y) + this.z * z;\n }\n dot4(x, y, z, w) {\n return this.dot3(x, y, z) + this.w * w;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/perlin-noise/./dist/browser/Grad.js?\n}");
38
38
 
39
39
  /***/ }),
40
40
 
@@ -44,7 +44,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
44
44
  \*************************************/
45
45
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
46
46
 
47
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PerlinNoise: () => (/* binding */ PerlinNoise)\n/* harmony export */ });\n/* harmony import */ var _Grad_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Grad.js */ \"./dist/browser/Grad.js\");\n\nclass PerlinNoise {\n constructor() {\n this._grad3 = [new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, -1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, -1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 0, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 0, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 0, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 0, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, 1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, -1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, 1, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, -1, -1)];\n this._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];\n this._gradP = new Array(512);\n this._perm = new Array(512);\n }\n noise2d(x, y) {\n const {\n _gradP,\n _perm\n } = this;\n let X = Math.floor(x),\n Y = Math.floor(y);\n x = x - X;\n y = y - Y;\n X = X & 255;\n Y = Y & 255;\n const n00 = _gradP[X + _perm[Y]].dot2(x, y),\n n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1),\n n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y),\n n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1);\n const u = this._fade(x);\n return this._lerp(this._lerp(n00, n10, u), this._lerp(n01, n11, u), this._fade(y));\n }\n noise3d(x, y, z) {\n const {\n _gradP: gradP,\n _perm: perm\n } = this;\n let X = Math.floor(x),\n Y = Math.floor(y),\n Z = Math.floor(z);\n x = x - X;\n y = y - Y;\n z = z - Z;\n X = X & 255;\n Y = Y & 255;\n Z = Z & 255;\n const n000 = gradP[X + perm[Y + perm[Z]]].dot3(x, y, z),\n n001 = gradP[X + perm[Y + perm[Z + 1]]].dot3(x, y, z - 1),\n n010 = gradP[X + perm[Y + 1 + perm[Z]]].dot3(x, y - 1, z),\n n011 = gradP[X + perm[Y + 1 + perm[Z + 1]]].dot3(x, y - 1, z - 1),\n n100 = gradP[X + 1 + perm[Y + perm[Z]]].dot3(x - 1, y, z),\n n101 = gradP[X + 1 + perm[Y + perm[Z + 1]]].dot3(x - 1, y, z - 1),\n n110 = gradP[X + 1 + perm[Y + 1 + perm[Z]]].dot3(x - 1, y - 1, z),\n n111 = gradP[X + 1 + perm[Y + 1 + perm[Z + 1]]].dot3(x - 1, y - 1, z - 1),\n u = this._fade(x),\n v = this._fade(y),\n w = this._fade(z);\n return this._lerp(this._lerp(this._lerp(n000, n100, u), this._lerp(n001, n101, u), w), this._lerp(this._lerp(n010, n110, u), this._lerp(n011, n111, u), w), v);\n }\n seed(inputSeed) {\n const {\n _grad3: grad3,\n _gradP: gradP,\n _perm: perm,\n _p: p\n } = this;\n let seed = inputSeed;\n if (seed > 0 && seed < 1) {\n seed *= 65536;\n }\n seed = Math.floor(seed);\n if (seed < 256) {\n seed |= seed << 8;\n }\n for (let i = 0; i < 256; i++) {\n const v = i & 1 ? p[i] ^ seed & 255 : p[i] ^ seed >> 8 & 255;\n perm[i] = perm[i + 256] = v;\n gradP[i] = gradP[i + 256] = grad3[v % 12];\n }\n }\n _fade(t) {\n return t * t * t * (t * (t * 6 - 15) + 10);\n }\n _lerp(a, b, t) {\n return (1 - t) * a + t * b;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/perlin-noise/./dist/browser/PerlinNoise.js?");
47
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PerlinNoise: () => (/* binding */ PerlinNoise)\n/* harmony export */ });\n/* harmony import */ var _Grad_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Grad.js */ \"./dist/browser/Grad.js\");\n\nclass PerlinNoise {\n constructor() {\n this._grad4 = [new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, 1, 1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, 1, 1, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, 1, -1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, 1, -1, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, -1, 1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, -1, 1, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, -1, -1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(0, -1, -1, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 0, 1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 0, 1, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 0, -1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 0, -1, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 0, 1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 0, 1, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 0, -1, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 0, -1, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 1, 0, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 1, 0, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, -1, 0, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, -1, 0, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 1, 0, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 1, 0, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, -1, 0, 1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, -1, 0, -1), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 1, 1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, 1, -1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, -1, 1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(1, -1, -1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 1, 1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, 1, -1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, -1, 1, 0), new _Grad_js__WEBPACK_IMPORTED_MODULE_0__.Grad(-1, -1, -1, 0)];\n this._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];\n this._gradP = new Array(512);\n this._perm = new Array(512);\n }\n noise2d(x, y) {\n const {\n _gradP,\n _perm\n } = this;\n let X = Math.floor(x),\n Y = Math.floor(y);\n x -= X;\n y -= Y;\n X &= 255;\n Y &= 255;\n const n00 = _gradP[X + _perm[Y]].dot2(x, y),\n n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1),\n n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y),\n n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1),\n u = this._fade(x);\n return this._lerp(this._lerp(n00, n10, u), this._lerp(n01, n11, u), this._fade(y));\n }\n noise3d(x, y, z) {\n const {\n _gradP: gradP,\n _perm: perm\n } = this;\n let X = Math.floor(x),\n Y = Math.floor(y),\n Z = Math.floor(z);\n x = x - X;\n y = y - Y;\n z = z - Z;\n X = X & 255;\n Y = Y & 255;\n Z = Z & 255;\n const n000 = gradP[X + perm[Y + perm[Z]]].dot3(x, y, z),\n n001 = gradP[X + perm[Y + perm[Z + 1]]].dot3(x, y, z - 1),\n n010 = gradP[X + perm[Y + 1 + perm[Z]]].dot3(x, y - 1, z),\n n011 = gradP[X + perm[Y + 1 + perm[Z + 1]]].dot3(x, y - 1, z - 1),\n n100 = gradP[X + 1 + perm[Y + perm[Z]]].dot3(x - 1, y, z),\n n101 = gradP[X + 1 + perm[Y + perm[Z + 1]]].dot3(x - 1, y, z - 1),\n n110 = gradP[X + 1 + perm[Y + 1 + perm[Z]]].dot3(x - 1, y - 1, z),\n n111 = gradP[X + 1 + perm[Y + 1 + perm[Z + 1]]].dot3(x - 1, y - 1, z - 1),\n u = this._fade(x),\n v = this._fade(y),\n w = this._fade(z);\n return this._lerp(this._lerp(this._lerp(n000, n100, u), this._lerp(n001, n101, u), w), this._lerp(this._lerp(n010, n110, u), this._lerp(n011, n111, u), w), v);\n }\n noise4d(x, y, z, w) {\n const {\n _gradP: gradP,\n _perm: perm\n } = this;\n let X = Math.floor(x),\n Y = Math.floor(y),\n Z = Math.floor(z),\n W = Math.floor(w);\n x -= X;\n y -= Y;\n z -= Z;\n w -= W;\n X &= 255;\n Y &= 255;\n Z &= 255;\n W &= 255;\n const u = this._fade(x),\n v = this._fade(y),\n s = this._fade(z),\n t = this._fade(w),\n gi = (i, j, k, l) => gradP[X + i + perm[Y + j + perm[Z + k + perm[W + l]]]],\n n0000 = gi(0, 0, 0, 0).dot4(x, y, z, w),\n n0001 = gi(0, 0, 0, 1).dot4(x, y, z, w - 1),\n n0010 = gi(0, 0, 1, 0).dot4(x, y, z - 1, w),\n n0011 = gi(0, 0, 1, 1).dot4(x, y, z - 1, w - 1),\n n0100 = gi(0, 1, 0, 0).dot4(x, y - 1, z, w),\n n0101 = gi(0, 1, 0, 1).dot4(x, y - 1, z, w - 1),\n n0110 = gi(0, 1, 1, 0).dot4(x, y - 1, z - 1, w),\n n0111 = gi(0, 1, 1, 1).dot4(x, y - 1, z - 1, w - 1),\n n1000 = gi(1, 0, 0, 0).dot4(x - 1, y, z, w),\n n1001 = gi(1, 0, 0, 1).dot4(x - 1, y, z, w - 1),\n n1010 = gi(1, 0, 1, 0).dot4(x - 1, y, z - 1, w),\n n1011 = gi(1, 0, 1, 1).dot4(x - 1, y, z - 1, w - 1),\n n1100 = gi(1, 1, 0, 0).dot4(x - 1, y - 1, z, w),\n n1101 = gi(1, 1, 0, 1).dot4(x - 1, y - 1, z, w - 1),\n n1110 = gi(1, 1, 1, 0).dot4(x - 1, y - 1, z - 1, w),\n n1111 = gi(1, 1, 1, 1).dot4(x - 1, y - 1, z - 1, w - 1),\n x00 = this._lerp(n0000, n1000, u),\n x01 = this._lerp(n0001, n1001, u),\n x10 = this._lerp(n0010, n1010, u),\n x11 = this._lerp(n0011, n1011, u),\n y00 = this._lerp(x00, x10, s),\n y01 = this._lerp(x01, x11, s),\n x20 = this._lerp(n0100, n1100, u),\n x21 = this._lerp(n0101, n1101, u),\n x30 = this._lerp(n0110, n1110, u),\n x31 = this._lerp(n0111, n1111, u),\n y10 = this._lerp(x20, x30, s),\n y11 = this._lerp(x21, x31, s),\n z0 = this._lerp(y00, y10, v),\n z1 = this._lerp(y01, y11, v);\n return this._lerp(z0, z1, t);\n }\n seed(inputSeed) {\n const {\n _grad4: grad4,\n _gradP: gradP,\n _perm: perm,\n _p: p\n } = this;\n let seed = inputSeed;\n if (seed > 0 && seed < 1) {\n seed *= 65536;\n }\n seed = Math.floor(seed);\n if (seed < 256) {\n seed |= seed << 8;\n }\n const grad4Length = grad4.length;\n for (let i = 0; i < 256; i++) {\n const v = i & 1 ? p[i] ^ seed & 255 : p[i] ^ seed >> 8 & 255;\n perm[i] = perm[i + 256] = v;\n gradP[i] = gradP[i + 256] = grad4[v % grad4Length];\n }\n }\n _fade(t) {\n return t * t * t * (t * (t * 6 - 15) + 10);\n }\n _lerp(a, b, t) {\n return (1 - t) * a + t * b;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/perlin-noise/./dist/browser/PerlinNoise.js?\n}");
48
48
 
49
49
  /***/ }),
50
50
 
@@ -54,7 +54,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
54
54
  \*******************************/
55
55
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
56
56
 
57
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PerlinNoise: () => (/* reexport safe */ _PerlinNoise_js__WEBPACK_IMPORTED_MODULE_0__.PerlinNoise)\n/* harmony export */ });\n/* harmony import */ var _PerlinNoise_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PerlinNoise.js */ \"./dist/browser/PerlinNoise.js\");\n\n\n//# sourceURL=webpack://@tsparticles/perlin-noise/./dist/browser/index.js?");
57
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ PerlinNoise: () => (/* reexport safe */ _PerlinNoise_js__WEBPACK_IMPORTED_MODULE_0__.PerlinNoise)\n/* harmony export */ });\n/* harmony import */ var _PerlinNoise_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PerlinNoise.js */ \"./dist/browser/PerlinNoise.js\");\n\n\n//# sourceURL=webpack://@tsparticles/perlin-noise/./dist/browser/index.js?\n}");
58
58
 
59
59
  /***/ })
60
60
 
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.perlin.noise.min.js.LICENSE.txt */
2
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var o=t();for(var r in o)("object"==typeof exports?exports:e)[r]=o[r]}}(this,(()=>(()=>{var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{PerlinNoise:()=>r});class o{constructor(e,t,o){this.x=e,this.y=t,this.z=o}dot2(e,t){return this.x*e+this.y*t}dot3(e,t,o){return this.dot2(e,t)+this.z*o}}class r{constructor(){this._grad3=[new o(1,1,0),new o(-1,1,0),new o(1,-1,0),new o(-1,-1,0),new o(1,0,1),new o(-1,0,1),new o(1,0,-1),new o(-1,0,-1),new o(0,1,1),new o(0,-1,1),new o(0,1,-1),new o(0,-1,-1)],this._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],this._gradP=new Array(512),this._perm=new Array(512)}noise2d(e,t){const{_gradP:o,_perm:r}=this;let s=Math.floor(e),n=Math.floor(t);e-=s,t-=n,s&=255,n&=255;const i=o[s+r[n]].dot2(e,t),d=o[s+r[n+1]].dot2(e,t-1),l=o[s+1+r[n]].dot2(e-1,t),h=o[s+1+r[n+1]].dot2(e-1,t-1),a=this._fade(e);return this._lerp(this._lerp(i,l,a),this._lerp(d,h,a),this._fade(t))}noise3d(e,t,o){const{_gradP:r,_perm:s}=this;let n=Math.floor(e),i=Math.floor(t),d=Math.floor(o);e-=n,t-=i,o-=d,n&=255,i&=255,d&=255;const l=r[n+s[i+s[d]]].dot3(e,t,o),h=r[n+s[i+s[d+1]]].dot3(e,t,o-1),a=r[n+s[i+1+s[d]]].dot3(e,t-1,o),p=r[n+s[i+1+s[d+1]]].dot3(e,t-1,o-1),f=r[n+1+s[i+s[d]]].dot3(e-1,t,o),_=r[n+1+s[i+s[d+1]]].dot3(e-1,t,o-1),c=r[n+1+s[i+1+s[d]]].dot3(e-1,t-1,o),u=r[n+1+s[i+1+s[d+1]]].dot3(e-1,t-1,o-1),y=this._fade(e),w=this._fade(t),b=this._fade(o);return this._lerp(this._lerp(this._lerp(l,f,y),this._lerp(h,_,y),b),this._lerp(this._lerp(a,c,y),this._lerp(p,u,y),b),w)}seed(e){const{_grad3:t,_gradP:o,_perm:r,_p:s}=this;let n=e;n>0&&n<1&&(n*=65536),n=Math.floor(n),n<256&&(n|=n<<8);for(let e=0;e<256;e++){const i=1&e?s[e]^255&n:s[e]^n>>8&255;r[e]=r[e+256]=i,o[e]=o[e+256]=t[i%12]}}_fade(e){return e*e*e*(e*(6*e-15)+10)}_lerp(e,t,o){return(1-o)*e+o*t}}return t})()));
2
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o=e();for(var r in o)("object"==typeof exports?exports:t)[r]=o[r]}}(this,(()=>(()=>{var t={d:(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{PerlinNoise:()=>r});class o{constructor(t,e,o,r){this.x=t,this.y=e,this.z=o,this.w=r}dot2(t,e){return this.x*t+this.y*e}dot3(t,e,o){return this.dot2(t,e)+this.z*o}dot4(t,e,o,r){return this.dot3(t,e,o)+this.w*r}}class r{constructor(){this._grad4=[new o(0,1,1,1),new o(0,1,1,-1),new o(0,1,-1,1),new o(0,1,-1,-1),new o(0,-1,1,1),new o(0,-1,1,-1),new o(0,-1,-1,1),new o(0,-1,-1,-1),new o(1,0,1,1),new o(1,0,1,-1),new o(1,0,-1,1),new o(1,0,-1,-1),new o(-1,0,1,1),new o(-1,0,1,-1),new o(-1,0,-1,1),new o(-1,0,-1,-1),new o(1,1,0,1),new o(1,1,0,-1),new o(1,-1,0,1),new o(1,-1,0,-1),new o(-1,1,0,1),new o(-1,1,0,-1),new o(-1,-1,0,1),new o(-1,-1,0,-1),new o(1,1,1,0),new o(1,1,-1,0),new o(1,-1,1,0),new o(1,-1,-1,0),new o(-1,1,1,0),new o(-1,1,-1,0),new o(-1,-1,1,0),new o(-1,-1,-1,0)],this._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],this._gradP=new Array(512),this._perm=new Array(512)}noise2d(t,e){const{_gradP:o,_perm:r}=this;let s=Math.floor(t),n=Math.floor(e);t-=s,e-=n,s&=255,n&=255;const i=o[s+r[n]].dot2(t,e),d=o[s+r[n+1]].dot2(t,e-1),h=o[s+1+r[n]].dot2(t-1,e),l=o[s+1+r[n+1]].dot2(t-1,e-1),_=this._fade(t);return this._lerp(this._lerp(i,h,_),this._lerp(d,l,_),this._fade(e))}noise3d(t,e,o){const{_gradP:r,_perm:s}=this;let n=Math.floor(t),i=Math.floor(e),d=Math.floor(o);t-=n,e-=i,o-=d,n&=255,i&=255,d&=255;const h=r[n+s[i+s[d]]].dot3(t,e,o),l=r[n+s[i+s[d+1]]].dot3(t,e,o-1),_=r[n+s[i+1+s[d]]].dot3(t,e-1,o),p=r[n+s[i+1+s[d+1]]].dot3(t,e-1,o-1),a=r[n+1+s[i+s[d]]].dot3(t-1,e,o),f=r[n+1+s[i+s[d+1]]].dot3(t-1,e,o-1),w=r[n+1+s[i+1+s[d]]].dot3(t-1,e-1,o),c=r[n+1+s[i+1+s[d+1]]].dot3(t-1,e-1,o-1),u=this._fade(t),y=this._fade(e),g=this._fade(o);return this._lerp(this._lerp(this._lerp(h,a,u),this._lerp(l,f,u),g),this._lerp(this._lerp(_,w,u),this._lerp(p,c,u),g),y)}noise4d(t,e,o,r){const{_gradP:s,_perm:n}=this;let i=Math.floor(t),d=Math.floor(e),h=Math.floor(o),l=Math.floor(r);t-=i,e-=d,o-=h,r-=l,i&=255,d&=255,h&=255,l&=255;const _=this._fade(t),p=this._fade(e),a=this._fade(o),f=this._fade(r),w=(t,e,o,r)=>s[i+t+n[d+e+n[h+o+n[l+r]]]],c=w(0,0,0,0).dot4(t,e,o,r),u=w(0,0,0,1).dot4(t,e,o,r-1),y=w(0,0,1,0).dot4(t,e,o-1,r),g=w(0,0,1,1).dot4(t,e,o-1,r-1),m=w(0,1,0,0).dot4(t,e-1,o,r),M=w(0,1,0,1).dot4(t,e-1,o,r-1),b=w(0,1,1,0).dot4(t,e-1,o-1,r),P=w(0,1,1,1).dot4(t,e-1,o-1,r-1),j=w(1,0,0,0).dot4(t-1,e,o,r),v=w(1,0,0,1).dot4(t-1,e,o,r-1),x=w(1,0,1,0).dot4(t-1,e,o-1,r),O=w(1,0,1,1).dot4(t-1,e,o-1,r-1),S=w(1,1,0,0).dot4(t-1,e-1,o,r),z=w(1,1,0,1).dot4(t-1,e-1,o,r-1),A=w(1,1,1,0).dot4(t-1,e-1,o-1,r),T=w(1,1,1,1).dot4(t-1,e-1,o-1,r-1),N=this._lerp(c,j,_),k=this._lerp(u,v,_),q=this._lerp(y,x,_),B=this._lerp(g,O,_),C=this._lerp(N,q,a),D=this._lerp(k,B,a),E=this._lerp(m,S,_),F=this._lerp(M,z,_),G=this._lerp(b,A,_),H=this._lerp(P,T,_),I=this._lerp(E,G,a),J=this._lerp(F,H,a),K=this._lerp(C,I,p),L=this._lerp(D,J,p);return this._lerp(K,L,f)}seed(t){const{_grad4:e,_gradP:o,_perm:r,_p:s}=this;let n=t;n>0&&n<1&&(n*=65536),n=Math.floor(n),n<256&&(n|=n<<8);const i=e.length;for(let t=0;t<256;t++){const d=1&t?s[t]^255&n:s[t]^n>>8&255;r[t]=r[t+256]=d,o[t]=o[t+256]=e[d%i]}}_fade(t){return t*t*t*(t*(6*t-15)+10)}_lerp(t,e,o){return(1-o)*t+o*e}}return e})()));
@@ -1 +1 @@
1
- /*! tsParticles Perlin Noise v3.8.1 by Matteo Bruni */
1
+ /*! tsParticles Perlin Noise v3.9.0 by Matteo Bruni */
package/types/Grad.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  export declare class Grad {
2
+ readonly w: number;
2
3
  readonly x: number;
3
4
  readonly y: number;
4
5
  readonly z: number;
5
- constructor(x: number, y: number, z: number);
6
+ constructor(x: number, y: number, z: number, w: number);
6
7
  dot2(x: number, y: number): number;
7
8
  dot3(x: number, y: number, z: number): number;
9
+ dot4(x: number, y: number, z: number, w: number): number;
8
10
  }
@@ -1,11 +1,12 @@
1
1
  export declare class PerlinNoise {
2
- private readonly _grad3;
2
+ private readonly _grad4;
3
3
  private readonly _gradP;
4
4
  private readonly _p;
5
5
  private readonly _perm;
6
6
  constructor();
7
7
  noise2d(x: number, y: number): number;
8
8
  noise3d(x: number, y: number, z: number): number;
9
+ noise4d(x: number, y: number, z: number, w: number): number;
9
10
  seed(inputSeed: number): void;
10
11
  private _fade;
11
12
  private _lerp;
package/umd/Grad.js CHANGED
@@ -11,10 +11,11 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Grad = void 0;
13
13
  class Grad {
14
- constructor(x, y, z) {
14
+ constructor(x, y, z, w) {
15
15
  this.x = x;
16
16
  this.y = y;
17
17
  this.z = z;
18
+ this.w = w;
18
19
  }
19
20
  dot2(x, y) {
20
21
  return this.x * x + this.y * y;
@@ -22,6 +23,9 @@
22
23
  dot3(x, y, z) {
23
24
  return this.dot2(x, y) + this.z * z;
24
25
  }
26
+ dot4(x, y, z, w) {
27
+ return this.dot3(x, y, z) + this.w * w;
28
+ }
25
29
  }
26
30
  exports.Grad = Grad;
27
31
  });
@@ -13,19 +13,39 @@
13
13
  const Grad_js_1 = require("./Grad.js");
14
14
  class PerlinNoise {
15
15
  constructor() {
16
- this._grad3 = [
17
- new Grad_js_1.Grad(1, 1, 0),
18
- new Grad_js_1.Grad(-1, 1, 0),
19
- new Grad_js_1.Grad(1, -1, 0),
20
- new Grad_js_1.Grad(-1, -1, 0),
21
- new Grad_js_1.Grad(1, 0, 1),
22
- new Grad_js_1.Grad(-1, 0, 1),
23
- new Grad_js_1.Grad(1, 0, -1),
24
- new Grad_js_1.Grad(-1, 0, -1),
25
- new Grad_js_1.Grad(0, 1, 1),
26
- new Grad_js_1.Grad(0, -1, 1),
27
- new Grad_js_1.Grad(0, 1, -1),
28
- new Grad_js_1.Grad(0, -1, -1),
16
+ this._grad4 = [
17
+ new Grad_js_1.Grad(0, 1, 1, 1),
18
+ new Grad_js_1.Grad(0, 1, 1, -1),
19
+ new Grad_js_1.Grad(0, 1, -1, 1),
20
+ new Grad_js_1.Grad(0, 1, -1, -1),
21
+ new Grad_js_1.Grad(0, -1, 1, 1),
22
+ new Grad_js_1.Grad(0, -1, 1, -1),
23
+ new Grad_js_1.Grad(0, -1, -1, 1),
24
+ new Grad_js_1.Grad(0, -1, -1, -1),
25
+ new Grad_js_1.Grad(1, 0, 1, 1),
26
+ new Grad_js_1.Grad(1, 0, 1, -1),
27
+ new Grad_js_1.Grad(1, 0, -1, 1),
28
+ new Grad_js_1.Grad(1, 0, -1, -1),
29
+ new Grad_js_1.Grad(-1, 0, 1, 1),
30
+ new Grad_js_1.Grad(-1, 0, 1, -1),
31
+ new Grad_js_1.Grad(-1, 0, -1, 1),
32
+ new Grad_js_1.Grad(-1, 0, -1, -1),
33
+ new Grad_js_1.Grad(1, 1, 0, 1),
34
+ new Grad_js_1.Grad(1, 1, 0, -1),
35
+ new Grad_js_1.Grad(1, -1, 0, 1),
36
+ new Grad_js_1.Grad(1, -1, 0, -1),
37
+ new Grad_js_1.Grad(-1, 1, 0, 1),
38
+ new Grad_js_1.Grad(-1, 1, 0, -1),
39
+ new Grad_js_1.Grad(-1, -1, 0, 1),
40
+ new Grad_js_1.Grad(-1, -1, 0, -1),
41
+ new Grad_js_1.Grad(1, 1, 1, 0),
42
+ new Grad_js_1.Grad(1, 1, -1, 0),
43
+ new Grad_js_1.Grad(1, -1, 1, 0),
44
+ new Grad_js_1.Grad(1, -1, -1, 0),
45
+ new Grad_js_1.Grad(-1, 1, 1, 0),
46
+ new Grad_js_1.Grad(-1, 1, -1, 0),
47
+ new Grad_js_1.Grad(-1, -1, 1, 0),
48
+ new Grad_js_1.Grad(-1, -1, -1, 0),
29
49
  ];
30
50
  this._p = [
31
51
  151,
@@ -291,12 +311,11 @@
291
311
  noise2d(x, y) {
292
312
  const { _gradP, _perm } = this;
293
313
  let X = Math.floor(x), Y = Math.floor(y);
294
- x = x - X;
295
- y = y - Y;
296
- X = X & 255;
297
- Y = Y & 255;
298
- const n00 = _gradP[X + _perm[Y]].dot2(x, y), n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1), n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y), n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1);
299
- const u = this._fade(x);
314
+ x -= X;
315
+ y -= Y;
316
+ X &= 255;
317
+ Y &= 255;
318
+ const n00 = _gradP[X + _perm[Y]].dot2(x, y), n01 = _gradP[X + _perm[Y + 1]].dot2(x, y - 1), n10 = _gradP[X + 1 + _perm[Y]].dot2(x - 1, y), n11 = _gradP[X + 1 + _perm[Y + 1]].dot2(x - 1, y - 1), u = this._fade(x);
300
319
  return this._lerp(this._lerp(n00, n10, u), this._lerp(n01, n11, u), this._fade(y));
301
320
  }
302
321
  noise3d(x, y, z) {
@@ -311,8 +330,22 @@
311
330
  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 = this._fade(x), v = this._fade(y), w = this._fade(z);
312
331
  return this._lerp(this._lerp(this._lerp(n000, n100, u), this._lerp(n001, n101, u), w), this._lerp(this._lerp(n010, n110, u), this._lerp(n011, n111, u), w), v);
313
332
  }
333
+ noise4d(x, y, z, w) {
334
+ const { _gradP: gradP, _perm: perm } = this;
335
+ let X = Math.floor(x), Y = Math.floor(y), Z = Math.floor(z), W = Math.floor(w);
336
+ x -= X;
337
+ y -= Y;
338
+ z -= Z;
339
+ w -= W;
340
+ X &= 255;
341
+ Y &= 255;
342
+ Z &= 255;
343
+ W &= 255;
344
+ const u = this._fade(x), v = this._fade(y), s = this._fade(z), t = this._fade(w), gi = (i, j, k, l) => gradP[X + i + perm[Y + j + perm[Z + k + perm[W + l]]]], n0000 = gi(0, 0, 0, 0).dot4(x, y, z, w), n0001 = gi(0, 0, 0, 1).dot4(x, y, z, w - 1), n0010 = gi(0, 0, 1, 0).dot4(x, y, z - 1, w), n0011 = gi(0, 0, 1, 1).dot4(x, y, z - 1, w - 1), n0100 = gi(0, 1, 0, 0).dot4(x, y - 1, z, w), n0101 = gi(0, 1, 0, 1).dot4(x, y - 1, z, w - 1), n0110 = gi(0, 1, 1, 0).dot4(x, y - 1, z - 1, w), n0111 = gi(0, 1, 1, 1).dot4(x, y - 1, z - 1, w - 1), n1000 = gi(1, 0, 0, 0).dot4(x - 1, y, z, w), n1001 = gi(1, 0, 0, 1).dot4(x - 1, y, z, w - 1), n1010 = gi(1, 0, 1, 0).dot4(x - 1, y, z - 1, w), n1011 = gi(1, 0, 1, 1).dot4(x - 1, y, z - 1, w - 1), n1100 = gi(1, 1, 0, 0).dot4(x - 1, y - 1, z, w), n1101 = gi(1, 1, 0, 1).dot4(x - 1, y - 1, z, w - 1), n1110 = gi(1, 1, 1, 0).dot4(x - 1, y - 1, z - 1, w), n1111 = gi(1, 1, 1, 1).dot4(x - 1, y - 1, z - 1, w - 1), x00 = this._lerp(n0000, n1000, u), x01 = this._lerp(n0001, n1001, u), x10 = this._lerp(n0010, n1010, u), x11 = this._lerp(n0011, n1011, u), y00 = this._lerp(x00, x10, s), y01 = this._lerp(x01, x11, s), x20 = this._lerp(n0100, n1100, u), x21 = this._lerp(n0101, n1101, u), x30 = this._lerp(n0110, n1110, u), x31 = this._lerp(n0111, n1111, u), y10 = this._lerp(x20, x30, s), y11 = this._lerp(x21, x31, s), z0 = this._lerp(y00, y10, v), z1 = this._lerp(y01, y11, v);
345
+ return this._lerp(z0, z1, t);
346
+ }
314
347
  seed(inputSeed) {
315
- const { _grad3: grad3, _gradP: gradP, _perm: perm, _p: p } = this;
348
+ const { _grad4: grad4, _gradP: gradP, _perm: perm, _p: p } = this;
316
349
  let seed = inputSeed;
317
350
  if (seed > 0 && seed < 1) {
318
351
  seed *= 65536;
@@ -321,10 +354,11 @@
321
354
  if (seed < 256) {
322
355
  seed |= seed << 8;
323
356
  }
357
+ const grad4Length = grad4.length;
324
358
  for (let i = 0; i < 256; i++) {
325
359
  const v = i & 1 ? p[i] ^ (seed & 255) : p[i] ^ ((seed >> 8) & 255);
326
360
  perm[i] = perm[i + 256] = v;
327
- gradP[i] = gradP[i + 256] = grad3[v % 12];
361
+ gradP[i] = gradP[i + 256] = grad4[v % grad4Length];
328
362
  }
329
363
  }
330
364
  _fade(t) {