API Reference › Noise › Noise.unit
method

Noise.unit

Noise.unit(n) -> fixed

Remaps a noise sample from [-1, 1] to [0, 1] — literally n / 2 + 0.5 — returning a fixed. The signed range is the natural output of the samplers, but heights, densities, probabilities, and colour ramps usually want the unsigned [0, 1] range; unit is the one-step conversion. It is a plain affine remap, so unit(-1) == 0, unit(0) == 0.5, and unit(1) == 1.

Parameters

na sample in [-1, 1] (e.g. from perlin2/simplex2/fbm2)

Example

program Unit {
  entry {
    let n = Noise.simplex2(fixed(1) / fixed(2), fixed(1) / fixed(2), 1337)
    let height = Math.floor(Noise.unit(n) * fixed(64))   # 0..64 tiles
    print(height)
  }
}
← All symbols