@cult-frog/noise 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +205 -2
- package/dist/fractal/_types/fractalOptions.d.ts +36 -0
- package/dist/fractal/_types/fractalOptions.d.ts.map +1 -0
- package/dist/fractal/_types/fractalOptions.js +2 -0
- package/dist/fractal/_types/fractalOptions.js.map +1 -0
- package/dist/fractal/_types/index.d.ts +2 -0
- package/dist/fractal/_types/index.d.ts.map +1 -0
- package/dist/fractal/_types/index.js +2 -0
- package/dist/fractal/_types/index.js.map +1 -0
- package/dist/fractal/fractal.d.ts +17 -0
- package/dist/fractal/fractal.d.ts.map +1 -0
- package/dist/fractal/fractal.js +31 -0
- package/dist/fractal/fractal.js.map +1 -0
- package/dist/fractal/index.d.ts +4 -0
- package/dist/fractal/index.d.ts.map +1 -0
- package/dist/fractal/index.js +3 -0
- package/dist/fractal/index.js.map +1 -0
- package/dist/fractal/options.d.ts +14 -0
- package/dist/fractal/options.d.ts.map +1 -0
- package/dist/fractal/options.js +57 -0
- package/dist/fractal/options.js.map +1 -0
- package/dist/gradient/cubeEdge3.d.ts +11 -0
- package/dist/gradient/cubeEdge3.d.ts.map +1 -0
- package/dist/gradient/cubeEdge3.js +39 -0
- package/dist/gradient/cubeEdge3.js.map +1 -0
- package/dist/gradient/index.d.ts +2 -0
- package/dist/gradient/index.d.ts.map +1 -0
- package/dist/gradient/index.js +2 -0
- package/dist/gradient/index.js.map +1 -0
- package/dist/hashes/hash.d.ts +16 -0
- package/dist/hashes/hash.d.ts.map +1 -0
- package/dist/hashes/hash.js +37 -0
- package/dist/hashes/hash.js.map +1 -0
- package/dist/hashes/hashes.d.ts +3 -0
- package/dist/hashes/hashes.d.ts.map +1 -0
- package/dist/hashes/hashes.js +3 -0
- package/dist/hashes/hashes.js.map +1 -0
- package/dist/hashes/index.d.ts +2 -0
- package/dist/hashes/index.d.ts.map +1 -0
- package/dist/hashes/index.js +2 -0
- package/dist/hashes/index.js.map +1 -0
- package/dist/hashes/lowbias.d.ts +12 -0
- package/dist/hashes/lowbias.d.ts.map +1 -0
- package/dist/hashes/lowbias.js +19 -0
- package/dist/hashes/lowbias.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/noiseMap/_types/index.d.ts +3 -0
- package/dist/noiseMap/_types/index.d.ts.map +1 -0
- package/dist/noiseMap/_types/index.js +2 -0
- package/dist/noiseMap/_types/index.js.map +1 -0
- package/dist/noiseMap/_types/noise2d.d.ts +21 -0
- package/dist/noiseMap/_types/noise2d.d.ts.map +1 -0
- package/dist/noiseMap/_types/noise2d.js +2 -0
- package/dist/noiseMap/_types/noise2d.js.map +1 -0
- package/dist/noiseMap/_types/noise3d.d.ts +24 -0
- package/dist/noiseMap/_types/noise3d.d.ts.map +1 -0
- package/dist/noiseMap/_types/noise3d.js +2 -0
- package/dist/noiseMap/_types/noise3d.js.map +1 -0
- package/dist/noiseMap/index.d.ts +6 -0
- package/dist/noiseMap/index.d.ts.map +1 -0
- package/dist/noiseMap/index.js +3 -0
- package/dist/noiseMap/index.js.map +1 -0
- package/dist/noiseMap/noise2d.d.ts +52 -0
- package/dist/noiseMap/noise2d.d.ts.map +1 -0
- package/dist/noiseMap/noise2d.js +105 -0
- package/dist/noiseMap/noise2d.js.map +1 -0
- package/dist/noiseMap/noise3d.d.ts +62 -0
- package/dist/noiseMap/noise3d.d.ts.map +1 -0
- package/dist/noiseMap/noise3d.js +129 -0
- package/dist/noiseMap/noise3d.js.map +1 -0
- package/dist/noiseTypes/cellular/2d.d.ts +36 -0
- package/dist/noiseTypes/cellular/2d.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/2d.js +123 -0
- package/dist/noiseTypes/cellular/2d.js.map +1 -0
- package/dist/noiseTypes/cellular/3d.d.ts +32 -0
- package/dist/noiseTypes/cellular/3d.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/3d.js +143 -0
- package/dist/noiseTypes/cellular/3d.js.map +1 -0
- package/dist/noiseTypes/cellular/_types/index.d.ts +2 -0
- package/dist/noiseTypes/cellular/_types/index.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/_types/index.js +2 -0
- package/dist/noiseTypes/cellular/_types/index.js.map +1 -0
- package/dist/noiseTypes/cellular/_types/options.d.ts +37 -0
- package/dist/noiseTypes/cellular/_types/options.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/_types/options.js +2 -0
- package/dist/noiseTypes/cellular/_types/options.js.map +1 -0
- package/dist/noiseTypes/cellular/defaultOptions.d.ts +4 -0
- package/dist/noiseTypes/cellular/defaultOptions.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/defaultOptions.js +13 -0
- package/dist/noiseTypes/cellular/defaultOptions.js.map +1 -0
- package/dist/noiseTypes/cellular/floorDiv.d.ts +18 -0
- package/dist/noiseTypes/cellular/floorDiv.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/floorDiv.js +28 -0
- package/dist/noiseTypes/cellular/floorDiv.js.map +1 -0
- package/dist/noiseTypes/cellular/index.d.ts +4 -0
- package/dist/noiseTypes/cellular/index.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/index.js +3 -0
- package/dist/noiseTypes/cellular/index.js.map +1 -0
- package/dist/noiseTypes/cellular/options.d.ts +6 -0
- package/dist/noiseTypes/cellular/options.d.ts.map +1 -0
- package/dist/noiseTypes/cellular/options.js +20 -0
- package/dist/noiseTypes/cellular/options.js.map +1 -0
- package/dist/noiseTypes/index.d.ts +5 -0
- package/dist/noiseTypes/index.d.ts.map +1 -0
- package/dist/noiseTypes/index.js +5 -0
- package/dist/noiseTypes/index.js.map +1 -0
- package/dist/noiseTypes/perlin/2d.d.ts +23 -0
- package/dist/noiseTypes/perlin/2d.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/2d.js +64 -0
- package/dist/noiseTypes/perlin/2d.js.map +1 -0
- package/dist/noiseTypes/perlin/3d.d.ts +24 -0
- package/dist/noiseTypes/perlin/3d.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/3d.js +69 -0
- package/dist/noiseTypes/perlin/3d.js.map +1 -0
- package/dist/noiseTypes/perlin/_types/index.d.ts +2 -0
- package/dist/noiseTypes/perlin/_types/index.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/_types/index.js +2 -0
- package/dist/noiseTypes/perlin/_types/index.js.map +1 -0
- package/dist/noiseTypes/perlin/_types/options.d.ts +22 -0
- package/dist/noiseTypes/perlin/_types/options.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/_types/options.js +2 -0
- package/dist/noiseTypes/perlin/_types/options.js.map +1 -0
- package/dist/noiseTypes/perlin/defaultOptions.d.ts +4 -0
- package/dist/noiseTypes/perlin/defaultOptions.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/defaultOptions.js +14 -0
- package/dist/noiseTypes/perlin/defaultOptions.js.map +1 -0
- package/dist/noiseTypes/perlin/index.d.ts +4 -0
- package/dist/noiseTypes/perlin/index.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/index.js +3 -0
- package/dist/noiseTypes/perlin/index.js.map +1 -0
- package/dist/noiseTypes/perlin/options.d.ts +9 -0
- package/dist/noiseTypes/perlin/options.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/options.js +17 -0
- package/dist/noiseTypes/perlin/options.js.map +1 -0
- package/dist/noiseTypes/perlin/sample2.d.ts +25 -0
- package/dist/noiseTypes/perlin/sample2.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/sample2.js +58 -0
- package/dist/noiseTypes/perlin/sample2.js.map +1 -0
- package/dist/noiseTypes/perlin/sample3.d.ts +9 -0
- package/dist/noiseTypes/perlin/sample3.d.ts.map +1 -0
- package/dist/noiseTypes/perlin/sample3.js +38 -0
- package/dist/noiseTypes/perlin/sample3.js.map +1 -0
- package/dist/noiseTypes/simplex/2d.d.ts +23 -0
- package/dist/noiseTypes/simplex/2d.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/2d.js +64 -0
- package/dist/noiseTypes/simplex/2d.js.map +1 -0
- package/dist/noiseTypes/simplex/3d.d.ts +25 -0
- package/dist/noiseTypes/simplex/3d.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/3d.js +70 -0
- package/dist/noiseTypes/simplex/3d.js.map +1 -0
- package/dist/noiseTypes/simplex/_types/index.d.ts +2 -0
- package/dist/noiseTypes/simplex/_types/index.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/_types/index.js +2 -0
- package/dist/noiseTypes/simplex/_types/index.js.map +1 -0
- package/dist/noiseTypes/simplex/_types/options.d.ts +33 -0
- package/dist/noiseTypes/simplex/_types/options.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/_types/options.js +2 -0
- package/dist/noiseTypes/simplex/_types/options.js.map +1 -0
- package/dist/noiseTypes/simplex/defaultOptions.d.ts +4 -0
- package/dist/noiseTypes/simplex/defaultOptions.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/defaultOptions.js +14 -0
- package/dist/noiseTypes/simplex/defaultOptions.js.map +1 -0
- package/dist/noiseTypes/simplex/index.d.ts +4 -0
- package/dist/noiseTypes/simplex/index.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/index.js +3 -0
- package/dist/noiseTypes/simplex/index.js.map +1 -0
- package/dist/noiseTypes/simplex/options.d.ts +9 -0
- package/dist/noiseTypes/simplex/options.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/options.js +17 -0
- package/dist/noiseTypes/simplex/options.js.map +1 -0
- package/dist/noiseTypes/simplex/sample2.d.ts +32 -0
- package/dist/noiseTypes/simplex/sample2.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/sample2.js +94 -0
- package/dist/noiseTypes/simplex/sample2.js.map +1 -0
- package/dist/noiseTypes/simplex/sample3.d.ts +19 -0
- package/dist/noiseTypes/simplex/sample3.d.ts.map +1 -0
- package/dist/noiseTypes/simplex/sample3.js +110 -0
- package/dist/noiseTypes/simplex/sample3.js.map +1 -0
- package/dist/noiseTypes/white/2d.d.ts +18 -0
- package/dist/noiseTypes/white/2d.d.ts.map +1 -0
- package/dist/noiseTypes/white/2d.js +33 -0
- package/dist/noiseTypes/white/2d.js.map +1 -0
- package/dist/noiseTypes/white/3d.d.ts +17 -0
- package/dist/noiseTypes/white/3d.d.ts.map +1 -0
- package/dist/noiseTypes/white/3d.js +34 -0
- package/dist/noiseTypes/white/3d.js.map +1 -0
- package/dist/noiseTypes/white/_types/index.d.ts +2 -0
- package/dist/noiseTypes/white/_types/index.d.ts.map +1 -0
- package/dist/noiseTypes/white/_types/index.js +2 -0
- package/dist/noiseTypes/white/_types/index.js.map +1 -0
- package/dist/noiseTypes/white/_types/options.d.ts +28 -0
- package/dist/noiseTypes/white/_types/options.d.ts.map +1 -0
- package/dist/noiseTypes/white/_types/options.js +2 -0
- package/dist/noiseTypes/white/_types/options.js.map +1 -0
- package/dist/noiseTypes/white/defaultOptions.d.ts +4 -0
- package/dist/noiseTypes/white/defaultOptions.d.ts.map +1 -0
- package/dist/noiseTypes/white/defaultOptions.js +10 -0
- package/dist/noiseTypes/white/defaultOptions.js.map +1 -0
- package/dist/noiseTypes/white/index.d.ts +4 -0
- package/dist/noiseTypes/white/index.d.ts.map +1 -0
- package/dist/noiseTypes/white/index.js +3 -0
- package/dist/noiseTypes/white/index.js.map +1 -0
- package/dist/noiseTypes/white/options.d.ts +6 -0
- package/dist/noiseTypes/white/options.d.ts.map +1 -0
- package/dist/noiseTypes/white/options.js +14 -0
- package/dist/noiseTypes/white/options.js.map +1 -0
- package/package.json +78 -4
- package/src/fractal/_types/fractalOptions.ts +35 -0
- package/src/fractal/_types/index.ts +1 -0
- package/src/fractal/fractal.ts +41 -0
- package/src/fractal/index.ts +4 -0
- package/src/fractal/options.ts +62 -0
- package/src/gradient/cubeEdge3.ts +47 -0
- package/src/gradient/index.ts +1 -0
- package/src/hashes/hash.ts +41 -0
- package/src/hashes/hashes.ts +2 -0
- package/src/hashes/index.ts +1 -0
- package/src/hashes/lowbias.ts +18 -0
- package/src/index.ts +4 -0
- package/src/noiseMap/_types/index.ts +2 -0
- package/src/noiseMap/_types/noise2d.ts +21 -0
- package/src/noiseMap/_types/noise3d.ts +24 -0
- package/src/noiseMap/index.ts +7 -0
- package/src/noiseMap/noise2d.ts +117 -0
- package/src/noiseMap/noise3d.ts +146 -0
- package/src/noiseTypes/cellular/2d.ts +142 -0
- package/src/noiseTypes/cellular/3d.ts +171 -0
- package/src/noiseTypes/cellular/_types/index.ts +1 -0
- package/src/noiseTypes/cellular/_types/options.ts +37 -0
- package/src/noiseTypes/cellular/defaultOptions.ts +15 -0
- package/src/noiseTypes/cellular/floorDiv.ts +27 -0
- package/src/noiseTypes/cellular/index.ts +4 -0
- package/src/noiseTypes/cellular/options.ts +20 -0
- package/src/noiseTypes/index.ts +4 -0
- package/src/noiseTypes/perlin/2d.ts +86 -0
- package/src/noiseTypes/perlin/3d.ts +93 -0
- package/src/noiseTypes/perlin/_types/index.ts +1 -0
- package/src/noiseTypes/perlin/_types/options.ts +23 -0
- package/src/noiseTypes/perlin/defaultOptions.ts +16 -0
- package/src/noiseTypes/perlin/index.ts +4 -0
- package/src/noiseTypes/perlin/options.ts +19 -0
- package/src/noiseTypes/perlin/sample2.ts +62 -0
- package/src/noiseTypes/perlin/sample3.ts +43 -0
- package/src/noiseTypes/simplex/2d.ts +86 -0
- package/src/noiseTypes/simplex/3d.ts +94 -0
- package/src/noiseTypes/simplex/_types/index.ts +1 -0
- package/src/noiseTypes/simplex/_types/options.ts +34 -0
- package/src/noiseTypes/simplex/defaultOptions.ts +16 -0
- package/src/noiseTypes/simplex/index.ts +4 -0
- package/src/noiseTypes/simplex/options.ts +19 -0
- package/src/noiseTypes/simplex/sample2.ts +103 -0
- package/src/noiseTypes/simplex/sample3.ts +128 -0
- package/src/noiseTypes/white/2d.ts +44 -0
- package/src/noiseTypes/white/3d.ts +46 -0
- package/src/noiseTypes/white/_types/index.ts +1 -0
- package/src/noiseTypes/white/_types/options.ts +28 -0
- package/src/noiseTypes/white/defaultOptions.ts +12 -0
- package/src/noiseTypes/white/index.ts +4 -0
- package/src/noiseTypes/white/options.ts +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/noiseTypes/white/_types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/noiseTypes/white/_types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for 2D white noise. A map is a pure function of its size and these
|
|
3
|
+
* options, so the same options reproduce it exactly on any JS engine.
|
|
4
|
+
*/
|
|
5
|
+
export interface White2dOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Selects the value at every world cell. An integer; only its low 32 bits
|
|
8
|
+
* take part, so seeds 2^32 apart give the same map.
|
|
9
|
+
*/
|
|
10
|
+
seed: number;
|
|
11
|
+
/**
|
|
12
|
+
* World x of the map's first column, in map cells. A safe integer (|v| < 2^53),
|
|
13
|
+
* so `x + offsetX` is exact and a chunk at offset 64 reproduces column 64 of a
|
|
14
|
+
* chunk at offset 0 bit for bit. Larger integers would round when added to.
|
|
15
|
+
*
|
|
16
|
+
* The cell hash only sees the low 32 bits of each world coordinate, so the
|
|
17
|
+
* pattern repeats every 2^32 cells along each axis.
|
|
18
|
+
*/
|
|
19
|
+
offsetX: number;
|
|
20
|
+
/** World y of the map's first row. Same contract as {@link offsetX}. */
|
|
21
|
+
offsetY: number;
|
|
22
|
+
}
|
|
23
|
+
/** Options for 3D white noise: the 2D options plus a z offset. */
|
|
24
|
+
export interface White3dOptions extends White2dOptions {
|
|
25
|
+
/** World z of the map's first layer. Same contract as {@link White2dOptions.offsetX}. */
|
|
26
|
+
offsetZ: number;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../src/noiseTypes/white/_types/options.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,kEAAkE;AAClE,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,yFAAyF;IACzF,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../src/noiseTypes/white/_types/options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultOptions.d.ts","sourceRoot":"","sources":["../../../src/noiseTypes/white/defaultOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1E,eAAO,MAAM,wBAAwB,EAAE,cAItC,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAGtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultOptions.js","sourceRoot":"","sources":["../../../src/noiseTypes/white/defaultOptions.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,wBAAwB,GAAmB;IACtD,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAmB;IACtD,GAAG,wBAAwB;IAC3B,OAAO,EAAE,CAAC;CACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/noiseTypes/white/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAElC,mBAAmB,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/noiseTypes/white/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { White2dOptions, White3dOptions } from './_types/index.js';
|
|
2
|
+
/** Throws if `options` breaks a contract in {@link White2dOptions}. */
|
|
3
|
+
export declare function validateOptions2(options: White2dOptions): void;
|
|
4
|
+
/** Throws if `options` breaks a contract in {@link White3dOptions}. */
|
|
5
|
+
export declare function validateOptions3(options: White3dOptions): void;
|
|
6
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/noiseTypes/white/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExE,uEAAuE;AACvE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAI9D;AAED,uEAAuE;AACvE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAG9D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Throws if `options` breaks a contract in {@link White2dOptions}. */
|
|
2
|
+
export function validateOptions2(options) {
|
|
3
|
+
if (!Number.isInteger(options.seed))
|
|
4
|
+
throw new RangeError('Invalid seed');
|
|
5
|
+
if (!(Number.isSafeInteger(options.offsetX) && Number.isSafeInteger(options.offsetY)))
|
|
6
|
+
throw new RangeError('Invalid offsetX or offsetY');
|
|
7
|
+
}
|
|
8
|
+
/** Throws if `options` breaks a contract in {@link White3dOptions}. */
|
|
9
|
+
export function validateOptions3(options) {
|
|
10
|
+
validateOptions2(options);
|
|
11
|
+
if (!Number.isSafeInteger(options.offsetZ))
|
|
12
|
+
throw new RangeError('Invalid offsetZ');
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/noiseTypes/white/options.ts"],"names":[],"mappings":"AAEA,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAAC,OAAuB;IACtD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,cAAc,CAAC,CAAC;IAC1E,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACnF,MAAM,IAAI,UAAU,CAAC,4BAA4B,CAAC,CAAC;AACvD,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAAC,OAAuB;IACtD,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC1B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,iBAAiB,CAAC,CAAC;AACtF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cult-frog/noise",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A lightweight JavaScript library for procedural noise generation",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Quin Partridge",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"seeded",
|
|
9
|
+
"noise",
|
|
10
|
+
"procedural",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/CapnQwan/cult-frog-noise-js.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/CapnQwan/cult-frog-noise-js/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/CapnQwan/cult-frog-noise-js#readme",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src",
|
|
26
|
+
"!src/**/__tests__",
|
|
27
|
+
"CHANGELOG.md"
|
|
28
|
+
],
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20.19"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"test:watch": "vitest watch",
|
|
49
|
+
"test:coverage": "vitest run --coverage",
|
|
50
|
+
"playground": "vite playground",
|
|
51
|
+
"playground:typecheck": "tsc -p playground --noEmit",
|
|
52
|
+
"check": "biome check . --error-on-warnings",
|
|
53
|
+
"check:ci": "biome ci . --error-on-warnings",
|
|
54
|
+
"fix": "biome check . --write",
|
|
55
|
+
"prepublishOnly": "pnpm check:ci && pnpm typecheck && pnpm test && pnpm build",
|
|
56
|
+
"prepare": "husky"
|
|
57
|
+
},
|
|
58
|
+
"packageManager": "pnpm@10.33.4",
|
|
59
|
+
"lint-staged": {
|
|
60
|
+
"*.{ts,tsx,js}": [
|
|
61
|
+
"biome check --write --error-on-warnings --no-errors-on-unmatched"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@biomejs/biome": "~2.5.13",
|
|
66
|
+
"@cult-frog/tooling": "^0.1.2",
|
|
67
|
+
"@types/node": "^22.20.2",
|
|
68
|
+
"husky": "^9.1.7",
|
|
69
|
+
"lint-staged": "^17.5.1",
|
|
70
|
+
"rimraf": "^6.1.3",
|
|
71
|
+
"typescript": "^7.0.2",
|
|
72
|
+
"vite": "^8.3.4",
|
|
73
|
+
"vitest": "^5.0.0"
|
|
74
|
+
},
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"@cult-frog/math": "^0.1.0",
|
|
77
|
+
"@cult-frog/random": "^0.1.0",
|
|
78
|
+
"@cult-frog/types": "^1.0.1"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options shared by every fractal (multi-octave) generator: how octaves are
|
|
3
|
+
* spaced, weighted and seeded. Each generator's own options add its offsets.
|
|
4
|
+
*
|
|
5
|
+
* Besides each field's own contract, `scale`, `lacunarity` and `octaves` are
|
|
6
|
+
* rejected together when the finest octave's frequency is so high that sample
|
|
7
|
+
* coordinates would overflow. That takes extreme values (lacunarity 2 stays far
|
|
8
|
+
* inside the limit even at 32 octaves), and the check does not depend on the
|
|
9
|
+
* offsets, so options that work for one chunk work for every chunk.
|
|
10
|
+
*/
|
|
11
|
+
export interface FractalOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Selects the lattice gradients and each octave's offset. An integer; only its
|
|
14
|
+
* low 32 bits take part, so seeds 2^32 apart give the same map.
|
|
15
|
+
*/
|
|
16
|
+
seed: number;
|
|
17
|
+
/**
|
|
18
|
+
* Width of one lattice cell of the first octave, in map cells. Larger values
|
|
19
|
+
* zoom in. Finite and greater than 0.
|
|
20
|
+
*/
|
|
21
|
+
scale: number;
|
|
22
|
+
/**
|
|
23
|
+
* Frequency multiplier from one octave to the next; 2 halves the feature size
|
|
24
|
+
* each octave. Finite and greater than 0.
|
|
25
|
+
*/
|
|
26
|
+
lacunarity: number;
|
|
27
|
+
/**
|
|
28
|
+
* Amplitude multiplier from one octave to the next, in [0, 1]. Output is scaled
|
|
29
|
+
* by the sum of all amplitudes, so raising this or adding octaves narrows the
|
|
30
|
+
* spread of values around 0.5.
|
|
31
|
+
*/
|
|
32
|
+
persistence: number;
|
|
33
|
+
/** Number of layers summed. Integer in [1, 32]. Cost grows linearly with it. */
|
|
34
|
+
octaves: number;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { FractalOptions } from './fractalOptions.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Random } from '@cult-frog/random';
|
|
2
|
+
|
|
3
|
+
import type { FractalOptions } from './_types/index.js';
|
|
4
|
+
|
|
5
|
+
const OFFSET_RANGE = 100_000;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Seed-derived per-octave sample offsets (x, y interleaved) and the sum of all
|
|
9
|
+
* octave amplitudes, which bounds the summed noise.
|
|
10
|
+
*
|
|
11
|
+
* The offsets stop every octave sharing the lattice origin. They deliberately
|
|
12
|
+
* exclude `offsetX`/`offsetY`, so every chunk of a world adds the same constants
|
|
13
|
+
* to the same exact integer world position and gets bit-identical samples.
|
|
14
|
+
*
|
|
15
|
+
* The offsets come from `@cult-frog/random`'s sequence, so every Perlin and
|
|
16
|
+
* simplex map depends on it. Random treats a sequence change as breaking, which
|
|
17
|
+
* its semver range here already excludes; moving this package onto a new
|
|
18
|
+
* breaking range of random changes every fractal map, so it is a breaking
|
|
19
|
+
* release of this package too. The golden-value tests fail when that happens.
|
|
20
|
+
*/
|
|
21
|
+
export function getOctaveConfig(
|
|
22
|
+
config: FractalOptions,
|
|
23
|
+
dimensions: 2 | 3
|
|
24
|
+
): [octaveOffsets: Float32Array, maxPossibleHeight: number] {
|
|
25
|
+
const octaveOffsets = new Float32Array(config.octaves * dimensions);
|
|
26
|
+
const prng = new Random(config.seed);
|
|
27
|
+
|
|
28
|
+
let maxPossibleHeight = 0;
|
|
29
|
+
let amplitude = 1;
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < config.octaves; i++) {
|
|
32
|
+
const index = i * dimensions;
|
|
33
|
+
for (let j = 0; j < dimensions; j++)
|
|
34
|
+
octaveOffsets[index + j] = prng.float(-OFFSET_RANGE, OFFSET_RANGE);
|
|
35
|
+
|
|
36
|
+
maxPossibleHeight += amplitude;
|
|
37
|
+
amplitude *= config.persistence;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return [octaveOffsets, maxPossibleHeight];
|
|
41
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { FractalOptions } from './_types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Upper bound on `octaves`. At lacunarity 2 the last octave already has 2^31
|
|
5
|
+
* lattice cells per first-octave cell, far finer than one map cell, and at the
|
|
6
|
+
* default persistence its amplitude is below Float32 resolution. Each octave
|
|
7
|
+
* costs a full sample per cell and a slot in the per-call octave table, so the
|
|
8
|
+
* cap also bounds the cost of a single call.
|
|
9
|
+
*/
|
|
10
|
+
const MAX_OCTAVES = 32;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Upper bound on |world coordinate + octave offset| for any map: a safe-integer
|
|
14
|
+
* offset (< 2^53), plus a map extent that cannot exceed 2^53 cells, plus the
|
|
15
|
+
* octave offset range, rounded up with headroom so rounding near the limit
|
|
16
|
+
* cannot matter.
|
|
17
|
+
*/
|
|
18
|
+
const MAX_WORLD_COORDINATE = 2 ** 55;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Highest per-octave frequency, built with the same repeated multiplication the
|
|
22
|
+
* samplers use. With lacunarity below 1 the frequency falls each octave, so the
|
|
23
|
+
* first octave is the highest.
|
|
24
|
+
*/
|
|
25
|
+
function getMaxFrequency(octaves: number, lacunarity: number): number {
|
|
26
|
+
let frequency = 1;
|
|
27
|
+
let maxFrequency = 1;
|
|
28
|
+
for (let i = 1; i < octaves; i++) {
|
|
29
|
+
frequency *= lacunarity;
|
|
30
|
+
if (frequency > maxFrequency) maxFrequency = frequency;
|
|
31
|
+
}
|
|
32
|
+
return maxFrequency;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Throws if `options` breaks a contract in {@link FractalOptions}. Each fractal
|
|
37
|
+
* generator calls this before checking its own offsets, so every generator
|
|
38
|
+
* accepts and rejects the same fractal options with the same messages.
|
|
39
|
+
*
|
|
40
|
+
* The last check rejects combinations whose individual values are fine but
|
|
41
|
+
* whose highest sample coordinate would overflow to Infinity, which turns every
|
|
42
|
+
* sample into NaN. It assumes the worst-case world position rather than this
|
|
43
|
+
* map's offsets, so options accepted for one chunk are accepted for every chunk
|
|
44
|
+
* of the same world.
|
|
45
|
+
*/
|
|
46
|
+
export function validateFractalOptions(options: FractalOptions): void {
|
|
47
|
+
if (!Number.isInteger(options.seed)) throw new RangeError('Invalid seed');
|
|
48
|
+
if (
|
|
49
|
+
!(Number.isInteger(options.octaves) && options.octaves >= 1 && options.octaves <= MAX_OCTAVES)
|
|
50
|
+
)
|
|
51
|
+
throw new RangeError('Invalid octaves');
|
|
52
|
+
if (!(Number.isFinite(options.lacunarity) && options.lacunarity > 0))
|
|
53
|
+
throw new RangeError('Invalid lacunarity');
|
|
54
|
+
if (!(options.persistence >= 0 && options.persistence <= 1))
|
|
55
|
+
throw new RangeError('Invalid persistence');
|
|
56
|
+
if (!(Number.isFinite(options.scale) && options.scale > 0)) throw new RangeError('Invalid scale');
|
|
57
|
+
|
|
58
|
+
const maxScaledFrequency =
|
|
59
|
+
(1 / options.scale) * getMaxFrequency(options.octaves, options.lacunarity);
|
|
60
|
+
if (!Number.isFinite(MAX_WORLD_COORDINATE * maxScaledFrequency))
|
|
61
|
+
throw new RangeError('Invalid scale, lacunarity, or octaves');
|
|
62
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Hashes } from '../hashes/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dot product of the gradient hashed for lattice corner (`cx`, `cy`, `cz`) with
|
|
5
|
+
* the offset (`dx`, `dy`, `dz`) from that corner to the sample point.
|
|
6
|
+
*
|
|
7
|
+
* The twelve gradients are the cube's edge directions, (±1, ±1, 0), (±1, 0, ±1)
|
|
8
|
+
* and (0, ±1, ±1), picked by integer hash rather than angle, so each dot product
|
|
9
|
+
* is an exact sum and the same seed gives the same noise in every engine.
|
|
10
|
+
* `Hashes.hash3` is unsigned, which keeps `% 12` in range.
|
|
11
|
+
*/
|
|
12
|
+
export function cubeEdge3(
|
|
13
|
+
cx: number,
|
|
14
|
+
cy: number,
|
|
15
|
+
cz: number,
|
|
16
|
+
dx: number,
|
|
17
|
+
dy: number,
|
|
18
|
+
dz: number,
|
|
19
|
+
seed: number
|
|
20
|
+
) {
|
|
21
|
+
switch (Hashes.hash3(cx, cy, cz, seed) % 12) {
|
|
22
|
+
case 0:
|
|
23
|
+
return dx + dy;
|
|
24
|
+
case 1:
|
|
25
|
+
return -dx + dy;
|
|
26
|
+
case 2:
|
|
27
|
+
return dx - dy;
|
|
28
|
+
case 3:
|
|
29
|
+
return -dx - dy;
|
|
30
|
+
case 4:
|
|
31
|
+
return dx + dz;
|
|
32
|
+
case 5:
|
|
33
|
+
return -dx + dz;
|
|
34
|
+
case 6:
|
|
35
|
+
return dx - dz;
|
|
36
|
+
case 7:
|
|
37
|
+
return -dx - dz;
|
|
38
|
+
case 8:
|
|
39
|
+
return dy + dz;
|
|
40
|
+
case 9:
|
|
41
|
+
return -dy + dz;
|
|
42
|
+
case 10:
|
|
43
|
+
return dy - dz;
|
|
44
|
+
default:
|
|
45
|
+
return -dy - dz;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cubeEdge3.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { lowbias32 } from './lowbias.js';
|
|
2
|
+
|
|
3
|
+
// A different odd 32-bit multiplier per input, so the hash is not symmetric:
|
|
4
|
+
// (1, 2) and (2, 1) are mixed differently rather than colliding by design.
|
|
5
|
+
// They are xxHash32's primes, chosen for well-mixed bits rather than any
|
|
6
|
+
// property of noise.
|
|
7
|
+
const SEED_MUL = 0xc2b2ae3d;
|
|
8
|
+
|
|
9
|
+
const X_MUL = 0x9e3779b1;
|
|
10
|
+
const Y_MUL = 0x85ebca77;
|
|
11
|
+
const Z_MUL = 0x165667b1;
|
|
12
|
+
|
|
13
|
+
const INIT = 0x27d4eb2f;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Unsigned 32-bit hash of an integer lattice point and a seed: the source of
|
|
17
|
+
* every gradient, feature point and white noise value in this package.
|
|
18
|
+
*
|
|
19
|
+
* Each input is truncated to int32 (`| 0`), so non-integers hash like their
|
|
20
|
+
* integer part and coordinates 2^32 apart collide; that is where every
|
|
21
|
+
* generator's 2^32-cell repeat comes from. Each coordinate is mixed in with a
|
|
22
|
+
* full {@link lowbias32} round, so neighbouring points get unrelated hashes.
|
|
23
|
+
*
|
|
24
|
+
* The output is part of the package's compatibility contract: changing it
|
|
25
|
+
* changes every map, and the golden-value tests fail when it does.
|
|
26
|
+
*/
|
|
27
|
+
export function hash2(x: number, y: number, seed: number): number {
|
|
28
|
+
let h = Math.imul(seed | 0, SEED_MUL) ^ INIT;
|
|
29
|
+
h = lowbias32(h ^ Math.imul(x | 0, X_MUL));
|
|
30
|
+
h = lowbias32(h ^ Math.imul(y | 0, Y_MUL));
|
|
31
|
+
return h;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** {@link hash2} with a third coordinate, mixed in the same way. */
|
|
35
|
+
export function hash3(x: number, y: number, z: number, seed: number): number {
|
|
36
|
+
let h = Math.imul(seed | 0, SEED_MUL) ^ INIT;
|
|
37
|
+
h = lowbias32(h ^ Math.imul(x | 0, X_MUL));
|
|
38
|
+
h = lowbias32(h ^ Math.imul(y | 0, Y_MUL));
|
|
39
|
+
h = lowbias32(h ^ Math.imul(z | 0, Z_MUL));
|
|
40
|
+
return h;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Hashes from './hashes.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scrambles a 32-bit integer so that flipping any input bit flips about half
|
|
3
|
+
* the output bits, returned unsigned. This is Chris Wellons' `lowbias32`
|
|
4
|
+
* (hash-prospector), found by search for low bias. It is a bijection, so
|
|
5
|
+
* distinct inputs never collide, and 0 maps to 0.
|
|
6
|
+
*
|
|
7
|
+
* Used both inside {@link hash2}/{@link hash3} and on its own to draw further
|
|
8
|
+
* independent values from one hash, as cellular noise does for each point's
|
|
9
|
+
* x, y and z.
|
|
10
|
+
*/
|
|
11
|
+
export function lowbias32(h: number): number {
|
|
12
|
+
h ^= h >>> 16;
|
|
13
|
+
h = Math.imul(h, 0x7feb352d);
|
|
14
|
+
h ^= h >>> 15;
|
|
15
|
+
h = Math.imul(h, 0x846ca68b);
|
|
16
|
+
h ^= h >>> 16;
|
|
17
|
+
return h >>> 0;
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Brand } from '@cult-frog/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A 2D noise map: one `Float32Array` holding a two-number header, then every
|
|
5
|
+
* cell's value in row-major order (x fastest).
|
|
6
|
+
*
|
|
7
|
+
* @example [width, height, value, value, value, value, ...]
|
|
8
|
+
*
|
|
9
|
+
* It is a plain typed array, so it can be posted to a worker, transferred, or
|
|
10
|
+
* uploaded without copying. The brand stops an arbitrary `Float32Array` being
|
|
11
|
+
* passed where a map is expected; make maps with `Noise2D.create` or a
|
|
12
|
+
* generator. Never write to the header: every helper reads the size from it, so
|
|
13
|
+
* changing it makes `get`, `set` and `forEach` index the wrong cells. Use
|
|
14
|
+
* `Noise2D.getValues` for a view of the cells alone.
|
|
15
|
+
*/
|
|
16
|
+
export type Noise2D = Brand<Float32Array, 'Noise2D'> & {
|
|
17
|
+
/** Width in cells. Part of the header: read-only by contract. */
|
|
18
|
+
0: number;
|
|
19
|
+
/** Height in cells. Part of the header: read-only by contract. */
|
|
20
|
+
1: number;
|
|
21
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Brand } from '@cult-frog/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A 3D noise map: one `Float32Array` holding a three-number header, then every
|
|
5
|
+
* cell's value with x varying fastest, then y, then z, so each z layer is one
|
|
6
|
+
* contiguous 2D slice.
|
|
7
|
+
*
|
|
8
|
+
* @example [width, height, depth, value, value, value, value, value, value, ...]
|
|
9
|
+
*
|
|
10
|
+
* It is a plain typed array, so it can be posted to a worker, transferred, or
|
|
11
|
+
* uploaded without copying. The brand stops an arbitrary `Float32Array` being
|
|
12
|
+
* passed where a map is expected; make maps with `Noise3D.create` or a
|
|
13
|
+
* generator. Never write to the header: every helper reads the size from it, so
|
|
14
|
+
* changing it makes `get`, `set` and `forEach` index the wrong cells. Use
|
|
15
|
+
* `Noise3D.getValues` for a view of the cells alone.
|
|
16
|
+
*/
|
|
17
|
+
export type Noise3D = Brand<Float32Array, 'Noise3D'> & {
|
|
18
|
+
/** Width in cells. Part of the header: read-only by contract. */
|
|
19
|
+
0: number;
|
|
20
|
+
/** Height in cells. Part of the header: read-only by contract. */
|
|
21
|
+
1: number;
|
|
22
|
+
/** Depth in cells. Part of the header: read-only by contract. */
|
|
23
|
+
2: number;
|
|
24
|
+
};
|