Packages

Work with different noise functions using Elixir. Fork of isotope, maintained for Elixir 1.18+.

Current section

Files

Jump to
isotope_118 lib isotope.ex
Raw

lib/isotope.ex

defmodule Isotope do
@moduledoc """
Elixir bindings to Rust's [bracket-noise](https://crates.io/crates/bracket-noise)
library, which is a Rust port of [FastNoise Lite](https://github.com/Auburn/FastNoiseLite).
Implemented using [NIFs](https://erlang.org/doc/tutorial/nif.html) for performance.
Noise maps are returned as compact binaries of packed `f32` values, using ~4 bytes
per value instead of ~32 bytes for nested Elixir lists.
## Quick Start
# Create a noise generator
{:ok, noise} = Isotope.Noise.new(%Isotope.Options{
seed: 42,
noise_type: :simplex_fractal,
frequency: 0.01,
fractal_options: %Isotope.Options.Fractal{octaves: 4}
})
# Generate a noise map
nm = Isotope.Noise.noise_map(noise, {100, 100})
# Access values
Isotope.NoiseMap.get(nm, 50, 50) # single value
Isotope.NoiseMap.row(nm, 0) # first row as list
Isotope.NoiseMap.to_list(nm) # full nested list
# Works with Enum (iterates rows)
Enum.map(nm, fn row -> Enum.sum(row) / length(row) end)
## Modules
- `Isotope.Noise` — create noise generators, sample individual points,
and generate noise maps or chunks.
- `Isotope.NoiseMap` — compact struct wrapping noise map data with accessors
for individual values, rows, and conversion to lists. Implements `Enumerable`.
- `Isotope.Options` — configuration for noise type, frequency, seed,
fractal parameters, and cellular parameters.
- `Isotope.Utils` — visualization utilities (ANSI terminal output).
"""
end