< index < 15. Heightmap toolkit < 15.1 Creating a heightmap | ===================================== 15.2 Basic operations ===================================== | > 15.3 Modifying the heightmap

Those are simple operations applied either on a single map cell or on every map cell.
15.2.1 Setting a cell value
15.2.2 Adding a float value to all cells
15.2.3 Multiplying all values by a float
15.2.4 Resetting all values to 0.0
15.2.5 Clamping all values
15.2.6 Copying values from another heightmap
15.2.7 Normalizing values
15.2.8 Doing a lerp operation between two heightmaps
15.2.9 Adding two heightmaps
15.2.10 Multiplying two heightmaps

#### 15.2.1 Setting a cell value

Once the heightmap has been created, you can do some basic operations on the values inside it.
You can set a single value :

    C++ : void TCODHeightmap::setValue(int x, int y, float v)
    C   : void TCOD_heightmap_set_value(TCOD_heightmap_t *hm, int x, int y, float value)
    Py  : heightmap_set_value(hm, x, y, value)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
x,y | Coordinates of the cells to modify inside the map. 0 <= x < map width 0 <= y < map height
value | The new value of the map cell.

#### 15.2.2 Adding a float value to all cells

    C++ : void TCODHeightmap::add(float value)
    C   : void TCOD_heightmap_add(TCOD_heightmap_t *hm, float value)
    Py  : heightmap_add(hm, value)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
value | Value to add to every cell.

#### 15.2.3 Multiplying all values by a float

    C++ : void TCODHeightmap::scale(float value)
    C   : void TCOD_heightmap_scale(TCOD_heightmap_t *hm, float value)
    Py  : heightmap_scale(hm, value)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
value | Every cell's value is multiplied by this value.

#### 15.2.4 Resetting all values to 0.0

    C++ : void TCODHeightmap::clear()
    C   : void TCOD_heightmap_clear(TCOD_heightmap_t *hm)
    Py  : heightmap_clear(hm)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.

#### 15.2.5 Clamping all values

    C++ : void TCODHeightmap::clamp(float min, float max)
    C   : void TCOD_heightmap_clamp(TCOD_heightmap_t *hm, float min, float max)
    Py  : heightmap_clamp(hm, mi, ma)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
min,max | Every cell value is clamped between min and max. min < max

#### 15.2.6 Copying values from another heightmap

    C++ : void TCODHeightmap::copy(const TCODHeightMap *source)
    C   : void TCOD_heightmap_copy(const TCOD_heightmap_t *source,TCOD_heightmap_t *dest)
    Py  : heightmap_copy(source,dest)

Parameter | Description
--- | ---
source | Each cell value from the source heightmap is copied in the destination (this for C++) heightmap. The source and destination heightmap must have the same width and height.
hm | In the C version, the address of the destination heightmap.

#### 15.2.7 Normalizing values

    C++ : void TCODHeightmap::normalize(float min=0.0f, float max=1.0f)
    C   : void TCOD_heightmap_normalize(TCOD_heightmap_t *hm, float min, float max)
    Py  : heightmap_normalize(hm, mi=0.0, ma=1.0)

Parameter | Description
--- | ---
hm | In the C version, the address of the heightmap struct returned by the creation function.
min,max | The whole heightmap is translated and scaled so that the lowest cell value becomes min and the highest cell value becomes max min < max

#### 15.2.8 Doing a lerp operation between two heightmaps

    C++ : void TCODHeightmap::lerp(const TCODHeightMap *a, const TCODHeightMap *b,float coef)
    C   : void TCOD_heightmap_lerp_hm(const TCOD_heightmap_t *a, const TCOD_heightmap_t *b, TCOD_heightmap_t *res, float coef)
    Py  : heightmap_lerp_hm(a, b, res, coef)

Parameter | Description
--- | ---
a | First heightmap in the lerp operation.
b | Second heightmap in the lerp operation.
coef | lerp coefficient. For each cell in the destination map (this for C++), value = a.value + (b.value - a.value) * coef
res | In the C version, the address of the destination heightmap.

#### 15.2.9 Adding two heightmaps

    C++ : void TCODHeightmap::add(const TCODHeightMap *a, const TCODHeightMap *b)
    C   : void TCOD_heightmap_add_hm(const TCOD_heightmap_t *a, const TCOD_heightmap_t *b, TCOD_heightmap_t *res)
    Py  : heightmap_add_hm(a, b, res)

Parameter | Description
--- | ---
a | First heightmap.
b | Second heightmap. For each cell in the destination map (this for C++), value = a.value + b.value
res | In the C version, the address of the destination heightmap.

#### 15.2.10 Multiplying two heightmaps

    C++ : void TCODHeightmap::multiply(const TCODHeightMap *a, const TCODHeightMap *b)
    C   : void TCOD_heightmap_multiply_hm(const TCOD_heightmap_t *a, const TCOD_heightmap_t *b, TCOD_heightmap_t *res)
    Py  : heightmap_multiply_hm(a, b, res)

Parameter | Description
--- | ---
a | First heightmap.
b | Second heightmap. For each cell in the destination map (this for C++), value = a.value * b.value
res | In the C version, the address of the destination heightmap.