noise
stableProcedural noise generation including Perlin, Simplex, fBm, Voronoi, and domain-warp variants for 2D and 3D use cases.
use plugin noise::{perlin2d, simplex2d, fbm2d, …} Functions (16)
- perlin2d Perlin gradient noise at a 2D point
- simplex2d Simplex noise at a 2D point
- fbm2d Fractional Brownian Motion noise in 2D
- value_noise2d Value noise at a 2D point
- white_noise Single pseudo-random value from a seed
- generate_noise_map Generate a flat Perlin noise map
- perlin3d Perlin gradient noise at a 3D point
- fbm3d Fractional Brownian Motion noise in 3D
- voronoi3d Voronoi (cellular) noise in 3D
- ridged_noise2d Ridged multifractal noise for terrain ridges
- turbulence2d Absolute-value noise for fire and smoke
- domain_warp2d Warp 2D coordinates using Perlin offsets
- voronoi2d Voronoi (cellular/Worley) noise in 2D
- billow2d Billow noise for cloud-like shapes
- generate_tileable_noise Seamlessly tiling noise map
- noise_to_color_ramp Map a noise value to an RGB color via stops
Overview
noise is a dependency-free procedural noise library for generating natural-looking
randomness: terrain heightmaps, cloud textures, organic patterns, and animated
effects. It is stateless — every function is a pure call that takes coordinates plus
an integer seed and returns a deterministic result, so the same inputs always
yield the same output and there is no handle to create or dispose of. The seed drives
an internal permutation table, so changing it gives you a completely independent
noise field.
Scalar samplers (perlin2d, simplex2d, value_noise2d, perlin3d) return a single
float roughly in [-1, 1]. The fractal helpers (fbm2d, ridged_noise2d,
turbulence2d, billow2d) layer several octaves of that base noise to add detail.
Cellular samplers (voronoi2d, voronoi3d) and domain_warp2d return small tables
of named fields, the grid builders (generate_noise_map, generate_tileable_noise)
return flat row-major tables of values, and noise_to_color_ramp turns a scalar into
an {r, g, b} color. Use the plugin whenever you need smooth, controllable
pseudo-randomness rather than the uncorrelated values of a normal RNG.
Common patterns
Build a heightmap and color each sample through a ramp:
use plugin noise::{generate_noise_map, noise_to_color_ramp}
let stops = #{
1: #{t: 0.0, r: 0.1, g: 0.2, b: 0.6},
2: #{t: 0.5, r: 0.8, g: 0.7, b: 0.4},
3: #{t: 1.0, r: 0.2, g: 0.5, b: 0.1}
}
let map = generate_noise_map(16, 16, 8.0, 7)
let first = (map[1] + 1.0) / 2.0
let color = noise_to_color_ramp(first, stops)
print("top-left color: r={color["r"]} g={color["g"]} b={color["b"]}")
Warp coordinates, then sample fractal noise through them for organic swirls:
use plugin noise::{domain_warp2d, fbm2d}
let warped = domain_warp2d(2.0, 1.5, 1.8, 0.6, 3)
let v = fbm2d(warped["wx"], warped["wy"], 6, 1.0, 0.5, 3)
print("warped fbm: {v}")
Animate 2D noise by sweeping the z axis of a 3D sampler over time:
use plugin noise::{perlin3d}
for frame in 0..4 {
let t = frame * 0.25
let v = perlin3d(1.0, 2.0, t, 99)
print("frame {frame}: {v}")
}
Perlin gradient noise at a 2D point
Evaluates classic Perlin gradient noise at position (x, y) using the given integer seed. Returns a value roughly in [-1, 1]. Seed controls the permutation table so different seeds produce independent noise fields.
use plugin noise::{perlin2d}
let v = perlin2d(1.5, 2.3, 42)
print("noise: {v}")
Simplex noise at a 2D point
Evaluates Simplex noise at (x, y). Simplex noise has fewer directional artifacts than Perlin and scales better to higher dimensions. Returns values in approximately [-1, 1].
use plugin noise::{simplex2d}
let v = simplex2d(0.5, 0.5, 0)
print("simplex: {v}")
Fractional Brownian Motion noise in 2D
Fractional Brownian Motion — sums multiple octaves of Perlin noise with increasing frequency and decreasing amplitude. Higher octaves adds fine detail; persistence controls how quickly amplitude falls off per octave.
use plugin noise::{fbm2d}
let v = fbm2d(1.0, 1.0, 6, 1.0, 0.5, 12)
print("fbm: {v}")
Lowering persistence makes higher octaves contribute less, producing smoother
output; raising it adds more high-frequency roughness:
use plugin noise::{fbm2d}
let smooth = fbm2d(4.0, 4.0, 6, 1.0, 0.3, 1)
let rough = fbm2d(4.0, 4.0, 6, 1.0, 0.8, 1)
print("smooth: {smooth}, rough: {rough}")
Value noise at a 2D point
Evaluates value noise at (x, y). Unlike gradient noise, value noise assigns random values to lattice points and interpolates between them. Returns values in [-1, 1].
use plugin noise::{value_noise2d}
let v = value_noise2d(3.0, 1.5, 7)
print("value noise: {v}")
Single pseudo-random value from a seed
Returns a single pseudo-random float in [-1, 1] derived from the seed via hash. Each unique seed produces a distinct value with no spatial correlation.
use plugin noise::{white_noise}
let r = white_noise(12345)
print("random: {r}")
Generate a flat Perlin noise map
Generates a flat table of Perlin noise values for a width × height grid. Each entry is indexed 1..width*height in row-major order. scale controls the zoom level — larger values produce more zoomed-in noise.
use plugin noise::{generate_noise_map}
let map = generate_noise_map(64, 64, 32.0, 0)
let center = map[32 * 64 + 32]
print("center: {center}")
Because the table is row-major and 1-indexed, you can walk a single row by
stepping over width entries:
use plugin noise::{generate_noise_map}
let map = generate_noise_map(8, 8, 4.0, 1)
for x in 0..8 {
let idx = 0 * 8 + x + 1
print("row 0 col {x}: {map[idx]}")
}
Perlin gradient noise at a 3D point
Evaluates 3D Perlin noise at (x, y, z). Useful for volumetric effects, animated 2D noise (using time as z), or 3D terrain.
use plugin noise::{perlin3d}
let v = perlin3d(1.0, 2.0, 0.5, 99)
print("3d perlin: {v}")
Fractional Brownian Motion noise in 3D
3D Fractional Brownian Motion. Sums multiple octaves of 3D Perlin noise. Use with a time coordinate for smoothly animated noise.
use plugin noise::{fbm3d}
let v = fbm3d(1.0, 1.0, 0.0, 5, 1.0, 0.5, 0)
print("fbm3d: {v}")
Voronoi (cellular) noise in 3D
Computes 3D Voronoi (cellular/Worley) noise. Returns {distance, cell_x, cell_y, cell_z} where distance is the Euclidean distance to the nearest cell center point.
use plugin noise::{voronoi3d}
let result = voronoi3d(1.5, 2.5, 0.5, 42)
print("distance: {result["distance"]}")
Ridged multifractal noise for terrain ridges
Ridged multifractal noise — inverts the absolute value of Perlin noise to create sharp ridges. Well-suited for mountain ranges and rocky terrain. lacunarity controls frequency growth per octave.
use plugin noise::{ridged_noise2d}
let v = ridged_noise2d(2.0, 3.0, 6, 1.0, 2.0, 5)
print("ridged: {v}")
Absolute-value noise for fire and smoke
Turbulence noise sums the absolute values of multiple Perlin octaves. Produces a boiling, fire-like appearance. All octave amplitudes halve per step with frequency doubling.
use plugin noise::{turbulence2d}
let v = turbulence2d(1.0, 1.0, 5, 1.0, 3)
print("turbulence: {v}")
Warp 2D coordinates using Perlin offsets
Warps the input coordinates (x, y) by two independent Perlin noise fields before sampling. Returns {wx, wy} — the warped coordinates. Feed the warped coordinates into another noise call for organic, swirling patterns.
use plugin noise::{domain_warp2d, fbm2d}
let warped = domain_warp2d(1.0, 1.0, 1.5, 0.8, 0)
let v = fbm2d(warped["wx"], warped["wy"], 5, 1.0, 0.5, 0)
print("warped fbm: {v}")
Voronoi (cellular/Worley) noise in 2D
Computes 2D Voronoi (cellular/Worley) noise. Returns {distance, cell_x, cell_y} — the distance to the nearest random cell center and the center's coordinates. Useful for cracks, stones, and stylized textures.
use plugin noise::{voronoi2d}
let result = voronoi2d(2.5, 1.5, 7)
print("dist: {result["distance"]}, cell: ({result["cell_x"]}, {result["cell_y"]})")
The returned distance makes a convenient cell-edge mask — small distances sit
near a cell center, larger ones near the seams between cells:
use plugin noise::{voronoi2d}
let cell = voronoi2d(5.2, 3.7, 1)
if cell["distance"] < 0.2 {
print("near a cell center")
} else {
print("near a cell edge")
}
Billow noise for cloud-like shapes
Billow noise maps Perlin values through |n| * 2 - 1, producing a billowy, cloud-like appearance. Useful for cumulus clouds and rolling hills.
use plugin noise::{billow2d}
let v = billow2d(1.0, 2.0, 4, 1.0, 11)
print("billow: {v}")
Seamlessly tiling noise map
Generates a seamlessly tiling noise map using bilinear blending of wrapped Perlin samples. The result tiles perfectly when repeated edge-to-edge, making it suitable for texture atlases and repeating backgrounds.
use plugin noise::{generate_tileable_noise}
let tile = generate_tileable_noise(32, 32, 16.0, 42)
Map a noise value to an RGB color via stops
Maps a scalar noise value to an RGB color by interpolating between a sorted list of color stops. Each stop is a table {t, r, g, b} where t is the position in [0, 1] and r, g, b are color components in [0, 1]. Returns {r, g, b}.
use plugin noise::{fbm2d, noise_to_color_ramp}
let stops = #{
1: #{t: 0.0, r: 0.1, g: 0.1, b: 0.6},
2: #{t: 0.4, r: 0.8, g: 0.7, b: 0.3},
3: #{t: 1.0, r: 0.2, g: 0.5, b: 0.1}
}
let v = (fbm2d(1.0, 2.0, 5, 1.0, 0.5, 0) + 1.0) / 2.0
let color = noise_to_color_ramp(v, stops)
print("r={color["r"]} g={color["g"]} b={color["b"]}")