Color
This class stores color values as three floating-point channels (red, green, blue), normalized to the range . It does not include an alpha component. Color supports construction from floats, hexadecimal values, and spans, as well as basic arithmetic operations.
Construction
Constructors
Color() constexpr
Constructs a color from individual RGB components.
The components are assumed to be in linear color space.
Color::Color(float r, float g, float b);| Parameter | Description |
|---|---|
| r | |
| g | |
| b |
Color() constexpr
Constructs a color from a span of three float values.
Color::Color(std::span<float> color);| Parameter | Description |
|---|---|
| color | Span containing red, green, and blue components. |
Color() constexpr
Constructs a color from a hexadecimal value.
The format is 0xRRGGBB. The hexadecimal value is interpreted as an sRGB color (as commonly used in CSS and color pickers) and is converted to linear RGB for storage in this Color instance.
Color::Color(unsigned int hex);| Parameter | Description |
|---|---|
| hex | Hexadecimal color code in 0xRRGGBB format (sRGB). |
Properties
b float
Blue channel in .
float b {1.0f};g float
Green channel in .
float g {1.0f};r float
Red channel in .
float r {1.0f};Functions
Multiplies the color by a scalar in-place.
Color& Color::operator* =(float n);| Parameter | Description |
|---|---|
| n | Scalar value. |
Assigns a new color from a hexadecimal value.
Color& Color::operator=(unsigned int hex);| Parameter | Description |
|---|---|
| hex | Hexadecimal color code in 0xRRGGBB format. |
operator[]() float &
Accesses a channel by index.
float& Color::operator[](int i);| Parameter | Description |
|---|---|
| i | Index: 0 → r, 1 → g, 2 → b. |
operator[]() float
Accesses a channel by index.
float Color::operator[](int i) const;| Parameter | Description |
|---|---|
| i | Index: 0 → r, 1 → g, 2 → b. |
Linearly interpolates between two colors.
Color Lerp(const Color& a, const Color& b, float f);| Parameter | Description |
|---|---|
| a | Start color. |
| b | |
| f | Interpolation factor in . |
Multiplies a color by a scalar.
Color operator* (const Color& v, float n);| Parameter | Description |
|---|---|
| v | Input color. |
| n | Scalar value. |
Multiplies a scalar by a color.
Color operator* (float n, const Color& v);| Parameter | Description |
|---|---|
| n | Scalar value. |
| v | Input color. |
Adds two colors component-wise.
Color operator+(const Color& a, const Color& b);| Parameter | Description |
|---|---|
| a | First color. |
| b |