< index < 15. Heightmap toolkit < 15.2 Basic operations | ===================================== 15.3 Modifying the heightmap ===================================== | > 15.4 Reading data from the heightmap

Those are advanced operations involving several or all map cells.
15.3.1 Add hills
15.3.2 Dig hills
15.3.3 Simulate rain erosion
15.3.4 Do a generic transformation
15.3.5 Add a Voronoi diagram
15.3.6 Add a fbm
15.3.7 Scale with a fbm
15.3.8 Dig along a Bezier curve

#### 15.3.1 Add hills

This function adds a hill (a half spheroid) at given position.

    C++ : void TCODHeightmap::addHill(float x, float y, float radius, float height)
    C   : void TCOD_heightmap_add_hill(TCOD_heightmap_t *hm, float x, float y, float radius, float height)
    Py  : heightmap_add_hill(hm, x, y, radius, height)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
x,y | Coordinates of the center of the hill. 0 <= x < map width 0 <= y < map height
radius | The hill radius.
height | The hill height. If height == radius or -radius, the hill is a half-sphere.

#### 15.3.2 Dig hills

This function takes the highest value (if height > 0) or the lowest (if height < 0) between the map and the hill.
It's main goal is to carve things in maps (like rivers) by digging hills along a curve.

    C++ : void TCODHeightmap::digHill(float hx, float hy, float hradius, float height)
    C   : void TCOD_heightmap_dig_hill(TCOD_heightmap_t *hm, float x, float y, float radius, float height)
    Py  : heightmap_dig_hill(hm, x, y, radius, height)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
x,y | Coordinates of the center of the hill. 0 <= x < map width 0 <= y < map height
radius | The hill radius.
height | The hill height. Can be < 0 or > 0

#### 15.3.3 Simulate rain erosion

This function simulates the effect of rain drops on the terrain, resulting in erosion patterns.

    C++ : void TCODHeightmap::rainErosion(int nbDrops,float erosionCoef,float sedimentationCoef,TCODRandom *rnd)
    C   : void TCOD_heightmap_rain_erosion(TCOD_heightmap_t *hm, int nbDrops,float erosionCoef,float sedimentationCoef,TCOD_random_t rnd)
    Py  : heightmap_rain_erosion(hm, nbDrops,erosionCoef,sedimentationCoef,rnd=0)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
nbDrops | Number of rain drops to simulate. Should be at least width * height.
erosionCoef | Amount of ground eroded on the drop's path.
sedimentationCoef | Amount of ground deposited when the drops stops to flow
rnd | RNG to use, NULL for default generator.

#### 15.3.4 Do a generic transformation

This function allows you to apply a generic transformation on the map, so that each resulting cell value is the weighted sum of several neighbour cells. This can be used to smooth/sharpen the map.

    C++ : void TCODHeightmap::kernelTransform(int kernelSize, int *dx, int *dy, float *weight, float minLevel,float maxLevel)
    C   : void TCOD_heightmap_kernel_transform(TCOD_heightmap_t *hm, int kernelsize, int *dx, int *dy, float *weight, float minLevel,float maxLevel)
    Py  : heightmap_kernel_transform(hm, kernelsize, dx, dy, weight, minLevel,maxLevel)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
kernelSize | Number of neighbour cells involved.
dx,dy | Array of kernelSize cells coordinates. The coordinates are relative to the current cell (0,0) is current cell, (-1,0) is west cell, (0,-1) is north cell, (1,0) is east cell, (0,1) is south cell, ...
weight | Array of kernelSize cells weight. The value of each neighbour cell is scaled by its corresponding weight
minLevel | The transformation is only applied to cells which value is >= minLevel.
maxLevel | The transformation is only applied to cells which value is <= maxLevel.

#### 15.3.5 Add a Voronoi diagram

This function adds values from a Voronoi diagram to the map.

    C++ : void TCODHeightmap::addVoronoi(int nbPoints, int nbCoef, float *coef,TCODRandom *rnd)
    C   : void TCOD_heightmap_add_voronoi(TCOD_heightmap_t *hm, int nbPoints, int nbCoef, float *coef,TCOD_random_t rnd)
    Py  : heightmap_add_voronoi(hm, nbPoints, nbCoef, coef,rnd=0)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
nbPoints | Number of Voronoi sites.
nbCoef | The diagram value is calculated from the nbCoef closest sites.
coef | The distance to each site is scaled by the corresponding coef. Closest site : coef[0], second closest site : coef[1], ...
rnd | RNG to use, NULL for default generator.

#### 15.3.6 Add a fbm

This function adds values from a simplex fbm function to the map.

    C++ : void TCODHeightmap::addFbm(TCODNoise *noise,float mulx, float muly, float addx, float addy, float octaves, float delta, float scale)
    C   : void TCOD_heightmap_add_fbm(TCOD_heightmap_t *hm, TCOD_noise_t noise,float mulx, float muly, float addx, float addy, float octaves, float delta, float scale)
    Py  : heightmap_add_fbm(hm, noise,mulx, muly, addx, addy, octaves, delta, scale)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
noise | The 2D noise to use.
mulx, muly / addx, addy | The noise coordinate for map cell (x,y) are (x + addx)*mulx / width , (y + addy)*muly / height. Those values allow you to scale and translate the noise function over the heightmap.
octaves | Number of octaves in the fbm sum.
delta / scale | The value added to the heightmap is delta + noise * scale. noise is between -1.0 and 1.0

#### 15.3.7 Scale with a fbm

This function works exactly as the previous one, but it multiplies the resulting value instead of adding it to the heightmap.

    C++ : void TCODHeightmap::scaleFbm(TCODNoise *noise,float mulx, float muly, float addx, float addy, float octaves, float delta, float scale)
    C   : void TCOD_heightmap_scale_fbm(TCOD_heightmap_t *hm, TCOD_noise_t noise,float mulx, float muly, float addx, float addy, float octaves, float delta, float scale)
    Py  : heightmap_scale_fbm(hm, noise,mulx, muly, addx, addy, octaves, delta, scale)

#### 15.3.8 Dig along a Bezier curve

This function carve a path along a cubic Bezier curve using the digHill function.
Could be used for roads/rivers/...
Both radius and depth can vary linearly along the path.

    C++ : void TCODHeightmap::digBezier(int px[4], int py[4], float startRadius, float startDepth, float endRadius, float endDepth)
    C   : void TCOD_heightmap_dig_bezier(TCOD_heightmap_t *hm, int px[4], int py[4], float startRadius, float startDepth, float endRadius, float endDepth)
    Py  : heightmap_dig_bezier(hm, px, py,  startRadius,  startDepth, endRadius, endDepth)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
px,py | The coordinates of the 4 Bezier control points.
startRadius | The path radius in map cells at point P0. Might be < 1.0
startDepth | The path depth at point P0.
endRadius | The path radius in map cells at point P3. Might be < 1.0
endDepth | The path depth at point P3.