@tsparticles/simplex-noise 4.0.0-alpha.8 → 4.0.0-beta.1

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,9 +1,20 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
+ const half = 0.5;
2
3
  export class SimplexNoise2D {
4
+ _NORM_2D;
5
+ _SQUISH_2D;
6
+ _STRETCH_2D;
7
+ _base2D;
8
+ _gradients2D;
9
+ _lookup;
10
+ _lookupPairs2D;
11
+ _p2D;
12
+ _perm;
13
+ _perm2D;
3
14
  constructor() {
4
- this._NORM_2D = 1.0 / 47.0;
5
- this._SQUISH_2D = (Math.sqrt(2 + 1) - 1) / 2;
6
- this._STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) / 2;
15
+ this._NORM_2D = 1 / 47;
16
+ this._SQUISH_2D = (Math.sqrt(2 + 1) - 1) * half;
17
+ this._STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) * half;
7
18
  this._base2D = [
8
19
  [1, 1, 0, 1, 0, 1, 0, 0, 0],
9
20
  [1, 1, 0, 1, 0, 1, 2, 1, 1],
@@ -83,21 +94,20 @@ export class SimplexNoise2D {
83
94
  this._perm2D = new Uint8Array(256);
84
95
  }
85
96
  noise(x, y) {
86
- const { _gradients2D, _NORM_2D, _SQUISH_2D, _STRETCH_2D, _lookup, _perm, _perm2D } = this;
87
- const stretchOffset = (x + y) * _STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * _SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
97
+ const { _gradients2D, _NORM_2D, _SQUISH_2D, _STRETCH_2D, _lookup, _perm, _perm2D } = this, stretchOffset = (x + y) * _STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * _SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
88
98
  let value = 0;
89
99
  for (let c = _lookup[hash]; c !== undefined; c = c.next) {
90
100
  const dx = dx0 + c.dx, dy = dy0 + c.dy, attn = 2 - dx * dx - dy * dy;
91
- if (attn > 0) {
92
- const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = _perm[px & 0xff], index = _perm2D[(indexPartA + py) & 0xff], valuePart = _gradients2D[index] * dx + _gradients2D[index + 1] * dy;
93
- value += attn * attn * attn * attn * valuePart;
101
+ if (attn <= 0) {
102
+ continue;
94
103
  }
104
+ const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = _perm[px & 0xff], index = _perm2D[(indexPartA + py) & 0xff], valuePart = _gradients2D[index] * dx + _gradients2D[index + 1] * dy;
105
+ value += attn * attn * attn * attn * valuePart;
95
106
  }
96
107
  return value * _NORM_2D;
97
108
  }
98
109
  seed(clientSeed) {
99
- const { _p2D, _base2D, _lookupPairs2D } = this;
100
- const contributions = [];
110
+ const { _p2D, _base2D, _lookupPairs2D } = this, contributions = [];
101
111
  for (let i = 0; i < _p2D.length; i += 4) {
102
112
  const baseSet = _base2D[_p2D[i]];
103
113
  let previous = null, current = null;
@@ -1,9 +1,20 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
+ const third = 1 / 3;
2
3
  export class SimplexNoise3D {
4
+ _NORM_3D;
5
+ _SQUISH_3D;
6
+ _STRETCH_3D;
7
+ _base3D;
8
+ _gradients3D;
9
+ _lookup;
10
+ _lookupPairs3D;
11
+ _p3D;
12
+ _perm;
13
+ _perm3D;
3
14
  constructor() {
4
- this._NORM_3D = 1.0 / 103.0;
5
- this._SQUISH_3D = (Math.sqrt(3 + 1) - 1) / 3;
6
- this._STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) / 3;
15
+ this._NORM_3D = 1 / 103;
16
+ this._SQUISH_3D = (Math.sqrt(3 + 1) - 1) * third;
17
+ this._STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) * third;
7
18
  this._base3D = [
8
19
  [0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1],
9
20
  [2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1, 3, 1, 1, 1],
@@ -1,9 +1,20 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
+ const quarter = 0.25;
2
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;
3
14
  constructor() {
4
- this._NORM_4D = 1.0 / 30.0;
5
- this._SQUISH_4D = (Math.sqrt(4 + 1) - 1) * 0.25;
6
- this._STRETCH_4D = (1 / Math.sqrt(4 + 1) - 1) * 0.25;
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;
7
18
  this._lookup = [];
8
19
  this._perm = new Uint8Array(0);
9
20
  this._perm4D = new Uint8Array(0);
@@ -2779,8 +2790,7 @@ export class SimplexNoise4D {
2779
2790
  ];
2780
2791
  }
2781
2792
  noise(x, y, z, w) {
2782
- const { _perm, _perm4D, _lookup, _STRETCH_4D, _SQUISH_4D, _gradients4D, _NORM_4D } = this;
2783
- const 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, _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) |
2784
2794
  ((yins - zins + 1) << 1) |
2785
2795
  ((yins - wins + 1) << 2) |
2786
2796
  ((xins - yins + 1) << 3) |
@@ -2805,8 +2815,7 @@ export class SimplexNoise4D {
2805
2815
  return value * _NORM_4D;
2806
2816
  }
2807
2817
  seed(clientSeed) {
2808
- const { _p4D, _base4D, _lookupPairs4D } = this;
2809
- const contributions = [];
2818
+ const { _p4D, _base4D, _lookupPairs4D } = this, contributions = [];
2810
2819
  for (let i = 0; i < _p4D.length; i += 16) {
2811
2820
  const baseSet = _base4D[_p4D[i]];
2812
2821
  let previous = null, current = null;
@@ -2,6 +2,9 @@ import { SimplexNoise2D } from "./Classes/SimplexNoise2D.js";
2
2
  import { SimplexNoise3D } from "./Classes/SimplexNoise3D.js";
3
3
  import { SimplexNoise4D } from "./Classes/SimplexNoise4D.js";
4
4
  export class SimplexNoise {
5
+ noise2d;
6
+ noise3d;
7
+ noise4d;
5
8
  constructor() {
6
9
  this.noise2d = new SimplexNoise2D();
7
10
  this.noise3d = new SimplexNoise3D();
@@ -1,9 +1,20 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
+ const half = 0.5;
2
3
  export class SimplexNoise2D {
4
+ _NORM_2D;
5
+ _SQUISH_2D;
6
+ _STRETCH_2D;
7
+ _base2D;
8
+ _gradients2D;
9
+ _lookup;
10
+ _lookupPairs2D;
11
+ _p2D;
12
+ _perm;
13
+ _perm2D;
3
14
  constructor() {
4
- this._NORM_2D = 1.0 / 47.0;
5
- this._SQUISH_2D = (Math.sqrt(2 + 1) - 1) / 2;
6
- this._STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) / 2;
15
+ this._NORM_2D = 1 / 47;
16
+ this._SQUISH_2D = (Math.sqrt(2 + 1) - 1) * half;
17
+ this._STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) * half;
7
18
  this._base2D = [
8
19
  [1, 1, 0, 1, 0, 1, 0, 0, 0],
9
20
  [1, 1, 0, 1, 0, 1, 2, 1, 1],
@@ -83,21 +94,20 @@ export class SimplexNoise2D {
83
94
  this._perm2D = new Uint8Array(256);
84
95
  }
85
96
  noise(x, y) {
86
- const { _gradients2D, _NORM_2D, _SQUISH_2D, _STRETCH_2D, _lookup, _perm, _perm2D } = this;
87
- const stretchOffset = (x + y) * _STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * _SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
97
+ const { _gradients2D, _NORM_2D, _SQUISH_2D, _STRETCH_2D, _lookup, _perm, _perm2D } = this, stretchOffset = (x + y) * _STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * _SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
88
98
  let value = 0;
89
99
  for (let c = _lookup[hash]; c !== undefined; c = c.next) {
90
100
  const dx = dx0 + c.dx, dy = dy0 + c.dy, attn = 2 - dx * dx - dy * dy;
91
- if (attn > 0) {
92
- const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = _perm[px & 0xff], index = _perm2D[(indexPartA + py) & 0xff], valuePart = _gradients2D[index] * dx + _gradients2D[index + 1] * dy;
93
- value += attn * attn * attn * attn * valuePart;
101
+ if (attn <= 0) {
102
+ continue;
94
103
  }
104
+ const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = _perm[px & 0xff], index = _perm2D[(indexPartA + py) & 0xff], valuePart = _gradients2D[index] * dx + _gradients2D[index + 1] * dy;
105
+ value += attn * attn * attn * attn * valuePart;
95
106
  }
96
107
  return value * _NORM_2D;
97
108
  }
98
109
  seed(clientSeed) {
99
- const { _p2D, _base2D, _lookupPairs2D } = this;
100
- const contributions = [];
110
+ const { _p2D, _base2D, _lookupPairs2D } = this, contributions = [];
101
111
  for (let i = 0; i < _p2D.length; i += 4) {
102
112
  const baseSet = _base2D[_p2D[i]];
103
113
  let previous = null, current = null;
@@ -1,9 +1,20 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
+ const third = 1 / 3;
2
3
  export class SimplexNoise3D {
4
+ _NORM_3D;
5
+ _SQUISH_3D;
6
+ _STRETCH_3D;
7
+ _base3D;
8
+ _gradients3D;
9
+ _lookup;
10
+ _lookupPairs3D;
11
+ _p3D;
12
+ _perm;
13
+ _perm3D;
3
14
  constructor() {
4
- this._NORM_3D = 1.0 / 103.0;
5
- this._SQUISH_3D = (Math.sqrt(3 + 1) - 1) / 3;
6
- this._STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) / 3;
15
+ this._NORM_3D = 1 / 103;
16
+ this._SQUISH_3D = (Math.sqrt(3 + 1) - 1) * third;
17
+ this._STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) * third;
7
18
  this._base3D = [
8
19
  [0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1],
9
20
  [2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1, 3, 1, 1, 1],
@@ -1,9 +1,20 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
+ const quarter = 0.25;
2
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;
3
14
  constructor() {
4
- this._NORM_4D = 1.0 / 30.0;
5
- this._SQUISH_4D = (Math.sqrt(4 + 1) - 1) * 0.25;
6
- this._STRETCH_4D = (1 / Math.sqrt(4 + 1) - 1) * 0.25;
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;
7
18
  this._lookup = [];
8
19
  this._perm = new Uint8Array(0);
9
20
  this._perm4D = new Uint8Array(0);
@@ -2779,8 +2790,7 @@ export class SimplexNoise4D {
2779
2790
  ];
2780
2791
  }
2781
2792
  noise(x, y, z, w) {
2782
- const { _perm, _perm4D, _lookup, _STRETCH_4D, _SQUISH_4D, _gradients4D, _NORM_4D } = this;
2783
- const 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, _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) |
2784
2794
  ((yins - zins + 1) << 1) |
2785
2795
  ((yins - wins + 1) << 2) |
2786
2796
  ((xins - yins + 1) << 3) |
@@ -2805,8 +2815,7 @@ export class SimplexNoise4D {
2805
2815
  return value * _NORM_4D;
2806
2816
  }
2807
2817
  seed(clientSeed) {
2808
- const { _p4D, _base4D, _lookupPairs4D } = this;
2809
- const contributions = [];
2818
+ const { _p4D, _base4D, _lookupPairs4D } = this, contributions = [];
2810
2819
  for (let i = 0; i < _p4D.length; i += 16) {
2811
2820
  const baseSet = _base4D[_p4D[i]];
2812
2821
  let previous = null, current = null;
@@ -2,6 +2,9 @@ import { SimplexNoise2D } from "./Classes/SimplexNoise2D.js";
2
2
  import { SimplexNoise3D } from "./Classes/SimplexNoise3D.js";
3
3
  import { SimplexNoise4D } from "./Classes/SimplexNoise4D.js";
4
4
  export class SimplexNoise {
5
+ noise2d;
6
+ noise3d;
7
+ noise4d;
5
8
  constructor() {
6
9
  this.noise2d = new SimplexNoise2D();
7
10
  this.noise3d = new SimplexNoise3D();
@@ -1,9 +1,20 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
+ const half = 0.5;
2
3
  export class SimplexNoise2D {
4
+ _NORM_2D;
5
+ _SQUISH_2D;
6
+ _STRETCH_2D;
7
+ _base2D;
8
+ _gradients2D;
9
+ _lookup;
10
+ _lookupPairs2D;
11
+ _p2D;
12
+ _perm;
13
+ _perm2D;
3
14
  constructor() {
4
- this._NORM_2D = 1.0 / 47.0;
5
- this._SQUISH_2D = (Math.sqrt(2 + 1) - 1) / 2;
6
- this._STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) / 2;
15
+ this._NORM_2D = 1 / 47;
16
+ this._SQUISH_2D = (Math.sqrt(2 + 1) - 1) * half;
17
+ this._STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) * half;
7
18
  this._base2D = [
8
19
  [1, 1, 0, 1, 0, 1, 0, 0, 0],
9
20
  [1, 1, 0, 1, 0, 1, 2, 1, 1],
@@ -83,21 +94,20 @@ export class SimplexNoise2D {
83
94
  this._perm2D = new Uint8Array(256);
84
95
  }
85
96
  noise(x, y) {
86
- const { _gradients2D, _NORM_2D, _SQUISH_2D, _STRETCH_2D, _lookup, _perm, _perm2D } = this;
87
- const stretchOffset = (x + y) * _STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * _SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
97
+ const { _gradients2D, _NORM_2D, _SQUISH_2D, _STRETCH_2D, _lookup, _perm, _perm2D } = this, stretchOffset = (x + y) * _STRETCH_2D, xs = x + stretchOffset, ys = y + stretchOffset, xsb = Math.floor(xs), ysb = Math.floor(ys), squishOffset = (xsb + ysb) * _SQUISH_2D, dx0 = x - (xsb + squishOffset), dy0 = y - (ysb + squishOffset), xins = xs - xsb, yins = ys - ysb, inSum = xins + yins, hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4);
88
98
  let value = 0;
89
99
  for (let c = _lookup[hash]; c !== undefined; c = c.next) {
90
100
  const dx = dx0 + c.dx, dy = dy0 + c.dy, attn = 2 - dx * dx - dy * dy;
91
- if (attn > 0) {
92
- const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = _perm[px & 0xff], index = _perm2D[(indexPartA + py) & 0xff], valuePart = _gradients2D[index] * dx + _gradients2D[index + 1] * dy;
93
- value += attn * attn * attn * attn * valuePart;
101
+ if (attn <= 0) {
102
+ continue;
94
103
  }
104
+ const px = xsb + c.xsb, py = ysb + c.ysb, indexPartA = _perm[px & 0xff], index = _perm2D[(indexPartA + py) & 0xff], valuePart = _gradients2D[index] * dx + _gradients2D[index + 1] * dy;
105
+ value += attn * attn * attn * attn * valuePart;
95
106
  }
96
107
  return value * _NORM_2D;
97
108
  }
98
109
  seed(clientSeed) {
99
- const { _p2D, _base2D, _lookupPairs2D } = this;
100
- const contributions = [];
110
+ const { _p2D, _base2D, _lookupPairs2D } = this, contributions = [];
101
111
  for (let i = 0; i < _p2D.length; i += 4) {
102
112
  const baseSet = _base2D[_p2D[i]];
103
113
  let previous = null, current = null;
@@ -1,9 +1,20 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
+ const third = 1 / 3;
2
3
  export class SimplexNoise3D {
4
+ _NORM_3D;
5
+ _SQUISH_3D;
6
+ _STRETCH_3D;
7
+ _base3D;
8
+ _gradients3D;
9
+ _lookup;
10
+ _lookupPairs3D;
11
+ _p3D;
12
+ _perm;
13
+ _perm3D;
3
14
  constructor() {
4
- this._NORM_3D = 1.0 / 103.0;
5
- this._SQUISH_3D = (Math.sqrt(3 + 1) - 1) / 3;
6
- this._STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) / 3;
15
+ this._NORM_3D = 1 / 103;
16
+ this._SQUISH_3D = (Math.sqrt(3 + 1) - 1) * third;
17
+ this._STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) * third;
7
18
  this._base3D = [
8
19
  [0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1],
9
20
  [2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1, 3, 1, 1, 1],
@@ -1,9 +1,20 @@
1
1
  import { shuffleSeed } from "../utils.js";
2
+ const quarter = 0.25;
2
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;
3
14
  constructor() {
4
- this._NORM_4D = 1.0 / 30.0;
5
- this._SQUISH_4D = (Math.sqrt(4 + 1) - 1) * 0.25;
6
- this._STRETCH_4D = (1 / Math.sqrt(4 + 1) - 1) * 0.25;
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;
7
18
  this._lookup = [];
8
19
  this._perm = new Uint8Array(0);
9
20
  this._perm4D = new Uint8Array(0);
@@ -2779,8 +2790,7 @@ export class SimplexNoise4D {
2779
2790
  ];
2780
2791
  }
2781
2792
  noise(x, y, z, w) {
2782
- const { _perm, _perm4D, _lookup, _STRETCH_4D, _SQUISH_4D, _gradients4D, _NORM_4D } = this;
2783
- const 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, _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) |
2784
2794
  ((yins - zins + 1) << 1) |
2785
2795
  ((yins - wins + 1) << 2) |
2786
2796
  ((xins - yins + 1) << 3) |
@@ -2805,8 +2815,7 @@ export class SimplexNoise4D {
2805
2815
  return value * _NORM_4D;
2806
2816
  }
2807
2817
  seed(clientSeed) {
2808
- const { _p4D, _base4D, _lookupPairs4D } = this;
2809
- const contributions = [];
2818
+ const { _p4D, _base4D, _lookupPairs4D } = this, contributions = [];
2810
2819
  for (let i = 0; i < _p4D.length; i += 16) {
2811
2820
  const baseSet = _base4D[_p4D[i]];
2812
2821
  let previous = null, current = null;
@@ -2,6 +2,9 @@ import { SimplexNoise2D } from "./Classes/SimplexNoise2D.js";
2
2
  import { SimplexNoise3D } from "./Classes/SimplexNoise3D.js";
3
3
  import { SimplexNoise4D } from "./Classes/SimplexNoise4D.js";
4
4
  export class SimplexNoise {
5
+ noise2d;
6
+ noise3d;
7
+ noise4d;
5
8
  constructor() {
6
9
  this.noise2d = new SimplexNoise2D();
7
10
  this.noise3d = new SimplexNoise3D();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/simplex-noise",
3
- "version": "4.0.0-alpha.8",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "tsParticles simplex noise library",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {