@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.
Files changed (264) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +21 -0
  3. package/README.md +205 -2
  4. package/dist/fractal/_types/fractalOptions.d.ts +36 -0
  5. package/dist/fractal/_types/fractalOptions.d.ts.map +1 -0
  6. package/dist/fractal/_types/fractalOptions.js +2 -0
  7. package/dist/fractal/_types/fractalOptions.js.map +1 -0
  8. package/dist/fractal/_types/index.d.ts +2 -0
  9. package/dist/fractal/_types/index.d.ts.map +1 -0
  10. package/dist/fractal/_types/index.js +2 -0
  11. package/dist/fractal/_types/index.js.map +1 -0
  12. package/dist/fractal/fractal.d.ts +17 -0
  13. package/dist/fractal/fractal.d.ts.map +1 -0
  14. package/dist/fractal/fractal.js +31 -0
  15. package/dist/fractal/fractal.js.map +1 -0
  16. package/dist/fractal/index.d.ts +4 -0
  17. package/dist/fractal/index.d.ts.map +1 -0
  18. package/dist/fractal/index.js +3 -0
  19. package/dist/fractal/index.js.map +1 -0
  20. package/dist/fractal/options.d.ts +14 -0
  21. package/dist/fractal/options.d.ts.map +1 -0
  22. package/dist/fractal/options.js +57 -0
  23. package/dist/fractal/options.js.map +1 -0
  24. package/dist/gradient/cubeEdge3.d.ts +11 -0
  25. package/dist/gradient/cubeEdge3.d.ts.map +1 -0
  26. package/dist/gradient/cubeEdge3.js +39 -0
  27. package/dist/gradient/cubeEdge3.js.map +1 -0
  28. package/dist/gradient/index.d.ts +2 -0
  29. package/dist/gradient/index.d.ts.map +1 -0
  30. package/dist/gradient/index.js +2 -0
  31. package/dist/gradient/index.js.map +1 -0
  32. package/dist/hashes/hash.d.ts +16 -0
  33. package/dist/hashes/hash.d.ts.map +1 -0
  34. package/dist/hashes/hash.js +37 -0
  35. package/dist/hashes/hash.js.map +1 -0
  36. package/dist/hashes/hashes.d.ts +3 -0
  37. package/dist/hashes/hashes.d.ts.map +1 -0
  38. package/dist/hashes/hashes.js +3 -0
  39. package/dist/hashes/hashes.js.map +1 -0
  40. package/dist/hashes/index.d.ts +2 -0
  41. package/dist/hashes/index.d.ts.map +1 -0
  42. package/dist/hashes/index.js +2 -0
  43. package/dist/hashes/index.js.map +1 -0
  44. package/dist/hashes/lowbias.d.ts +12 -0
  45. package/dist/hashes/lowbias.d.ts.map +1 -0
  46. package/dist/hashes/lowbias.js +19 -0
  47. package/dist/hashes/lowbias.js.map +1 -0
  48. package/dist/index.d.ts +4 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +3 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/noiseMap/_types/index.d.ts +3 -0
  53. package/dist/noiseMap/_types/index.d.ts.map +1 -0
  54. package/dist/noiseMap/_types/index.js +2 -0
  55. package/dist/noiseMap/_types/index.js.map +1 -0
  56. package/dist/noiseMap/_types/noise2d.d.ts +21 -0
  57. package/dist/noiseMap/_types/noise2d.d.ts.map +1 -0
  58. package/dist/noiseMap/_types/noise2d.js +2 -0
  59. package/dist/noiseMap/_types/noise2d.js.map +1 -0
  60. package/dist/noiseMap/_types/noise3d.d.ts +24 -0
  61. package/dist/noiseMap/_types/noise3d.d.ts.map +1 -0
  62. package/dist/noiseMap/_types/noise3d.js +2 -0
  63. package/dist/noiseMap/_types/noise3d.js.map +1 -0
  64. package/dist/noiseMap/index.d.ts +6 -0
  65. package/dist/noiseMap/index.d.ts.map +1 -0
  66. package/dist/noiseMap/index.js +3 -0
  67. package/dist/noiseMap/index.js.map +1 -0
  68. package/dist/noiseMap/noise2d.d.ts +52 -0
  69. package/dist/noiseMap/noise2d.d.ts.map +1 -0
  70. package/dist/noiseMap/noise2d.js +105 -0
  71. package/dist/noiseMap/noise2d.js.map +1 -0
  72. package/dist/noiseMap/noise3d.d.ts +62 -0
  73. package/dist/noiseMap/noise3d.d.ts.map +1 -0
  74. package/dist/noiseMap/noise3d.js +129 -0
  75. package/dist/noiseMap/noise3d.js.map +1 -0
  76. package/dist/noiseTypes/cellular/2d.d.ts +36 -0
  77. package/dist/noiseTypes/cellular/2d.d.ts.map +1 -0
  78. package/dist/noiseTypes/cellular/2d.js +123 -0
  79. package/dist/noiseTypes/cellular/2d.js.map +1 -0
  80. package/dist/noiseTypes/cellular/3d.d.ts +32 -0
  81. package/dist/noiseTypes/cellular/3d.d.ts.map +1 -0
  82. package/dist/noiseTypes/cellular/3d.js +143 -0
  83. package/dist/noiseTypes/cellular/3d.js.map +1 -0
  84. package/dist/noiseTypes/cellular/_types/index.d.ts +2 -0
  85. package/dist/noiseTypes/cellular/_types/index.d.ts.map +1 -0
  86. package/dist/noiseTypes/cellular/_types/index.js +2 -0
  87. package/dist/noiseTypes/cellular/_types/index.js.map +1 -0
  88. package/dist/noiseTypes/cellular/_types/options.d.ts +37 -0
  89. package/dist/noiseTypes/cellular/_types/options.d.ts.map +1 -0
  90. package/dist/noiseTypes/cellular/_types/options.js +2 -0
  91. package/dist/noiseTypes/cellular/_types/options.js.map +1 -0
  92. package/dist/noiseTypes/cellular/defaultOptions.d.ts +4 -0
  93. package/dist/noiseTypes/cellular/defaultOptions.d.ts.map +1 -0
  94. package/dist/noiseTypes/cellular/defaultOptions.js +13 -0
  95. package/dist/noiseTypes/cellular/defaultOptions.js.map +1 -0
  96. package/dist/noiseTypes/cellular/floorDiv.d.ts +18 -0
  97. package/dist/noiseTypes/cellular/floorDiv.d.ts.map +1 -0
  98. package/dist/noiseTypes/cellular/floorDiv.js +28 -0
  99. package/dist/noiseTypes/cellular/floorDiv.js.map +1 -0
  100. package/dist/noiseTypes/cellular/index.d.ts +4 -0
  101. package/dist/noiseTypes/cellular/index.d.ts.map +1 -0
  102. package/dist/noiseTypes/cellular/index.js +3 -0
  103. package/dist/noiseTypes/cellular/index.js.map +1 -0
  104. package/dist/noiseTypes/cellular/options.d.ts +6 -0
  105. package/dist/noiseTypes/cellular/options.d.ts.map +1 -0
  106. package/dist/noiseTypes/cellular/options.js +20 -0
  107. package/dist/noiseTypes/cellular/options.js.map +1 -0
  108. package/dist/noiseTypes/index.d.ts +5 -0
  109. package/dist/noiseTypes/index.d.ts.map +1 -0
  110. package/dist/noiseTypes/index.js +5 -0
  111. package/dist/noiseTypes/index.js.map +1 -0
  112. package/dist/noiseTypes/perlin/2d.d.ts +23 -0
  113. package/dist/noiseTypes/perlin/2d.d.ts.map +1 -0
  114. package/dist/noiseTypes/perlin/2d.js +64 -0
  115. package/dist/noiseTypes/perlin/2d.js.map +1 -0
  116. package/dist/noiseTypes/perlin/3d.d.ts +24 -0
  117. package/dist/noiseTypes/perlin/3d.d.ts.map +1 -0
  118. package/dist/noiseTypes/perlin/3d.js +69 -0
  119. package/dist/noiseTypes/perlin/3d.js.map +1 -0
  120. package/dist/noiseTypes/perlin/_types/index.d.ts +2 -0
  121. package/dist/noiseTypes/perlin/_types/index.d.ts.map +1 -0
  122. package/dist/noiseTypes/perlin/_types/index.js +2 -0
  123. package/dist/noiseTypes/perlin/_types/index.js.map +1 -0
  124. package/dist/noiseTypes/perlin/_types/options.d.ts +22 -0
  125. package/dist/noiseTypes/perlin/_types/options.d.ts.map +1 -0
  126. package/dist/noiseTypes/perlin/_types/options.js +2 -0
  127. package/dist/noiseTypes/perlin/_types/options.js.map +1 -0
  128. package/dist/noiseTypes/perlin/defaultOptions.d.ts +4 -0
  129. package/dist/noiseTypes/perlin/defaultOptions.d.ts.map +1 -0
  130. package/dist/noiseTypes/perlin/defaultOptions.js +14 -0
  131. package/dist/noiseTypes/perlin/defaultOptions.js.map +1 -0
  132. package/dist/noiseTypes/perlin/index.d.ts +4 -0
  133. package/dist/noiseTypes/perlin/index.d.ts.map +1 -0
  134. package/dist/noiseTypes/perlin/index.js +3 -0
  135. package/dist/noiseTypes/perlin/index.js.map +1 -0
  136. package/dist/noiseTypes/perlin/options.d.ts +9 -0
  137. package/dist/noiseTypes/perlin/options.d.ts.map +1 -0
  138. package/dist/noiseTypes/perlin/options.js +17 -0
  139. package/dist/noiseTypes/perlin/options.js.map +1 -0
  140. package/dist/noiseTypes/perlin/sample2.d.ts +25 -0
  141. package/dist/noiseTypes/perlin/sample2.d.ts.map +1 -0
  142. package/dist/noiseTypes/perlin/sample2.js +58 -0
  143. package/dist/noiseTypes/perlin/sample2.js.map +1 -0
  144. package/dist/noiseTypes/perlin/sample3.d.ts +9 -0
  145. package/dist/noiseTypes/perlin/sample3.d.ts.map +1 -0
  146. package/dist/noiseTypes/perlin/sample3.js +38 -0
  147. package/dist/noiseTypes/perlin/sample3.js.map +1 -0
  148. package/dist/noiseTypes/simplex/2d.d.ts +23 -0
  149. package/dist/noiseTypes/simplex/2d.d.ts.map +1 -0
  150. package/dist/noiseTypes/simplex/2d.js +64 -0
  151. package/dist/noiseTypes/simplex/2d.js.map +1 -0
  152. package/dist/noiseTypes/simplex/3d.d.ts +25 -0
  153. package/dist/noiseTypes/simplex/3d.d.ts.map +1 -0
  154. package/dist/noiseTypes/simplex/3d.js +70 -0
  155. package/dist/noiseTypes/simplex/3d.js.map +1 -0
  156. package/dist/noiseTypes/simplex/_types/index.d.ts +2 -0
  157. package/dist/noiseTypes/simplex/_types/index.d.ts.map +1 -0
  158. package/dist/noiseTypes/simplex/_types/index.js +2 -0
  159. package/dist/noiseTypes/simplex/_types/index.js.map +1 -0
  160. package/dist/noiseTypes/simplex/_types/options.d.ts +33 -0
  161. package/dist/noiseTypes/simplex/_types/options.d.ts.map +1 -0
  162. package/dist/noiseTypes/simplex/_types/options.js +2 -0
  163. package/dist/noiseTypes/simplex/_types/options.js.map +1 -0
  164. package/dist/noiseTypes/simplex/defaultOptions.d.ts +4 -0
  165. package/dist/noiseTypes/simplex/defaultOptions.d.ts.map +1 -0
  166. package/dist/noiseTypes/simplex/defaultOptions.js +14 -0
  167. package/dist/noiseTypes/simplex/defaultOptions.js.map +1 -0
  168. package/dist/noiseTypes/simplex/index.d.ts +4 -0
  169. package/dist/noiseTypes/simplex/index.d.ts.map +1 -0
  170. package/dist/noiseTypes/simplex/index.js +3 -0
  171. package/dist/noiseTypes/simplex/index.js.map +1 -0
  172. package/dist/noiseTypes/simplex/options.d.ts +9 -0
  173. package/dist/noiseTypes/simplex/options.d.ts.map +1 -0
  174. package/dist/noiseTypes/simplex/options.js +17 -0
  175. package/dist/noiseTypes/simplex/options.js.map +1 -0
  176. package/dist/noiseTypes/simplex/sample2.d.ts +32 -0
  177. package/dist/noiseTypes/simplex/sample2.d.ts.map +1 -0
  178. package/dist/noiseTypes/simplex/sample2.js +94 -0
  179. package/dist/noiseTypes/simplex/sample2.js.map +1 -0
  180. package/dist/noiseTypes/simplex/sample3.d.ts +19 -0
  181. package/dist/noiseTypes/simplex/sample3.d.ts.map +1 -0
  182. package/dist/noiseTypes/simplex/sample3.js +110 -0
  183. package/dist/noiseTypes/simplex/sample3.js.map +1 -0
  184. package/dist/noiseTypes/white/2d.d.ts +18 -0
  185. package/dist/noiseTypes/white/2d.d.ts.map +1 -0
  186. package/dist/noiseTypes/white/2d.js +33 -0
  187. package/dist/noiseTypes/white/2d.js.map +1 -0
  188. package/dist/noiseTypes/white/3d.d.ts +17 -0
  189. package/dist/noiseTypes/white/3d.d.ts.map +1 -0
  190. package/dist/noiseTypes/white/3d.js +34 -0
  191. package/dist/noiseTypes/white/3d.js.map +1 -0
  192. package/dist/noiseTypes/white/_types/index.d.ts +2 -0
  193. package/dist/noiseTypes/white/_types/index.d.ts.map +1 -0
  194. package/dist/noiseTypes/white/_types/index.js +2 -0
  195. package/dist/noiseTypes/white/_types/index.js.map +1 -0
  196. package/dist/noiseTypes/white/_types/options.d.ts +28 -0
  197. package/dist/noiseTypes/white/_types/options.d.ts.map +1 -0
  198. package/dist/noiseTypes/white/_types/options.js +2 -0
  199. package/dist/noiseTypes/white/_types/options.js.map +1 -0
  200. package/dist/noiseTypes/white/defaultOptions.d.ts +4 -0
  201. package/dist/noiseTypes/white/defaultOptions.d.ts.map +1 -0
  202. package/dist/noiseTypes/white/defaultOptions.js +10 -0
  203. package/dist/noiseTypes/white/defaultOptions.js.map +1 -0
  204. package/dist/noiseTypes/white/index.d.ts +4 -0
  205. package/dist/noiseTypes/white/index.d.ts.map +1 -0
  206. package/dist/noiseTypes/white/index.js +3 -0
  207. package/dist/noiseTypes/white/index.js.map +1 -0
  208. package/dist/noiseTypes/white/options.d.ts +6 -0
  209. package/dist/noiseTypes/white/options.d.ts.map +1 -0
  210. package/dist/noiseTypes/white/options.js +14 -0
  211. package/dist/noiseTypes/white/options.js.map +1 -0
  212. package/package.json +78 -4
  213. package/src/fractal/_types/fractalOptions.ts +35 -0
  214. package/src/fractal/_types/index.ts +1 -0
  215. package/src/fractal/fractal.ts +41 -0
  216. package/src/fractal/index.ts +4 -0
  217. package/src/fractal/options.ts +62 -0
  218. package/src/gradient/cubeEdge3.ts +47 -0
  219. package/src/gradient/index.ts +1 -0
  220. package/src/hashes/hash.ts +41 -0
  221. package/src/hashes/hashes.ts +2 -0
  222. package/src/hashes/index.ts +1 -0
  223. package/src/hashes/lowbias.ts +18 -0
  224. package/src/index.ts +4 -0
  225. package/src/noiseMap/_types/index.ts +2 -0
  226. package/src/noiseMap/_types/noise2d.ts +21 -0
  227. package/src/noiseMap/_types/noise3d.ts +24 -0
  228. package/src/noiseMap/index.ts +7 -0
  229. package/src/noiseMap/noise2d.ts +117 -0
  230. package/src/noiseMap/noise3d.ts +146 -0
  231. package/src/noiseTypes/cellular/2d.ts +142 -0
  232. package/src/noiseTypes/cellular/3d.ts +171 -0
  233. package/src/noiseTypes/cellular/_types/index.ts +1 -0
  234. package/src/noiseTypes/cellular/_types/options.ts +37 -0
  235. package/src/noiseTypes/cellular/defaultOptions.ts +15 -0
  236. package/src/noiseTypes/cellular/floorDiv.ts +27 -0
  237. package/src/noiseTypes/cellular/index.ts +4 -0
  238. package/src/noiseTypes/cellular/options.ts +20 -0
  239. package/src/noiseTypes/index.ts +4 -0
  240. package/src/noiseTypes/perlin/2d.ts +86 -0
  241. package/src/noiseTypes/perlin/3d.ts +93 -0
  242. package/src/noiseTypes/perlin/_types/index.ts +1 -0
  243. package/src/noiseTypes/perlin/_types/options.ts +23 -0
  244. package/src/noiseTypes/perlin/defaultOptions.ts +16 -0
  245. package/src/noiseTypes/perlin/index.ts +4 -0
  246. package/src/noiseTypes/perlin/options.ts +19 -0
  247. package/src/noiseTypes/perlin/sample2.ts +62 -0
  248. package/src/noiseTypes/perlin/sample3.ts +43 -0
  249. package/src/noiseTypes/simplex/2d.ts +86 -0
  250. package/src/noiseTypes/simplex/3d.ts +94 -0
  251. package/src/noiseTypes/simplex/_types/index.ts +1 -0
  252. package/src/noiseTypes/simplex/_types/options.ts +34 -0
  253. package/src/noiseTypes/simplex/defaultOptions.ts +16 -0
  254. package/src/noiseTypes/simplex/index.ts +4 -0
  255. package/src/noiseTypes/simplex/options.ts +19 -0
  256. package/src/noiseTypes/simplex/sample2.ts +103 -0
  257. package/src/noiseTypes/simplex/sample3.ts +128 -0
  258. package/src/noiseTypes/white/2d.ts +44 -0
  259. package/src/noiseTypes/white/3d.ts +46 -0
  260. package/src/noiseTypes/white/_types/index.ts +1 -0
  261. package/src/noiseTypes/white/_types/options.ts +28 -0
  262. package/src/noiseTypes/white/defaultOptions.ts +12 -0
  263. package/src/noiseTypes/white/index.ts +4 -0
  264. 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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../src/noiseTypes/white/_types/options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { White2dOptions, White3dOptions } from './_types/options.js';
2
+ export declare const DEFAULT_WHITE_2D_OPTIONS: White2dOptions;
3
+ export declare const DEFAULT_WHITE_3D_OPTIONS: White3dOptions;
4
+ //# sourceMappingURL=defaultOptions.d.ts.map
@@ -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,10 @@
1
+ export const DEFAULT_WHITE_2D_OPTIONS = {
2
+ seed: 0,
3
+ offsetX: 0,
4
+ offsetY: 0,
5
+ };
6
+ export const DEFAULT_WHITE_3D_OPTIONS = {
7
+ ...DEFAULT_WHITE_2D_OPTIONS,
8
+ offsetZ: 0,
9
+ };
10
+ //# sourceMappingURL=defaultOptions.js.map
@@ -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,4 @@
1
+ export * as White2 from './2d.js';
2
+ export * as White3 from './3d.js';
3
+ export type * from './_types/index.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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,3 @@
1
+ export * as White2 from './2d.js';
2
+ export * as White3 from './3d.js';
3
+ //# sourceMappingURL=index.js.map
@@ -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.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
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,4 @@
1
+ export * from './fractal.js';
2
+ export * from './options.js';
3
+
4
+ export type { FractalOptions } from './_types/index.js';
@@ -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,2 @@
1
+ export * from './hash.js';
2
+ export * from './lowbias.js';
@@ -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,4 @@
1
+ export * from './noiseMap/index.js';
2
+ export * from './noiseTypes/index.js';
3
+
4
+ export type { FractalOptions } from './fractal/index.js';
@@ -0,0 +1,2 @@
1
+ export type { Noise2D } from './noise2d.js';
2
+ export type { Noise3D } from './noise3d.js';
@@ -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
+ };
@@ -0,0 +1,7 @@
1
+ export * as Noise2D from './noise2d.js';
2
+ export * as Noise3D from './noise3d.js';
3
+
4
+ import type { Noise2D as Noise2DType, Noise3D as Noise3DType } from './_types/index.js';
5
+
6
+ export type Noise2D = Noise2DType;
7
+ export type Noise3D = Noise3DType;