The pack
procgen
function procgen(): Pack<{ procgen: ProcgenApi }>
The procgen pack: seeded noise functions (Perlin 2D/3D, value, Worley, fBm, ridged, turbulence, curl) and noise textures into the atlas. Headless, pure. Assets it does not make; fields it does.
Helpers
fbm2
function fbm2(x: number, y: number, perm: Uint8Array, opts: FbmOptions = {}): number
Fractal Brownian motion over perlin2: octaves summed and normalised to about [-1, 1].
hashInts
function hashInts(...ns: number[]): number
A 32-bit FNV-1a hash of a list of integers (each as four bytes): deterministic and platform independent, for seeding a stream per slot (mulberry32(hashInts(seed, i, j))).
mulberry32
function mulberry32(seed: number): () => number
A seeded [0,1) stream for code that wants its own deterministic sequence: the kernel's createRng(seed).next, kept
under its old name for callers that seed a stream per slot (mulberry32(hashInts(seed, i, j))). The name is
historical; the generator is the kernel's xoshiro128**. New code should call createRng directly.
noiseCanvas
function noiseCanvas(opts: NoiseTextureOptions & { alpha?: boolean; mask?: 'radial' } = {}): OffscreenCanvas | null
Paint a noise field onto a canvas: greyscale, or white with the field as alpha; mask: 'radial' fades to the edge (a puff). Null headless.
noisePerm
function noisePerm(seed = 1): Uint8Array
A 512-entry permutation table from a seed: what every noise function samples. Make one per field and keep it.
perlin2
function perlin2(x: number, y: number, perm: Uint8Array, period = 0): number
2D Perlin gradient noise in about [-1, 1]; period (in lattice cells) makes it tile. Sample at x * frequency.
Functions
curl2
function curl2(x: number, y: number, perm: Uint8Array, opts: FbmOptions = {}, eps = 0.01): [number, number]
Divergence-free 2D curl of fbm2: a swirling flow field [vx, vy] for particles, smoke, water.
fbm3
function fbm3(x: number, y: number, z: number, perm: Uint8Array, opts: FbmOptions = {}): number
fbm2 in three dimensions.
hash2
function hash2(x: number, y: number, seed = 0): number
An integer hash to [0,1): the same (x, y, seed) always gives the same value. For per-cell randomness with no table.
hash3
function hash3(x: number, y: number, z: number, seed = 0): number
hash2 in three dimensions.
noiseData
function noiseData(opts: NoiseTextureOptions = {}): { data: Float32Array; size: number }
The field as floats in [0, 1], row-major, size×size.
perlin3
function perlin3(x: number, y: number, z: number, perm: Uint8Array, period = 0): number
3D Perlin gradient noise in about [-1, 1]; period tiles every axis. Terrain, clouds, a time axis for animated 2D fields.
ridged2
function ridged2(x: number, y: number, perm: Uint8Array, opts: FbmOptions = {}): number
Ridged multifractal over perlin2: 1 - |noise| per octave, sharp crests — mountain ridges, lightning, veins. In [0, 1].
turbulence2
function turbulence2(x: number, y: number, perm: Uint8Array, opts: FbmOptions = {}): number
Turbulence over perlin2: |noise| summed — billowy, always positive. In [0, 1].
value2
function value2(x: number, y: number, seed = 0, period = 0): number
2D value noise in [0, 1]: smooth-interpolated lattice randoms, cheaper and blockier than Perlin. period tiles.
worley2
function worley2(x: number, y: number, seed = 0, period = 0): number
2D Worley (cellular) noise: the distance to the nearest of one random point per lattice cell, in about [0, 1]. Cells, scales, cracked earth. period tiles.
Types
FbmOptions
interface FbmOptions
How octaves stack.
octaves?: number— Layers. Default 4.lacunarity?: number— Frequency multiplier per octave. Default 2.gain?: number— Amplitude multiplier per octave. Default 0.5.period?: number— Tiling period in cells at the base frequency; 0 = none. Default 0.
NoiseTextureOptions
interface NoiseTextureOptions
A noise field sampled into a square grid.
size?: number— Pixels per side. Default 256.cell?: number— Pixels per lattice cell at the base frequency. Default size / 4.octaves?: number— Octaves. Default 4.seed?: number— Seed. Default 1.tile?: boolean— Tile seamlessly. Default true.lacunarity?: number— Frequency multiplier per octave. Default 2.gain?: number— Amplitude multiplier per octave. Default 0.5.kind?: 'fbm' | 'ridged' | 'turbulence' | 'worley' | 'value'— Which field: 'fbm' (default), 'ridged', 'turbulence', 'worley', 'value'.
ProcgenApi
interface ProcgenApi
game.procgen: every function of this module, plus noiseFrame which paints a field straight into the atlas.
mulberry32: typeof mulberry32— A seeded [0,1) stream.noisePerm: typeof noisePerm— A permutation table from a seed.hash2: typeof hash2— Integer hash to [0,1).hash3: typeof hash3— Integer hash, 3D.perlin2: typeof perlin2— 2D Perlin.perlin3: typeof perlin3— 3D Perlin.value2: typeof value2— 2D value noise.worley2: typeof worley2— 2D Worley.fbm2: typeof fbm2— fBm over perlin2.fbm3: typeof fbm3— fBm over perlin3.ridged2: typeof ridged2— Ridged multifractal.turbulence2: typeof turbulence2— Turbulence.curl2: typeof curl2— Curl of fbm2.noiseData: typeof noiseData— A field as floats.noiseCanvas: typeof noiseCanvas— A field as a canvas.noiseFrame(key: string, opts?: NoiseTextureOptions & { alpha?: boolean; mask?: 'radial' }): number— Paint a noise field into the atlas underkey(headless: a blank frame) and return its frame index. Throws on a key already in the atlas.readonly seed: number— The kernel's seed, for fields that should follow the game's.


