@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.
- package/browser/Classes/SimplexNoise2D.js +40 -40
- package/browser/Classes/SimplexNoise3D.js +42 -42
- package/browser/Classes/SimplexNoise4D.js +47 -47
- package/cjs/Classes/SimplexNoise2D.js +40 -40
- package/cjs/Classes/SimplexNoise3D.js +42 -42
- package/cjs/Classes/SimplexNoise4D.js +47 -47
- package/esm/Classes/SimplexNoise2D.js +40 -40
- package/esm/Classes/SimplexNoise3D.js +42 -42
- package/esm/Classes/SimplexNoise4D.js +47 -47
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.simplex.noise.js +130 -130
- package/tsparticles.simplex.noise.min.js +1 -1
- package/types/Classes/SimplexNoise2D.d.ts +1 -11
- package/types/Classes/SimplexNoise3D.d.ts +1 -11
- package/types/Classes/SimplexNoise4D.d.ts +1 -11
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { shuffleSeed } from "../utils.js";
|
|
2
2
|
const quarter = 0.25;
|
|
3
3
|
export class SimplexNoise4D {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
16
|
-
this
|
|
17
|
-
this
|
|
18
|
-
this
|
|
19
|
-
this
|
|
20
|
-
this
|
|
21
|
-
this
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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 =
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
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 *
|
|
2815
|
+
return value * NORM_4D;
|
|
2816
2816
|
}
|
|
2817
2817
|
seed(clientSeed) {
|
|
2818
|
-
const
|
|
2819
|
-
for (let i = 0; i <
|
|
2820
|
-
const baseSet =
|
|
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
|
|
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
|
|
2834
|
-
current.next.next = this
|
|
2835
|
-
current.next.next.next = this
|
|
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
|
|
2839
|
-
for (let i = 0; i <
|
|
2840
|
-
this
|
|
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
|
|
2843
|
-
this
|
|
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
|
|
2859
|
-
this
|
|
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
|
-
|
|
2864
|
-
const
|
|
2863
|
+
#contribution4D(multiplier, xsb, ysb, zsb, wsb) {
|
|
2864
|
+
const SQUISH_4D = this.#SQUISH_4D;
|
|
2865
2865
|
return {
|
|
2866
|
-
dx: -xsb - multiplier *
|
|
2867
|
-
dy: -ysb - multiplier *
|
|
2868
|
-
dz: -zsb - multiplier *
|
|
2869
|
-
dw: -wsb - multiplier *
|
|
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
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":"
|
|
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;
|