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 22 of file ge211_color.h.
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 noexcept |
Gets the red component of a color. | |
uint8_t | green () const noexcept |
Gets the green component of a color. | |
uint8_t | blue () const noexcept |
Gets the blue component of a color. | |
uint8_t | alpha () const noexcept |
Gets the alpha (opacity) component of a color. | |
Transformations | |
Color | invert () const noexcept |
Returns the inverse of a color. | |
Color | rotate_hue (double degrees) const noexcept |
Returns a color by rotating the hue, leaving the other properties constant. More... | |
Color | lighten (double unit_amount) const noexcept |
Produces a tint by lightening the color. More... | |
Color | darken (double unit_amount) const noexcept |
Produces a shade by darkening the color. More... | |
Color | saturate (double unit_amount) const noexcept |
Produces a fuller tone by saturating the color. More... | |
Color | desaturate (double unit_amount) const noexcept |
Produces a weaker tone by desaturating the color. More... | |
Color | fade_in (double unit_amount) const noexcept |
Increases opacity of the color. More... | |
Color | fade_out (double unit_amount) const noexcept |
Decreases opacity of the color. More... | |
Static Public Member Functions | |
Named colors | |
static constexpr Color | white () noexcept |
Solid white. | |
static constexpr Color | black () noexcept |
Solid black. | |
static Color | medium_red () noexcept |
Solid red. | |
static Color | medium_green () noexcept |
Solid green. | |
static Color | medium_blue () noexcept |
Solid blue. | |
static Color | medium_cyan () noexcept |
Solid cyan. | |
static Color | medium_magenta () noexcept |
Solid magenta. | |
static Color | medium_yellow () noexcept |
Solid yellow. | |
Constructors and factories | |
constexpr | Color () noexcept |
Constructs the transparent color. | |
constexpr | Color (uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=255) noexcept |
Constructs the color with the given components. More... | |
static Color | from_rgba (double red, double green, double blue, double alpha=1.0) noexcept |
Constructs a color with the given components. More... | |
Alternative color models | |
HSLA | to_hsla () const noexcept |
Converts a color to the hue-saturation-lightness (HSL) color model. | |
HSVA | to_hsva () const noexcept |
Converts a color to the hue-saturation-value (HSV) color model. | |
static Color | from_hsla (double hue, double saturation, double lightness, double alpha=1) noexcept |
Constructs a color given the hue, saturation, lightness, and alpha. More... | |
static Color | from_hsva (double hue, double saturation, double value, double alpha=1) noexcept |
Constructs a color given the hue, saturation, value, and alpha. More... | |
|
inlinenoexcept |
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 37 of file ge211_color.h.
|
noexcept |
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 102 of file ge211_color.cpp.
|
noexcept |
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 112 of file ge211_color.cpp.
|
noexcept |
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 174 of file ge211_color.cpp.
|
noexcept |
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 179 of file ge211_color.cpp.
|
staticnoexcept |
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 71 of file ge211_color.cpp.
|
staticnoexcept |
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 79 of file ge211_color.cpp.
|
staticnoexcept |
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 26 of file ge211_color.cpp.
|
noexcept |
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 97 of file ge211_color.cpp.
|
noexcept |
Returns a color by rotating the hue, leaving the other properties constant.
Definition at line 92 of file ge211_color.cpp.
|
noexcept |
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 107 of file ge211_color.cpp.