tcod.noise - Noise Map Generators

Noise map generators are provided by this module.

The Noise.sample_mgrid and Noise.sample_ogrid methods perform much better than multiple calls to Noise.get_point.

Example:

import numpy as np
import tcod

noise = tcod.noise.Noise(
    dimensions=2,
    algorithm=tcod.NOISE_SIMPLEX,
    implementation=tcod.noise.TURBULENCE,
    hurst=0.5,
    lacunarity=2.0,
    octaves=4,
    seed=None,
    )

# Create a 5x5 open multi-dimensional mesh-grid.
ogrid = [np.arange(5, dtype=np.float32),
         np.arange(5, dtype=np.float32)]
print(ogrid)

# Scale the grid.
ogrid[0] *= 0.25
ogrid[1] *= 0.25

# Return the sampled noise from this grid of points.
samples = noise.sample_ogrid(ogrid)
print(samples)
class tcod.noise.Noise(dimensions: int, algorithm: int = 2, implementation: int = 0, hurst: float = 0.5, lacunarity: float = 2.0, octaves: float = 4, seed: Optional[tcod.random.Random] = None)[source]

The hurst exponent describes the raggedness of the resultant noise, with a higher value leading to a smoother noise. Not used with tcod.noise.SIMPLE.

lacunarity is a multiplier that determines how fast the noise frequency increases for each successive octave. Not used with tcod.noise.SIMPLE.

Parameters:
  • dimensions (int) – Must be from 1 to 4.
  • algorithm (int) – Defaults to NOISE_SIMPLEX
  • implementation (int) – Defaults to tcod.noise.SIMPLE
  • hurst (float) – The hurst exponent. Should be in the 0.0-1.0 range.
  • lacunarity (float) – The noise lacunarity.
  • octaves (float) – The level of detail on fBm and turbulence implementations.
  • seed (Optional[Random]) – A Random instance, or None.
noise_c

A cffi pointer to a TCOD_noise_t object.

Type:CData
__getitem__(indexes: Any) → numpy.ndarray[source]

Sample a noise map through NumPy indexing.

This follows NumPy’s advanced indexing rules, but allows for floating point values.

New in version 11.16.

get_point(x: float = 0, y: float = 0, z: float = 0, w: float = 0) → float[source]

Return the noise value at the (x, y, z, w) point.

Parameters:
  • x (float) – The position on the 1st axis.
  • y (float) – The position on the 2nd axis.
  • z (float) – The position on the 3rd axis.
  • w (float) – The position on the 4th axis.
sample_mgrid(mgrid: numpy.ndarray) → numpy.ndarray[source]

Sample a mesh-grid array and return the result.

The sample_ogrid method performs better as there is a lot of overhead when working with large mesh-grids.

Parameters:mgrid (numpy.ndarray) – A mesh-grid array of points to sample. A contiguous array of type numpy.float32 is preferred.
Returns:An array of sampled points.
This array has the shape: mgrid.shape[:-1]. The dtype is numpy.float32.
Return type:numpy.ndarray
sample_ogrid(ogrid: numpy.ndarray) → numpy.ndarray[source]

Sample an open mesh-grid array and return the result.

Args
ogrid (Sequence[Sequence[float]]): An open mesh-grid.
Returns:An array of sampled points.
The shape is based on the lengths of the open mesh-grid arrays. The dtype is numpy.float32.
Return type:numpy.ndarray