@tsparticles/simplex-noise 4.0.5 → 4.1.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.
@@ -1,24 +1,24 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
2
  const quarter = 0.25;
3
3
  export class SimplexNoise4D {
4
- _NORM_4D;
5
- _SQUISH_4D;
6
- _STRETCH_4D;
7
- _base4D;
8
- _gradients4D;
9
- _lookup;
10
- _lookupPairs4D;
11
- _p4D;
12
- _perm;
13
- _perm4D;
4
+ #NORM_4D;
5
+ #SQUISH_4D;
6
+ #STRETCH_4D;
7
+ #base4D;
8
+ #gradients4D;
9
+ #lookup;
10
+ #lookupPairs4D;
11
+ #p4D;
12
+ #perm;
13
+ #perm4D;
14
14
  constructor() {
15
- this._NORM_4D = 1 / 30;
16
- this._SQUISH_4D = (Math.sqrt(4 + 1) - 1) * quarter;
17
- this._STRETCH_4D = (1 / Math.sqrt(4 + 1) - 1) * quarter;
18
- this._lookup = [];
19
- this._perm = new Uint8Array(0);
20
- this._perm4D = new Uint8Array(0);
21
- this._base4D = [
15
+ this.#NORM_4D = 1 / 30;
16
+ this.#SQUISH_4D = (Math.sqrt(4 + 1) - 1) * quarter;
17
+ this.#STRETCH_4D = (1 / Math.sqrt(4 + 1) - 1) * quarter;
18
+ this.#lookup = [];
19
+ this.#perm = new Uint8Array(0);
20
+ this.#perm4D = new Uint8Array(0);
21
+ this.#base4D = [
22
22
  [0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1],
23
23
  [3, 1, 1, 1, 0, 3, 1, 1, 0, 1, 3, 1, 0, 1, 1, 3, 0, 1, 1, 1, 4, 1, 1, 1, 1],
24
24
  [
@@ -126,7 +126,7 @@ export class SimplexNoise4D {
126
126
  1,
127
127
  ],
128
128
  ];
129
- this._gradients4D = [
129
+ this.#gradients4D = [
130
130
  3,
131
131
  1,
132
132
  1,
@@ -384,7 +384,7 @@ export class SimplexNoise4D {
384
384
  -1,
385
385
  -3,
386
386
  ];
387
- this._lookupPairs4D = [
387
+ this.#lookupPairs4D = [
388
388
  0,
389
389
  3,
390
390
  1,
@@ -1506,7 +1506,7 @@ export class SimplexNoise4D {
1506
1506
  599295,
1507
1507
  10,
1508
1508
  ];
1509
- this._p4D = [
1509
+ this.#p4D = [
1510
1510
  0,
1511
1511
  0,
1512
1512
  1,
@@ -2790,7 +2790,7 @@ export class SimplexNoise4D {
2790
2790
  ];
2791
2791
  }
2792
2792
  noise(x, y, z, w) {
2793
- const { _perm, _perm4D, _lookup, _STRETCH_4D, _SQUISH_4D, _gradients4D, _NORM_4D } = this, stretchOffset = (x + y + z + w) * _STRETCH_4D, xs = x + stretchOffset, ys = y + stretchOffset, zs = z + stretchOffset, ws = w + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), zsb = Math.floor(zs), wsb = Math.floor(ws), squishOffset = (xsb + ysb + zsb + wsb) * _SQUISH_4D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), dz0 = z - (zsb + squishOffset), dw0 = w - (wsb + squishOffset), xins = xs - xsb, yins = ys - ysb, zins = zs - zsb, wins = ws - wsb, inSum = xins + yins + zins + wins, hash = (zins - wins + 1) |
2793
+ const perm = this.#perm, perm4D = this.#perm4D, lookup = this.#lookup, STRETCH_4D = this.#STRETCH_4D, SQUISH_4D = this.#SQUISH_4D, gradients4D = this.#gradients4D, NORM_4D = this.#NORM_4D, stretchOffset = (x + y + z + w) * STRETCH_4D, xs = x + stretchOffset, ys = y + stretchOffset, zs = z + stretchOffset, ws = w + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), zsb = Math.floor(zs), wsb = Math.floor(ws), squishOffset = (xsb + ysb + zsb + wsb) * SQUISH_4D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), dz0 = z - (zsb + squishOffset), dw0 = w - (wsb + squishOffset), xins = xs - xsb, yins = ys - ysb, zins = zs - zsb, wins = ws - wsb, inSum = xins + yins + zins + wins, hash = (zins - wins + 1) |
2794
2794
  ((yins - zins + 1) << 1) |
2795
2795
  ((yins - wins + 1) << 2) |
2796
2796
  ((xins - yins + 1) << 3) |
@@ -2802,25 +2802,25 @@ export class SimplexNoise4D {
2802
2802
  ((inSum + yins) << 14) |
2803
2803
  ((inSum + xins) << 17);
2804
2804
  let value = 0;
2805
- for (let c = _lookup[hash]; c !== undefined; c = c.next) {
2805
+ for (let c = lookup[hash]; c !== undefined; c = c.next) {
2806
2806
  const dx = dx0 + c.dx, dy = dy0 + c.dy, dz = dz0 + c.dz, dw = dw0 + c.dw, attn = 2 - dx * dx - dy * dy - dz * dz - dw * dw;
2807
2807
  if (attn > 0) {
2808
- const px = xsb + c.xsb, py = ysb + c.ysb, pz = zsb + c.zsb, pw = wsb + c.wsb, indexPartA = _perm[px & 0xff], indexPartB = _perm[(indexPartA + py) & 0xff], indexPartC = _perm[(indexPartB + pz) & 0xff], index = _perm4D[(indexPartC + pw) & 0xff], valuePart = _gradients4D[index] * dx +
2809
- _gradients4D[index + 1] * dy +
2810
- _gradients4D[index + 2] * dz +
2811
- _gradients4D[index + 3] * dw;
2808
+ const px = xsb + c.xsb, py = ysb + c.ysb, pz = zsb + c.zsb, pw = wsb + c.wsb, indexPartA = perm[px & 0xff], indexPartB = perm[(indexPartA + py) & 0xff], indexPartC = perm[(indexPartB + pz) & 0xff], index = perm4D[(indexPartC + pw) & 0xff], valuePart = gradients4D[index] * dx +
2809
+ gradients4D[index + 1] * dy +
2810
+ gradients4D[index + 2] * dz +
2811
+ gradients4D[index + 3] * dw;
2812
2812
  value += attn * attn * attn * attn * valuePart;
2813
2813
  }
2814
2814
  }
2815
- return value * _NORM_4D;
2815
+ return value * NORM_4D;
2816
2816
  }
2817
2817
  seed(clientSeed) {
2818
- const { _p4D, _base4D, _lookupPairs4D } = this, contributions = [];
2819
- for (let i = 0; i < _p4D.length; i += 16) {
2820
- const baseSet = _base4D[_p4D[i]];
2818
+ const p4D = this.#p4D, base4D = this.#base4D, lookupPairs4D = this.#lookupPairs4D, contributions = [];
2819
+ for (let i = 0; i < p4D.length; i += 16) {
2820
+ const baseSet = base4D[p4D[i]];
2821
2821
  let previous = null, current = null;
2822
2822
  for (let k = 0; k < baseSet.length; k += 5) {
2823
- current = this._contribution4D(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3], baseSet[k + 4]);
2823
+ current = this.#contribution4D(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3], baseSet[k + 4]);
2824
2824
  if (previous === null) {
2825
2825
  contributions[i / 16] = current;
2826
2826
  }
@@ -2830,17 +2830,17 @@ export class SimplexNoise4D {
2830
2830
  previous = current;
2831
2831
  }
2832
2832
  if (current) {
2833
- current.next = this._contribution4D(_p4D[i + 1], _p4D[i + 2], _p4D[i + 3], _p4D[i + 4], _p4D[i + 5]);
2834
- current.next.next = this._contribution4D(_p4D[i + 6], _p4D[i + 7], _p4D[i + 8], _p4D[i + 9], _p4D[i + 10]);
2835
- current.next.next.next = this._contribution4D(_p4D[i + 11], _p4D[i + 12], _p4D[i + 13], _p4D[i + 14], _p4D[i + 15]);
2833
+ current.next = this.#contribution4D(p4D[i + 1], p4D[i + 2], p4D[i + 3], p4D[i + 4], p4D[i + 5]);
2834
+ current.next.next = this.#contribution4D(p4D[i + 6], p4D[i + 7], p4D[i + 8], p4D[i + 9], p4D[i + 10]);
2835
+ current.next.next.next = this.#contribution4D(p4D[i + 11], p4D[i + 12], p4D[i + 13], p4D[i + 14], p4D[i + 15]);
2836
2836
  }
2837
2837
  }
2838
- this._lookup = [];
2839
- for (let i = 0; i < _lookupPairs4D.length; i += 2) {
2840
- this._lookup[_lookupPairs4D[i]] = contributions[_lookupPairs4D[i + 1]];
2838
+ this.#lookup = [];
2839
+ for (let i = 0; i < lookupPairs4D.length; i += 2) {
2840
+ this.#lookup[lookupPairs4D[i]] = contributions[lookupPairs4D[i + 1]];
2841
2841
  }
2842
- this._perm = new Uint8Array(256);
2843
- this._perm4D = new Uint8Array(256);
2842
+ this.#perm = new Uint8Array(256);
2843
+ this.#perm4D = new Uint8Array(256);
2844
2844
  const source = new Uint8Array(256);
2845
2845
  for (let i = 0; i < 256; i++) {
2846
2846
  source[i] = i;
@@ -2855,18 +2855,18 @@ export class SimplexNoise4D {
2855
2855
  if (r[0] < 0) {
2856
2856
  r[0] += i + 1;
2857
2857
  }
2858
- this._perm[i] = source[r[0]];
2859
- this._perm4D[i] = this._perm[i] & 0xfc;
2858
+ this.#perm[i] = source[r[0]];
2859
+ this.#perm4D[i] = this.#perm[i] & 0xfc;
2860
2860
  source[r[0]] = source[i];
2861
2861
  }
2862
2862
  }
2863
- _contribution4D(multiplier, xsb, ysb, zsb, wsb) {
2864
- const { _SQUISH_4D } = this;
2863
+ #contribution4D(multiplier, xsb, ysb, zsb, wsb) {
2864
+ const SQUISH_4D = this.#SQUISH_4D;
2865
2865
  return {
2866
- dx: -xsb - multiplier * _SQUISH_4D,
2867
- dy: -ysb - multiplier * _SQUISH_4D,
2868
- dz: -zsb - multiplier * _SQUISH_4D,
2869
- dw: -wsb - multiplier * _SQUISH_4D,
2866
+ dx: -xsb - multiplier * SQUISH_4D,
2867
+ dy: -ysb - multiplier * SQUISH_4D,
2868
+ dz: -zsb - multiplier * SQUISH_4D,
2869
+ dw: -wsb - multiplier * SQUISH_4D,
2870
2870
  xsb,
2871
2871
  ysb,
2872
2872
  zsb,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/simplex-noise",
3
- "version": "4.0.5",
3
+ "version": "4.1.0",
4
4
  "description": "tsParticles simplex noise library",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
package/report.html CHANGED
@@ -4930,7 +4930,7 @@ var drawChart = (function (exports) {
4930
4930
  </script>
4931
4931
  <script>
4932
4932
  /*<!--*/
4933
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"tsparticles.simplex.noise.js","children":[{"name":"dist/browser","children":[{"uid":"0284bb1d-1","name":"utils.js"},{"name":"Classes","children":[{"uid":"0284bb1d-3","name":"SimplexNoise2D.js"},{"uid":"0284bb1d-5","name":"SimplexNoise3D.js"},{"uid":"0284bb1d-7","name":"SimplexNoise4D.js"}]},{"uid":"0284bb1d-9","name":"SimplexNoise.js"},{"uid":"0284bb1d-11","name":"browser.js"}]}]}],"isRoot":true},"nodeParts":{"0284bb1d-1":{"renderedLength":159,"gzipLength":0,"brotliLength":0,"metaUid":"0284bb1d-0"},"0284bb1d-3":{"renderedLength":5314,"gzipLength":0,"brotliLength":0,"metaUid":"0284bb1d-2"},"0284bb1d-5":{"renderedLength":13314,"gzipLength":0,"brotliLength":0,"metaUid":"0284bb1d-4"},"0284bb1d-7":{"renderedLength":61581,"gzipLength":0,"brotliLength":0,"metaUid":"0284bb1d-6"},"0284bb1d-9":{"renderedLength":262,"gzipLength":0,"brotliLength":0,"metaUid":"0284bb1d-8"},"0284bb1d-11":{"renderedLength":121,"gzipLength":0,"brotliLength":0,"metaUid":"0284bb1d-10"}},"nodeMetas":{"0284bb1d-0":{"id":"/dist/browser/utils.js","moduleParts":{"tsparticles.simplex.noise.js":"0284bb1d-1"},"imported":[],"importedBy":[{"uid":"0284bb1d-2"},{"uid":"0284bb1d-4"},{"uid":"0284bb1d-6"}]},"0284bb1d-2":{"id":"/dist/browser/Classes/SimplexNoise2D.js","moduleParts":{"tsparticles.simplex.noise.js":"0284bb1d-3"},"imported":[{"uid":"0284bb1d-0"}],"importedBy":[{"uid":"0284bb1d-8"}]},"0284bb1d-4":{"id":"/dist/browser/Classes/SimplexNoise3D.js","moduleParts":{"tsparticles.simplex.noise.js":"0284bb1d-5"},"imported":[{"uid":"0284bb1d-0"}],"importedBy":[{"uid":"0284bb1d-8"}]},"0284bb1d-6":{"id":"/dist/browser/Classes/SimplexNoise4D.js","moduleParts":{"tsparticles.simplex.noise.js":"0284bb1d-7"},"imported":[{"uid":"0284bb1d-0"}],"importedBy":[{"uid":"0284bb1d-8"}]},"0284bb1d-8":{"id":"/dist/browser/SimplexNoise.js","moduleParts":{"tsparticles.simplex.noise.js":"0284bb1d-9"},"imported":[{"uid":"0284bb1d-2"},{"uid":"0284bb1d-4"},{"uid":"0284bb1d-6"}],"importedBy":[{"uid":"0284bb1d-12"}]},"0284bb1d-10":{"id":"/dist/browser/browser.js","moduleParts":{"tsparticles.simplex.noise.js":"0284bb1d-11"},"imported":[{"uid":"0284bb1d-12"}],"importedBy":[],"isEntry":true},"0284bb1d-12":{"id":"/dist/browser/index.js","moduleParts":{},"imported":[{"uid":"0284bb1d-8"}],"importedBy":[{"uid":"0284bb1d-10"}]}},"env":{"rollup":"4.60.4"},"options":{"gzip":false,"brotli":false,"sourcemap":false}};
4933
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"tsparticles.simplex.noise.js","children":[{"name":"dist/browser","children":[{"uid":"34e3533c-1","name":"utils.js"},{"name":"Classes","children":[{"uid":"34e3533c-3","name":"SimplexNoise2D.js"},{"uid":"34e3533c-5","name":"SimplexNoise3D.js"},{"uid":"34e3533c-7","name":"SimplexNoise4D.js"}]},{"uid":"34e3533c-9","name":"SimplexNoise.js"},{"uid":"34e3533c-11","name":"browser.js"}]}]}],"isRoot":true},"nodeParts":{"34e3533c-1":{"renderedLength":159,"gzipLength":0,"brotliLength":0,"metaUid":"34e3533c-0"},"34e3533c-3":{"renderedLength":5434,"gzipLength":0,"brotliLength":0,"metaUid":"34e3533c-2"},"34e3533c-5":{"renderedLength":13426,"gzipLength":0,"brotliLength":0,"metaUid":"34e3533c-4"},"34e3533c-7":{"renderedLength":61683,"gzipLength":0,"brotliLength":0,"metaUid":"34e3533c-6"},"34e3533c-9":{"renderedLength":262,"gzipLength":0,"brotliLength":0,"metaUid":"34e3533c-8"},"34e3533c-11":{"renderedLength":121,"gzipLength":0,"brotliLength":0,"metaUid":"34e3533c-10"}},"nodeMetas":{"34e3533c-0":{"id":"/dist/browser/utils.js","moduleParts":{"tsparticles.simplex.noise.js":"34e3533c-1"},"imported":[],"importedBy":[{"uid":"34e3533c-2"},{"uid":"34e3533c-4"},{"uid":"34e3533c-6"}]},"34e3533c-2":{"id":"/dist/browser/Classes/SimplexNoise2D.js","moduleParts":{"tsparticles.simplex.noise.js":"34e3533c-3"},"imported":[{"uid":"34e3533c-0"}],"importedBy":[{"uid":"34e3533c-8"}]},"34e3533c-4":{"id":"/dist/browser/Classes/SimplexNoise3D.js","moduleParts":{"tsparticles.simplex.noise.js":"34e3533c-5"},"imported":[{"uid":"34e3533c-0"}],"importedBy":[{"uid":"34e3533c-8"}]},"34e3533c-6":{"id":"/dist/browser/Classes/SimplexNoise4D.js","moduleParts":{"tsparticles.simplex.noise.js":"34e3533c-7"},"imported":[{"uid":"34e3533c-0"}],"importedBy":[{"uid":"34e3533c-8"}]},"34e3533c-8":{"id":"/dist/browser/SimplexNoise.js","moduleParts":{"tsparticles.simplex.noise.js":"34e3533c-9"},"imported":[{"uid":"34e3533c-2"},{"uid":"34e3533c-4"},{"uid":"34e3533c-6"}],"importedBy":[{"uid":"34e3533c-12"}]},"34e3533c-10":{"id":"/dist/browser/browser.js","moduleParts":{"tsparticles.simplex.noise.js":"34e3533c-11"},"imported":[{"uid":"34e3533c-12"}],"importedBy":[],"isEntry":true},"34e3533c-12":{"id":"/dist/browser/index.js","moduleParts":{},"imported":[{"uid":"34e3533c-8"}],"importedBy":[{"uid":"34e3533c-10"}]}},"env":{"rollup":"4.60.4"},"options":{"gzip":false,"brotli":false,"sourcemap":false}};
4934
4934
 
4935
4935
  const run = () => {
4936
4936
  const width = window.innerWidth;