CS 19: HSV Color Class
|
Represents an immutable HSV (hue, saturation, value) color where each of the three components is represented as a float. More...
#include <cs19_hsv_color.h>
Public Member Functions | |
HsvColor (float hue, float saturation, float value) | |
Constructs a new HsvColor with the given HSV components. More... | |
HsvColor | operator~ () const |
Returns a complementary color, with the hue shifted 180°. | |
HsvColor | operator| (const HsvColor &that) const |
Returns a color that is linearly interpolated between this and another (i.e., with the H/S/V components averaged between the two colors). | |
HsvColor | grayscale () const |
Returns the grayscale (desaturated) version of this color. | |
std::string | to_hex_string () const |
Returns a CSS-compatible color string in 24-bit RGB hexadecimal format, e.g. More... | |
std::string | to_rgb_string () const |
Returns a CSS-compatible color string in 24-bit RGB decimal format, e.g. More... | |
float | hue () const |
Returns the hue component of this color in degrees, [0.0, 360.0]. | |
float | saturation () const |
Returns the saturation component of this color as a percentage, [0.0, 1.0]. | |
float | value () const |
Returns the value component of this color as a percentage, [0.0, 1.0]. | |
int | red () const |
Returns the closest 8-bit red component of this color in RGB, [0, 255]. | |
int | green () const |
Returns the closest 8-bit green component of this color in RGB, [0, 255]. | |
int | blue () const |
Returns the closest 8-bit blue component of this color in RGB, [0, 255]. | |
Represents an immutable HSV (hue, saturation, value) color where each of the three components is represented as a float.
Offers a few overloaded operators and other functions, including several related to converting a HSV color to its equivalent 24-bit RGB components.
cs19::HsvColor::HsvColor | ( | float | hue, |
float | saturation, | ||
float | value | ||
) |
Constructs a new HsvColor with the given HSV components.
(hue: [0.0, 360.0], saturation: [0.0, 1.0], value: [0.0, 1.0])
std::domain_error | if any component is out of range. |
std::string cs19::HsvColor::to_hex_string | ( | ) | const |
Returns a CSS-compatible color string in 24-bit RGB hexadecimal format, e.g.
"#000000" for black, "#ffffff" for white, and "#6495ed" for cornflower blue.
std::string cs19::HsvColor::to_rgb_string | ( | ) | const |
Returns a CSS-compatible color string in 24-bit RGB decimal format, e.g.
"rgb(0,0,0)" for black, "rgb(255,255,255)" for white, and "rgb(100, 149, 237)" for cornflower blue.