View Source Perlin (perlin v0.1.0)

An implementation of Ken Perlin's improved Perlin noise algorithm in Elixir.

This module provides functions to generate 3D Perlin noise, which can be used for procedural generation of textures, terrains, and other natural-looking patterns. It includes both single-octave noise generation and multi-octave noise for more complex and detailed results.

The implementation is based on Ken Perlin's improved noise function from 2002, which addressed some of the visual artifacts present in his original 1985 algorithm.

Key features:

  • 3D noise generation
  • Optional repetition of noise pattern
  • Multi-octave noise for more natural-looking results
  • Configurable persistence for octave-based noise

Summary

Functions

Generates 3D Perlin noise for given coordinates.

Generates Perlin noise with multiple octaves.

Functions

Link to this function

noise(x, y, z, repeat \\ -1)

View Source
@spec noise(float(), float(), float(), integer()) :: float()

Generates 3D Perlin noise for given coordinates.

Parameters

  • x - X coordinate in the noise space
  • y - Y coordinate in the noise space
  • z - Z coordinate in the noise space
  • repeat - Optional. The interval at which the noise pattern repeats. Default is -1 (no repetition).

Returns

A float value between 0 and 1 representing the noise at the given coordinates.

Example

iex> Perlin.noise(3.14, 42.0, 7.0)
0.5684599793920001

iex> Perlin.noise(3.14, 42.0, 7.0, 5)
0.44100014719999997
Link to this function

octave(x, y, z, octaves, persistence)

View Source
@spec octave(float(), float(), float(), integer(), float()) :: float()

Generates Perlin noise with multiple octaves.

Parameters

  • x - X coordinate in the noise space
  • y - Y coordinate in the noise space
  • z - Z coordinate in the noise space
  • octaves - Number of octaves to sum
  • persistence - Amplitude multiplier for each octave

Returns

A float value between 0 and 1 representing the noise at the given coordinates.

Example

iex> Perlin.octave(3.14, 42.0, 7.0, 4, 0.5)
0.5530014285141335