tcod.noise¶
The Noise.sample_mgrid
and Noise.sample_ogrid
methods are
multithreaded operations when the Python runtime supports OpenMP.
Even when single threaded these methods will perform much better than
multiple calls to Noise.get_point
.
Example:
import numpy as np
import tcod
import tcod.noise
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 multidimensional meshgrid.
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.01.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

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:

sample_mgrid
(mgrid: numpy.array) → numpy.array[source]¶ Sample a meshgrid array and return the result.
The
sample_ogrid
method performs better as there is a lot of overhead when working with large meshgrids.Parameters: mgrid (numpy.ndarray) – A meshgrid 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]
. Thedtype
is numpy.float32.Return type: numpy.ndarray

sample_ogrid
(ogrid: numpy.array) → numpy.array[source]¶ Sample an open meshgrid array and return the result.
 Args
 ogrid (Sequence[Sequence[float]]): An open meshgrid.
Returns: An array of sampled points. Theshape
is based on the lengths of the open meshgrid arrays. Thedtype
is numpy.float32.Return type: numpy.ndarray