Class TCODNoise

Class Documentation

class TCODNoise

Usage example: 1D noise : the variation of a torch intensity 2D fbm : heightfield generation or clouds 3D fbm : animated smoke If you don’t know what is Perlin noise and derived functions, or what is the influence of the different fractal parameters, check the Perlin noise sample included with the library.

This toolkit provides several functions to generate Perlin noise and other derived noises. It can handle noise functions from 1 to 4 dimensions.

Simplex noise, fbm, turbulence

doxyxml/simplex.png

doxyxml/fbm_simplex.png

doxyxml/turbulence_simplex.png

Perlin noise, fbm, turbulence

doxyxml/perlin.png

doxyxml/fbm_perlin.png

doxyxml/turbulence_perlin.png

Wavelet noise, fbm, turbulence

doxyxml/wavelet.png

doxyxml/fbm_wavelet.png

doxyxml/turbulence_wavelet.png

Noise functions relative times

For example, in 4D, Perlin noise is 17 times slower than simplex noise.

1D

2D

3D

4D

simplex

1

1

1

1

Perlin

1.3

4

5

17

wavelet

53

32

14

X

Public Functions

TCODNoise(int dimensions, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)

@noop noise_init
@noop noise
@noop Creating a noise generator
@brief Those functions initialize a noise generator from a number of dimensions (from 1 to 4), some fractal parameters and a random number generator.
  The C++ version provides several constructors. When the hurst and lacunarity parameters are omitted, default values (TCOD_NOISE_DEFAULT_HURST = 0.5f and TCOD_NOISE_DEFAULT_LACUNARITY = 2.0f) are used.
@noop
  TCODNoise::TCODNoise(int dimensions, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
  TCODNoise::TCODNoise(int dimensions, TCODRandom *random, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
  TCODNoise::TCODNoise(int dimensions, float hurst, float lacunarity, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
  TCODNoise::TCODNoise(int dimensions, float hurst, float lacunarity, TCODRandom *random, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
@noop TCOD_noise_t TCOD_noise_new(int dimensions, float hurst, float lacunarity, TCOD_random_t random)
@noop noise_new(dimensions, hurst=TCOD_NOISE_DEFAULT_HURST, lacunarity=TCOD_NOISE_DEFAULT_LACUNARITY, random=0)
@noop#
  TCODNoise::TCODNoise(int dimensions)
  TCODNoise::TCODNoise(int dimensions, TCODRandom random)
  TCODNoise::TCODNoise(int dimensions, float hurst, float lacunarity)
  TCODNoise::TCODNoise(int dimensions, float hurst, float lacunarity, TCODRandom random)
@param dimensions From 1 to 4.
@param hurst  For fractional brownian motion and turbulence, the fractal Hurst exponent. You can use the default value TCOD_NOISE_DEFAULT_HURST = 0.5f.
@param lacunarity For fractional brownian motion and turbulence, the fractal lacunarity. You can use the default value TCOD_NOISE_DEFAULT_LACUNARITY = 2.0f.
@param random A random number generator obtained with the Mersenne twister toolkit or NULL to use the default random number generator.
@noop
1 dimension generator TCODNoise * noise1d = new TCODNoise(1); 2D noise with a predefined random number generator TCODRandom *myRandom = new TCODRandom(); TCODNoise *noise2d = new TCODNoise(2,myRandom); a 3D noise generator with a specific fractal parameters TCODNoise *noise3d = new TCODNoise(3,0.7f,1.4f);

1 dimension generator TCOD_noise_t noise1d = TCOD_noise_new(1,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY,NULL); 2D noise with a predefined random number generator TCOD_random_t my_random = TCOD_random_new(); TCOD_noise_t noise2d = TCOD_noise_new(2,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY,my_random); a 3D noise generator with a specific fractal parameters TCOD_noise_t noise3d = TCOD_noise_new(3,0.7f, 1.4f,NULL);

1 dimension generator

noise1d = libtcod.noise_new(1) 2D noise with a predefined random number generator

my_random = libtcod.random_new(); noise2d = libtcod.noise_new(2,libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY,my_random) a 3D noise generator with a specific fractal parameters

noise3d = libtcod.noise_new(3, 0.7, 1.4)

TCODNoise(int dimensions, TCODRandom *random, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
TCODNoise(int dimensions, float hurst, float lacunarity, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
TCODNoise(int dimensions, float hurst, float lacunarity, TCODRandom *random, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
TCODNoise(const TCODNoise&) = delete
TCODNoise &operator=(const TCODNoise&) = delete
inline TCODNoise(TCODNoise &&rhs) noexcept
inline TCODNoise &operator=(TCODNoise &&rhs) noexcept
virtual ~TCODNoise()

@noop noise_init
@brief To release resources used by a generator, use those functions :
@noop TCODNoise::~TCODNoise()
@noop void TCOD_noise_delete(TCOD_noise_t noise)
@noop noise_delete(noise)
@noop# void TCODNoise::Dispose()
@param noise  In the C and Python versions, the generator handler, returned by the initialization function.
@noop
create a generator TCODNoise *noise = new TCODNoise(2); use it … destroy it delete noise;

create a generator TCOD_noise_t noise = TCOD_noise_new(2,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY, NULL); use it … destroy it TCOD_noise_delete(noise);

create a generator

noise = libtcod.noise_new(2,libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY, 0) use it

destroy it

libtcod.noise_delete(noise)

void setType(TCOD_noise_type_t type)

Use this function to define the default algorithm used by the noise functions.

The default algorithm is simplex. It’s much faster than Perlin, especially in 4 dimensions. It has a better contrast too.

TCODNoise * noise1d = new TCODNoise(1); noise1d->setType(TCOD_NOISE_PERLIN);

TCOD_noise_t noise1d = TCOD_noise_new(1,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY,NULL); TCOD_noise_set_type(noise1d,TCOD_NOISE_PERLIN);

noise1d = libtcod.noise_new(1) libtcod.noise_set_type(noise1d,libtcod.NOISE_PERLIN)

Parameters
  • noise – In the C version, the generator handler, returned by the initialization function.

  • type – The algorithm to use, either TCOD_NOISE_SIMPLEX, TCOD_NOISE_PERLIN or TCOD_NOISE_WAVELET.

float get(float *f, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)

  @noop noise_get
@noop noise
@noop Getting flat noise
@brief This function returns the noise function value between -1.0 and 1.0 at given coordinates.
@noop float TCODNoise::get(float *f, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
@noop float TCOD_noise_get(TCOD_noise_t noise, float *f)
float TCOD_noise_get_ex(TCOD_noise_t noise, float *f, TCOD_noise_type_t type)

1d noise TCODNoise * noise1d = new TCODNoise(1); float p=0.5f; get a 1d simplex value float value = noise1d->get(&p); 2d noise TCODNoise * noise2d = new TCODNoise(2); float p[2]={0.5f,0.7f}; get a 2D Perlin value float value = noise2d->get(p, TCOD_NOISE_PERLIN);

1d noise TCOD_noise_t noise1d = TCOD_noise_new(1,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY,NULL); float p=0.5f; get a 1d simplex value float value = TCOD_noise_get(noise1d,&p); 2d noise TCOD_noise_t noise2d = TCOD_noise_new(2,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY,NULL); float p[2]={0.5f,0.7f}; get a 2d perlin value float value = TCOD_noise_get_ex(noise2d,p,TCOD_NOISE_PERLIN);

1d noise

noise1d = libtcod.noise_new(1) get a 1d simplex value

value = libtcod.noise_get(noise1d,[0.5]) 2d noise

noise2d = libtcod.noise_new(2) get a 2d perlin value

value = libtcod.noise_get(noise2d,[0.5,0.7], libtcod.NOISE_PERLIN)

Parameters
  • noise – In the C version, the generator handler, returned by the initialization function.

  • f – An array of coordinates, depending on the generator dimensions (between 1 and 4). The same array of coordinates will always return the same value.

  • type – The algorithm to use. If not defined, use the default one (set with setType or simplex if not set)

float get(const float *f, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
float getFbm(float *f, float octaves, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)

@noop noise_get_fbm
@noop noise
@noop Getting fbm noise
@brief This function returns the fbm function value between -1.0 and 1.0 at given coordinates, using fractal hurst and lacunarity defined when the generator has been created.
@noop float TCODNoise::getFbm(float *f, float octaves, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
@noop float TCOD_noise_get_fbm(TCOD_noise_t noise, float *f, float octaves)
float TCOD_noise_get_fbm(TCOD_noise_t noise, float *f, float octaves, TCOD_noise_type_t type)

1d fbm TCODNoise * noise1d = new TCODNoise(1); float p=0.5f; get a 1d simplex fbm float value = noise1d->getFbm(&p,32.0f); 2d fbm TCODNoise * noise2d = new TCODNoise(2); float p[2]={0.5f,0.7f}; get a 2d perlin fbm float value = noise2d->getFbm(p,32.0f, TCOD_NOISE_PERLIN);

1d fbm TCOD_noise_t noise1d = TCOD_noise_new(1,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY,NULL); float p=0.5f; get a 1d simplex fbm float value = TCOD_noise_get_fbm(noise1d,&p,32.0f); 2d fbm TCOD_noise_t noise2d = TCOD_noise_new(2,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY,NULL); float p[2]={0.5f,0.7f}; get a 2d perlin fbm float value = TCOD_noise_get_fbm_ex(noise2d,p,32.0f,TCOD_NOISE_PERLIN);

1d noise

noise1d = libtcod.noise_new(1) 1d simplex fbm

value = libtcod.noise_get_fbm(noise1d,[0.5],32.0) 2d noise

noise2d = libtcod.noise_new(2) 2d perlin fbm

value = libtcod.noise_get_fbm(noise2d,[0.5,0.7],32.0, libtcod.NOISE_PERLIN)

Parameters
  • noise – In the C version, the generator handler, returned by the initialization function.

  • f – An array of coordinates, depending on the generator dimensions (between 1 and 4). The same array of coordinates will always return the same value.

  • octaves – Number of iterations. Must be < TCOD_NOISE_MAX_OCTAVES = 128

  • type – The algorithm to use. If not defined, use the default one (set with setType or simplex if not set)

float getFbm(const float *f, float octaves, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
float getTurbulence(float *f, float octaves, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)

@noop noise_get_turbulence
@noop noise
@noop Getting turbulence
@brief This function returns the turbulence function value between -1.0 and 1.0 at given coordinates, using fractal hurst and lacunarity defined when the generator has been created.
@noop float TCODNoise::getTurbulence(float *f, float octaves, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)
@noop float TCOD_noise_get_turbulence(TCOD_noise_t noise, float *f, float octaves)
float TCOD_noise_get_turbulence_ex(TCOD_noise_t noise, float *f, float octaves, TCOD_noise_type_t)

1d fbm TCODNoise * noise1d = new TCODNoise(1); float p=0.5f; a 1d simplex turbulence float value = noise1d->getTurbulence(&p,32.0f); 2d fbm TCODNoise * noise2d = new TCODNoise(2); float p[2]={0.5f,0.7f}; a 2d perlin turbulence float value = noise2d->getTurbulence(p,32.0f, TCOD_NOISE_PERLIN);

1d fbm TCOD_noise_t noise1d = TCOD_noise_new(1,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY,NULL); float p=0.5f; a 1d simplex turbulence float value = TCOD_noise_get_turbulence(noise1d,&p,32.0f); 2d fbm TCOD_noise_t noise2d = TCOD_noise_new(2,TCOD_NOISE_DEFAULT_HURST, TCOD_NOISE_DEFAULT_LACUNARITY,NULL); float p[2]={0.5f,0.7f}; a 2d perlin turbulence float value = TCOD_noise_get_turbulence_ex(noise2d,p,32.0f, TCOD_NOISE_PERLIN);

1d noise

noise1d = libtcod.noise_new(1) 1d simplex turbulence

value = libtcod.noise_get_turbulence(noise1d,[0.5],32.0) 2d noise

noise2d = libtcod.noise_new(2) 2d perlin turbulence

value = libtcod.noise_get_turbulence(noise2d,[0.5,0.7],32.0,libtcod.NOISE_PERLIN)

Parameters
  • noise – In the C version, the generator handler, returned by the initialization function.

  • f – An array of coordinates, depending on the generator dimensions (between 1 and 4). The same array of coordinates will always return the same value.

  • octaves – Number of iterations. Must be < TCOD_NOISE_MAX_OCTAVES = 128

float getTurbulence(const float *f, float octaves, TCOD_noise_type_t type = TCOD_NOISE_DEFAULT)

Protected Attributes

TCOD_noise_t data

Friends

friend class TCODHeightMap