Colors

libtcod uses 32-bit color, therefore your OS desktop must also use 32-bit color. A color is defined by its red, green and blue component between 0 and 255.

You can use the following predefined colors (hover over a color to see its full name and R,G,B values):

INSERT COLOUR TABLE IN A PAINLESS MANNER

Create your own colors

You can create your own colours using a set of constructors, both for RGB and HSV values.

/* RGB */
TCOD_color_t my_color= { 24, 64, 255 };
TCOD_color_t my_other_color = TCOD_color_RGB(24, 64, 255);
/* HSV */
TCOD_color_t my_yet_another_color = TCOD_color_HSV(321.0f, 0.7f, 1.0f);
// RGB
TCODColor myColor(24, 64, 255);
// HSV
TCODColor myOtherColor(321.0f, 0.7f, 1.0f);
my_color = libtcod.Color(24, 64, 255)

Compare two colors

bool TCOD_color_equals(TCOD_color_t c1, TCOD_color_t c2)

Return a true value if c1 and c2 are equal.

Add and subtract Colors

TCOD_color_t TCOD_color_add(TCOD_color_t c1, TCOD_color_t c2)

Add two colors together and return the result.

Return

A new TCOD_color_t struct with the result.

Parameters
  • c1: The first color.

  • c2: The second color.

TCOD_color_t TCOD_color_subtract(TCOD_color_t c1, TCOD_color_t c2)

Subtract c2 from c1 and return the result.

Return

A new TCOD_color_t struct with the result.

Parameters
  • c1: The first color.

  • c2: The second color.

Multiply Colors together

TCOD_color_t TCOD_color_multiply(TCOD_color_t c1, TCOD_color_t c2)

Multiply two colors together and return the result.

Return

A new TCOD_color_t struct with the result.

Parameters
  • c1: The first color.

  • c2: The second color.

TCOD_color_t TCOD_color_multiply_scalar(TCOD_color_t c1, float value)

Multiply a color with a scalar value and return the result.

Return

A new TCOD_color_t struct with the result.

Parameters
  • c1: The color to multiply.

  • value: The scalar float.

Interpolate between two colors

TCOD_color_t TCOD_color_lerp(TCOD_color_t c1, TCOD_color_t c2, float coef)

Interpolate two colors together and return the result.

Return

A new TCOD_color_t struct with the result.

Parameters
  • c1: The first color (where coef if 0)

  • c2: The second color (where coef if 1)

  • coef: The coefficient.

Define a color by its hue, saturation and value

After this function is called, the r,g,b fields of the color are calculated according to the h,s,v parameters.

void TCOD_color_set_HSV(TCOD_color_t *color, float hue, float saturation, float value)

Sets a colors values from HSV values.

Parameters
  • color: The color to be changed.

  • hue: The colors hue (in degrees.)

  • saturation: The colors saturation (from 0 to 1)

  • value: The colors value (from 0 to 1)

These functions set only a single component in the HSV color space.

void TCOD_color_set_hue(TCOD_color_t *color, float hue)

Change a colors hue.

Parameters
  • color: Pointer to a color struct.

  • hue: The hue in degrees.

void TCOD_color_set_saturation(TCOD_color_t *color, float saturation)

Change a colors saturation.

Parameters
  • color: Pointer to a color struct.

  • saturation: The desired saturation value.

void TCOD_color_set_value(TCOD_color_t *color, float value)

Change a colors value.

Parameters
  • color: Pointer to a color struct.

  • value: The desired value.

Get a color hue, saturation and value components

void TCOD_color_get_HSV(TCOD_color_t color, float *hue, float *saturation, float *value)

Get a set of HSV values from a color.

The hue, saturation, and value parameters can not be NULL pointers,

Parameters
  • color: The color

  • hue: Pointer to a float, filled with the hue. (degrees)

  • saturation: Pointer to a float, filled with the saturation. (0 to 1)

  • value: Pointer to a float, filled with the value. (0 to 1)

Should you need to extract only one of the HSV components, these functions are what you should call. Note that if you need all three values, it’s way less burdensome for the CPU to call TCODColor::getHSV().

float TCOD_color_get_hue(TCOD_color_t color)

Return a colors hue.

Return

The colors hue. (degrees)

Parameters
  • color: A color struct.

float TCOD_color_get_saturation(TCOD_color_t color)

Return a colors saturation.

Return

The colors saturation. (0 to 1)

Parameters
  • color: A color struct.

float TCOD_color_get_value(TCOD_color_t color)

Get a colors value.

Return

The colors value. (0 to 1)

Parameters
  • color: A color struct.

Shift a color’s hue up or down

The hue shift value is the number of grades the color’s hue will be shifted. The value can be negative for shift left, or positive for shift right. Resulting values H < 0 and H >= 360 are handled automatically.

void TCOD_color_shift_hue(TCOD_color_t *color, float hshift)

Shift a colors hue by an amount.

Parameters
  • color: Pointer to a color struct.

  • hue_shift: The distance to shift the hue, in degrees.

Scale a color’s saturation and value

void TCOD_color_scale_HSV(TCOD_color_t *color, float saturation_coef, float value_coef)

Scale a colors saturation and value.

Parameters
  • color: Pointer to a color struct.

  • saturation_coef: Multiplier for this colors saturation.

  • value_coef: Multiplier for this colors value.

Generate a smooth color map

You can define a color map from an array of color keys. Colors will be interpolated between the keys. 0 -> black 4 -> red 8 -> white Result:

INSERT TABLE.

void TCOD_color_gen_map(TCOD_color_t *map, int nb_key, const TCOD_color_t *key_color, const int *key_index)

Generate an interpolated gradient of colors.

TCOD_color_t[256] gradient;
TCOD_color_t[4] key_color = {TCOD_black, TCOD_dark_amber,
                             TCOD_cyan, TCOD_white};
int[4] key_index = {0, 64, 192, 255};
TCOD_color_gen_map(&gradient, 4, &key_color, &key_index);
Parameters
  • map: Array to fill with the new gradient.

  • nb_key: The array size of the key_color and key_index parameters.

  • key_color: An array of colors to use, in order.

  • key_index: An array mapping key_color items to the map array.

C++

class TCODColor

STANDARD COLORS red 255,0,0 flame 255,63,0 orange 255,127,0 amber 255,191,0 yellow 255,255,0, lime 191,255,0 chartreuse 127,255,0 green 0,255,0 sea 0,255,127 turquoise 0,255,191 cyan 0,255,255 sky 0,191,255 azure 0,127,255 blue 0,0,255 han 63,0,255 violet 127,0,255 purple 191,0,255 fuchsia 255,0,255 magenta 255,0,191 pink 255,0,127 crimson 255,0,63 METALLIC COLORS brass 191,151,96 copper 196,136,124 gold 229,191,0 silver 203,203,203 MISCELLANEOUS COLORS celadon 172,255,175 peach 255,159,127 GREYSCALE & SEPIA grey 127,127,127 sepia 127,101,63 BLACK AND WHITE black 0,0,0 white 255,255,255

color Core Colors The Doryen library uses 32bits colors. Thus, your OS desktop must use 32bits colors. A color is defined by its red, green and blue component between 0 and 255. You can use the following predefined colors (hover over a color to see its full name and R,G,B values): TCODColor::desaturatedRed TCODColor::lightestRed TCODColor::lighterRed TCODColor::lightRed TCODColor::red TCODColor::darkRed TCODColor::darkerRed TCODColor::darkestRed TCOD_desaturated_red TCOD_lightest_red TCOD_lighter_red TCOD_light_red TCOD_red TCOD_dark_red TCOD_darker_red TCOD_darkest_red libtcod.desaturated_red libtcod.lightest_red libtcod.lighter_red libtcod.light_red libtcod.red libtcod.dark_red libtcod.darker_red libtcod.darkest_red #Ex TCODColor::desaturatedRed TCODColor::lightestRed TCODColor::lighterRed TCODColor::lightRed TCODColor::red TCODColor::darkRed TCODColor::darkerRed TCODColor::darkestRed tcod.color.desaturatedRed tcod.color.lightestRed tcod.color.lighterRed tcod.color.lightRed tcod.color.red tcod.color.darkRed tcod.color.darkerRed tcod.color.darkestRed

Public Functions

TCODColor(uint8_t r_, uint8_t g_, uint8_t b_)

color Create your own colors You can create your own colours using a set of constructors, both for RGB and HSV values.

TCODColor myColor(24,64,255); //RGB TCODColor myOtherColor(321.0f,0.7f,1.0f); //HSV TCOD_color_t my_color={24,64,255}; /* RGB */ TCOD_color_t my_other_color = TCOD_color_RGB(24,64,255); /* RGB too */ TCOD_color_t my_yet_another_color = TCOD_color_HSV(321.0f,0.7f,1.0f); /* HSV */ my_color=libtcod.Color(24,64,255) #Ex TCODColor myColor = new TCODColor(24,64,255); //RGB TCODColor myColor = new TCODColor(321.0f,0.7f,1.0f); //HSV myColor = tcod.Color(24,24,255)

bool operator==(const TCODColor &c) const

color Compare two colors if (myColor == TCODColor::yellow) { …

} if (myColor != TCODColor::white) { … } if (TCOD_color_equals(my_color,TCOD_yellow)) { … } if (!TCOD_color_equals(my_color,TCOD_white)) { … } if my_color == libtcod.yellow : … if my_color != litbcod.white : … #Ex if (myColor.Equal(TCODColor.yellow)) { … } if (myColor.NotEqual(TCODColor.white)) { … } if myColor == tcod.color.yellow then … end

TCODColor operator*(const TCODColor &rhs) const

color Multiply two colors c1 = c2 * c3 => c1.r = c2.r * c3.r / 255 c1.g = c2.g * c3.g / 255 c1.b = c2.b * c3.b / 255 darkishRed = darkGrey * red

TCODColor myDarkishRed = TCODColor::darkGrey * TCODColor::lightRed; TCOD_color_t my_darkish_red = TCOD_color_multiply(TCOD_dark_grey, TCOD_light_red); my_darkish_red = libtcod.dark_grey * libtcod.light_red #Ex TCODColor myDarkishRed = TCODColor.darkGrey.Multiply(TCODColor.lightRed); myDarkishRed = tcod.color.darkGrey * tcod.color.lightRed

TCODColor operator*(float value) const

color Multiply a color by a float c1 = c2 * v => c1.r = CLAMP(0, 255, c2.r * v) c1.g = CLAMP(0, 255, c2.g * v) c1.b = CLAMP(0, 255, c2.b * v) darkishRed = red * 0.5

</tbody>

TCODColor myDarkishRed = TCODColor::lightRed * 0.5f; TCOD_color_t my_darkish_red = TCOD_color_multiply_scalar(TCOD_light_red, 0.5f); myDarkishRed = litbcod.light_red * 0.5 #Ex TCODColor myDarkishRed = TCODColor.lightRed.Multiply(0.5f); myDarkishRed = tcod.color.lightRed * 0.5

TCODColor operator+(const TCODColor &rhs) const

color Adding two colors c1 = c1 + c2 => c1.r = MIN(255, c1.r + c2.r) c1.g = MIN(255, c1.g + c2.g) c1.b = MIN(255, c1.b + c2.b) lightishRed = red + darkGrey

TCODColor myLightishRed = TCODColor::red + TCODColor::darkGrey TCOD_color_t my_lightish_red = TCOD_color_add(TCOD_red, TCOD_dark_grey); myLightishRed = libtcod.red + libtcod.dark_grey #Ex TCODColor myLightishRed = TCODColor.red.Plus(TCODColor.darkGrey) myLightishRed = tcod.color.red + tcod.color.darkGrey

TCODColor operator-(const TCODColor &rhs) const

color Subtract two colors c1 = c1 - c2 => c1.r = MAX(0, c1.r - c2.r) c1.g = MAX(0, c1.g - c2.g) c1.b = MAX(0, c1.b - c2.b) redish = red - darkGrey

TCODColor myRedish = TCODColor::red - TCODColor::darkGrey TCOD_color_t my_redish = TCOD_color_subtract(TCOD_red, TCOD_dark_grey); myRedish = libtcod.red - libtcod.dark_grey #Ex TCODColor myRedish = TCODColor.red.Minus(TCODColor.darkGrey) myRedish = tcod.color.red - tcod.color.darkGrey

void setHSV(float h, float s, float v)

color Define a color by its hue, saturation and value After this function is called, the r,g,b fields of the color are calculated according to the h,s,v parameters.

void TCODColor::setHSV(float h, float s, float v) void TCOD_color_set_HSV(TCOD_color_t *c,float h, float s, float v) color_set_hsv(c,h,s,v) # void TCODColor::setHSV(float h, float s, float v) Color:setHSV( h, s ,v ) c In the C and Python versions, the color to modify h,s,v Color components in the HSV space 0.0 <= h < 360.0 0.0 <= s <= 1.0 0.0 <= v <= 1.0

void setHue(float h)

color Define a color’s hue, saturation or lightness These functions set only a single component in the HSV color space.

void TCODColor::setHue (float h) void TCODColor::setSaturation (float s) void TCODColor::setValue (float v) void TCOD_color_set_hue (TCOD_color_t *c, float h) void TCOD_color_set_saturation (TCOD_color_t *c, float s) void TCOD_color_set_value (TCOD_color_t *c, float v) Color:setHue(h) Color:setSaturation(s) Color:setValue(v) h,s,v Color components in the HSV space c In the C and Python versions, the color to modify

void getHSV(float *h, float *s, float *v) const

color Get a color hue, saturation and value components void TCODColor::getHSV(float *h, float *s, float *v) const void TCOD_color_get_HSV(TCOD_color_t c,float * h, float * s, float * v) color_get_HSV(c) # returns [h,s,v] # void TCODColor::getHSV(out float h, out float s, out float v) Color:getHSV() returns h,s,v c In the C and Python versions, the TCOD_color_t from which to read.

h,s,v Color components in the HSV space 0.0 <= h < 360.0 0.0 <= s <= 1.0 0.0 <= v <= 1.0

float getHue()

color Get a color’s hue, saturation or value Should you need to extract only one of the HSV components, these functions are what you should call.

Note that if you need all three values, it’s way less burdensome for the CPU to call TCODColor::getHSV(). float TCODColor::getHue () float TCODColor::getSaturation () float TCODColor::getValue () float TCOD_color_get_hue (TCOD_color_t c) float TCOD_color_get_saturation (TCOD_color_t c) float TCOD_color_get_value (TCOD_color_t c) Color:getHue() Color:getSaturation() Color:getValue() # float TCODColor::getHue() float TCODColor::getSaturation() float TCODColor::getValue() c the TCOD_color_t from which to read

void shiftHue(float hshift)

color Shift a color’s hue up or down The hue shift value is the number of grades the color’s hue will be shifted.

The value can be negative for shift left, or positive for shift right. Resulting values H < 0 and H >= 360 are handled automatically. void TCODColor::shiftHue (float hshift) void TCOD_color_shift_hue (TCOD_color_t *c, float hshift) # TCODColor::shiftHue(float hshift) Color:shiftHue(hshift) c The color to modify hshift The hue shift value

void scaleHSV(float sscale, float vscale)

color Scale a color’s saturation and value void TCODColor::scaleHSV (float sscale, float vscale) void TCOD_color_scale_HSV (TCOD_color_t *c, float scoef, float vcoef) color_scale_HSV(c, scoef, vcoef) # TCODColor::scaleHSV (float sscale, float vscale) Color:scaleHSV(sscale,vscale) c The color to modify sscale saturation multiplier (1.0f for no change) vscale value multiplier (1.0f for no change)

Public Static Functions

static TCODColor lerp(const TCODColor &c1, const TCODColor &c2, float coef)

color Interpolate between two colors c1 = lerp (c2, c3, coef) => c1.r = c2.r + (c3.r - c2.r ) * coef c1.g = c2.g + (c3.g - c2.g ) * coef c1.b = c2.b + (c3.b - c2.b ) * coef coef should be between 0.0 and 1.0 but you can as well use other values

TCODColor myColor = TCODColor::lerp ( TCODColor::darkGrey, TCODColor::lightRed,coef ); TCOD_color_t my_color = TCOD_color_lerp ( TCOD_dark_grey, TCOD_light_red,coef); my_color = libtcod.color_lerp ( libtcod.dark_grey, litbcod.light_red,coef) #Ex TCODColor myColor = TCODColor.Interpolate( TCODColor.darkGrey, TCODColor.lightRed, coef ); myColor = tcod.color.Interpolate( tcod.color.darkGrey, tcod.color.lightRed, coef )

void genMap(TCODColor *map, int nbKey, TCODColor const *keyColor, int const *keyIndex)

color Generate a smooth color map You can define a color map from an array of color keys.

Colors will be interpolated between the keys. 0 -> black 4 -> red 8 -> white Result :

black

red

white </tbody>

static void genMap(TCODColor *map, int nbKey, TCODColor const *keyColor, int const *keyIndex) void TCOD_gen_map(TCOD_color_t *map, int nb_key, TCOD_color_t const *key_color, int const *key_index) color_gen_map(keyColor,keyIndex) # returns an array of colors map An array of colors to be filled by the function. nbKey Number of color keys keyColor Array of nbKey colors containing the color of each key keyIndex Array of nbKey integers containing the index of each key. If you want to fill the map array, keyIndex[0] must be 0 and keyIndex[nbKey-1] is the number of elements in map minus 1 but you can also use the function to fill only a part of the map array. int idx[] = { 0, 4, 8 }; // indexes of the keys TCODColor col[] = { TCODColor( 0,0,0 ), TCODColor(255,0,0), TCODColor(255,255,255) }; // colors : black, red, white TCODColor map[9]; TCODColor::genMap(map,3,col,idx); int idx[] = { 0, 4, 8 }; // indexes of the keys TCOD_color_t col[] = { { 0,0,0 }, {255,0,0}, {255,255,255} }; // colors : black, red, white TCOD_color_t map[9]; TCOD_color_gen_map(map,3,col,idx); idx = [ 0, 4, 8 ] # indexes of the keys col = [ libtcod.Color( 0,0,0 ), libtcod.Color( 255,0,0 ), libtcod.Color(255,255,255) ] # colors : black, red, white map=libtcod.color_gen_map(col,idx)