For representing colors.
A color has red, green, blue, and alpha (opacity) components, each of which is an integer from 0 to 255, inclusive.
The most common way to construct a color is to pass these components to the constructor Color(uint8_t, uint8_t, uint8_t, uint8_t). The components can also be passed as unit-interval double
s to Color::from_rgba(double, double, double, double).
It's also possible to construct a color via alternative color models HSLA and HSVA, and then convert those to RGBA.
Definition at line 23 of file ge211_color.hxx.
Classes | |
struct | HSLA |
Representation for the hue-saturation-lightness-alpha color model. More... | |
struct | HSVA |
Representation for the hue-saturation-value-alpha color model. More... | |
Public Member Functions | |
RGBA-model getters | |
uint8_t | red () const |
Gets the red component of a color. | |
uint8_t | green () const |
Gets the green component of a color. | |
uint8_t | blue () const |
Gets the blue component of a color. | |
uint8_t | alpha () const |
Gets the alpha (opacity) component of a color. | |
Transformations | |
Color | blend (double weight, Color that) const |
Produces a blend of this color and that , with higher weight (between 0 and 1) increasing the level of that . | |
Color | invert () const |
Returns the inverse of a color. | |
Color | rotate_hue (double degrees) const |
Returns a color by rotating the hue, leaving the other properties constant. | |
Color | lighten (double unit_amount) const |
Produces a tint by lightening the color. More... | |
Color | darken (double unit_amount) const |
Produces a shade by darkening the color. More... | |
Color | saturate (double unit_amount) const |
Produces a fuller tone by saturating the color. More... | |
Color | desaturate (double unit_amount) const |
Produces a weaker tone by desaturating the color. More... | |
Color | fade_in (double unit_amount) const |
Increases opacity of the color. More... | |
Color | fade_out (double unit_amount) const |
Decreases opacity of the color. More... | |
Static Public Member Functions | |
Named colors | |
static constexpr Color | white () |
Solid white. | |
static constexpr Color | black () |
Solid black. | |
static Color | medium_red () |
Solid red. | |
static Color | medium_green () |
Solid green. | |
static Color | medium_blue () |
Solid blue. | |
static Color | medium_cyan () |
Solid cyan. | |
static Color | medium_magenta () |
Solid magenta. | |
static Color | medium_yellow () |
Solid yellow. | |
Constructors and factories | |
constexpr | Color () |
Constructs the transparent color. | |
constexpr | Color (uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=255) |
Constructs the color with the given components. More... | |
static Color | from_rgba (double red, double green, double blue, double alpha=1.0) |
Constructs a color with the given components. More... | |
Alternative color models | |
HSLA | to_hsla () const |
Converts a color to the hue-saturation-lightness (HSL) color model. | |
HSVA | to_hsva () const |
Converts a color to the hue-saturation-value (HSV) color model. | |
static Color | from_hsla (double hue, double saturation, double lightness, double alpha=1) |
Constructs a color given the hue, saturation, lightness, and alpha. More... | |
static Color | from_hsva (double hue, double saturation, double value, double alpha=1) |
Constructs a color given the hue, saturation, value, and alpha. More... | |
|
inlineconstexpr |
Constructs the color with the given components.
Components are integers from 0 to 255, inclusive. If alpha
is not provided, it defaults to fully opaque.
Definition at line 38 of file ge211_color.hxx.
Color darken | ( | double | unit_amount | ) | const |
Produces a shade by darkening the color.
The unit_amount
must be between 0 and 1, where 0 leaves the color the same, and 1 produces black.
Definition at line 114 of file ge211_color.cxx.
Color desaturate | ( | double | unit_amount | ) | const |
Produces a weaker tone by desaturating the color.
The unit_amount
must be between 0 and 1, where 0 leaves the color the same, and 1 produces gray at the same lightness as the original color.
Definition at line 124 of file ge211_color.cxx.
Color fade_in | ( | double | unit_amount | ) | const |
Increases opacity of the color.
The unit_amount
must be between 0 and 1, where 0 leaves the color the same, and 1 produces a fully opaque color.
Definition at line 186 of file ge211_color.cxx.
Color fade_out | ( | double | unit_amount | ) | const |
Decreases opacity of the color.
The // unit_amount
must be between 0 and 1, where 0 leaves the color the same, and 1 produces full transparency.
Definition at line 191 of file ge211_color.cxx.
|
static |
Constructs a color given the hue, saturation, lightness, and alpha.
hue | in degrees, from 0.0 to 360.0 |
saturation | from 0.0 to 1.0 |
lightness | from 0.0 to 1.0 |
alpha | opacity, from 0.0 to 1.0 |
Definition at line 73 of file ge211_color.cxx.
|
static |
Constructs a color given the hue, saturation, value, and alpha.
hue | in degrees, from 0.0 to 360.0 |
saturation | from 0.0 to 1.0 |
value | from 0.0 to 1.0 |
alpha | opacity, from 0.0 to 1.0 |
Definition at line 81 of file ge211_color.cxx.
|
static |
Constructs a color with the given components.
Components are doubles from 0.0. to 1.0, inclusive. If alpha
is not given, it defaults to 1.0, meaning fully opaque.
Definition at line 28 of file ge211_color.cxx.
Color lighten | ( | double | unit_amount | ) | const |
Produces a tint by lightening the color.
The amount
must be between 0 and 1, where 0 leaves the color the same, and 1 produces white.
Definition at line 109 of file ge211_color.cxx.
Color saturate | ( | double | unit_amount | ) | const |
Produces a fuller tone by saturating the color.
The unit_amount
must be between 0 and 1, where 0 leaves the color the same, and 1 produces a fully saturated color.
Definition at line 119 of file ge211_color.cxx.