next up previous contents index
Next: Windows ( window ) Up: Graphics Previous: Graphics   Contents   Index


Colors ( color )

Definition

The data type color is the type of all colors available for drawing operations in windows (cf. Windows). Each color is defined by a triple of integers (r, g, b) with 0 < = r, g, b < = 255, the so-called rgb-value of the color. The number of available colors is restricted and depends on the underlying hardware. Colors can be created from rgb-values, from names in a color data base (X11), or from the 16 integer constants (enumeration in < LEDA/graphics/x_window.htex2html_wrap_inline> ) black, white, red, green, blue, yellow, violet, orange; cyan, brown, pink, green2, blue2, grey1, grey2, grey3.

#include < LEDA/graphics/color.h >

Creation

color col creates a color with rgb-value (0, 0, 0) (i.e. black).

color col(int r, int g, int b) creates a color with rgb-value (r, g, b).

color col(const char* name) creates a color and initializes it with the rgb-string name.

color col(int val) creates a color and initializes it with a color integer value. In particular one of the 16 predefined color values constants can be used: black, white, red, green, blue, yellow, violet, orange, cyan, brown, pink, green2, blue2, grey1, grey2, or grey3.

Operations

void col.set_rgb(int r, int g, int b)
    sets the red, blue, and green components of col to r, g, b.

void col.get_rgb(int& r, int& g, int& b)
    assigns the red, green, and blue components of col to r, g, b.

void col.set_red(int x) sets the red component of col to x.

void col.set_green(int x) sets the green component of col to x.

void col.set_blue(int x) sets the blue component of col to x.

string col.get_string() returns a string representation of col.

color col.text_color() returns a suitable color (black or white) for writing text on a background of color col.


next up previous contents index
Next: Windows ( window ) Up: Graphics Previous: Graphics   Contents   Index