Color
Class representing a RGBA color with component values between 0.0 and
1.0.
A Color instance is represented by RGBA components. Colors can be
initialized from hexadecimal values, strings, color names, HSL values,
or separate RGBA components. Key Features:
- RGBA component storage (r, g, b, a)
- Multiple initialization methods (hex, strings, color names, HSL)
- Color operations (add, subtract, multiply, lerp)
- HSL conversion support
- color name dictionary Usage:
- Create colors from hex: Color(0xff0000)
- Create colors from RGB: Color(1.0f, 0.0f, 0.0f)
- Create colors from RGBA: Color(1.0f, 0.0f, 0.0f, 1.0f)
- Create colors from strings: Color("rgb(255, 0, 0)")
- Create colors from names: Color("red")
Methods
Color()
Default constructor - creates white color (1, 1, 1, 1)
Color(f32 r, f32 g, f32 b)
Value constructor from RGB components
| r | Red component (0.0-1.0) | 1.0f |
| g | Green component (0.0-1.0) | 1.0f |
| b | Blue component (0.0-1.0) | 1.0f |
Color(f32 r, f32 g, f32 b, f32 a)
Value constructor from RGBA components
| r | Red component (0.0-1.0) | 1.0f |
| g | Green component (0.0-1.0) | 1.0f |
| b | Blue component (0.0-1.0) | 1.0f |
| a | Alpha component (0.0-1.0) | 1.0f |
Color(u32 hex)
Constructor from hexadecimal value
| hex | Hexadecimal color value (e.g., 0xff0000) |
Color(const string& style)
Constructor from string or color name
| style | string (e.g., "rgb(255,0,0)") or color name (e.g., "red") |
Color& set(f32 r, f32 g, f32 b)
Sets color from RGB components
| r | Red component (0.0-1.0) | |
| g | Green component (0.0-1.0) | |
| b | Blue component (0.0-1.0) |
Color& set(f32 r, f32 g, f32 b, f32 a)
Sets color from RGBA components
| r | Red component (0.0-1.0) | |
| g | Green component (0.0-1.0) | |
| b | Blue component (0.0-1.0) | |
| a | Alpha component (0.0-1.0) |
Color& set(const Color& color)
Sets color from another Color instance
| color | Source color |
Color& set(u32 hex)
Sets color from hexadecimal value
| hex | Hexadecimal color value |
Color& set(const string& style)
Sets color from string or color name
| style | string or color name |
Color& setScalar(f32 scalar)
Sets all RGBA components to the same value
| scalar | Value to set for all components (0.0-1.0) |
Color& setHex(u32 hex)
Sets color from hexadecimal value
| hex | Hexadecimal color value (e.g., 0xff0000) |
Color& setRGB(f32 r, f32 g, f32 b)
Sets color from RGB values (alpha unchanged)
| r | Red channel value (0.0-1.0) | |
| g | Green channel value (0.0-1.0) | |
| b | Blue channel value (0.0-1.0) |
Color& setRGBA(f32 r, f32 g, f32 b, f32 a)
Sets color from RGBA values
| r | Red channel value (0.0-1.0) | |
| g | Green channel value (0.0-1.0) | |
| b | Blue channel value (0.0-1.0) | |
| a | Alpha channel value (0.0-1.0) |
Color& setHSL(f32 h, f32 s, f32 l)
Sets color from HSL values
| h | Hue value (0.0-1.0) | |
| s | Saturation value (0.0-1.0) | |
| l | Lightness value (0.0-1.0) |
Color& setStyle(const string& style)
Sets color from string
| style | string (e.g., "rgb(255,0,0)", "hsl(0,100%,50%)", "#ff0000") |
Color& setColorName(const string& name)
Sets color from color name
| name | Color name (e.g., "red", "skyblue") |
Color& setFromVector3(const Vector3& v)
Sets color from Vector3 components
| v | Vector3 with x=r, y=g, z=b |
Color clone() const
Creates a copy of this color
Color& copy(const Color& color)
Copies values from another color
| color | Source color |
Color& convertSRGBToLinear()
Converts color from SRGB to linear space
Color& convertLinearToSRGB()
Converts color from linear to SRGB space
Color& copySRGBToLinear(const Color& color)
Copies color and converts from SRGB to linear
| color | Source color in SRGB space |
Color& copyLinearToSRGB(const Color& color)
Copies color and converts from linear to SRGB
| color | Source color in linear space |
u32 getHex() const
Returns hexadecimal value of this color
string getHexString() const
Returns hexadecimal value as string
Color& getRGB(Color& target) const
Gets RGB values and stores in target
| target | Target color to store RGB values |
void getHSL(f32& h, f32& s, f32& l) const
Converts color to HSL and stores in parameters
| h | Hue value (0.0-1.0) | |
| s | Saturation value (0.0-1.0) | |
| l | Lightness value (0.0-1.0) |
string getStyle() const
Returns style string representation
Color& add(const Color& color)
Adds RGB values of another color
| color | Color to add |
Color& addColors(const Color& color1, const Color& color2)
Sets this color to sum of two colors
| color1 | First color | |
| color2 | Second color |
Color& addScalar(f32 s)
Adds scalar to all RGB components
| s | Scalar value to add |
Color& sub(const Color& color)
Subtracts RGB values of another color
| color | Color to subtract |
Color& multiply(const Color& color)
Multiplies RGB values by another color
| color | Color to multiply by |
Color& multiplyScalar(f32 s)
Multiplies all RGB components by scalar
| s | Scalar value to multiply by |
Color& lerp(const Color& color, f32 alpha)
Linearly interpolates toward another color
| color | Target color | |
| alpha | Interpolation factor (0.0-1.0) |
Color& lerpColors(const Color& color1, const Color& color2, f32 alpha)
Sets this color to lerp between two colors
| color1 | First color | |
| color2 | Second color | |
| alpha | Interpolation factor (0.0-1.0) |
Color& lerpHSL(const Color& color, f32 alpha)
Linearly interpolates HSL values toward another color
| color | Target color | |
| alpha | Interpolation factor (0.0-1.0) |
Color& offsetHSL(f32 h, f32 s, f32 l)
Adds HSL values to this color
| h | Hue offset (0.0-1.0) | |
| s | Saturation offset (0.0-1.0) | |
| l | Lightness offset (0.0-1.0) |
Color& applyMatrix3(const Matrix3& m)
Transforms color with 3x3 matrix
| m | 3x3 transformation matrix |
bool equals(const Color& c) const
Checks if this color equals another
| c | Color to compare with |
Color& fromArray(const f32* array, u32 offset)
Sets color from array of floats
| array | Array of float values [r, g, b] or [r, g, b, a] | |
| offset | Starting offset in array |
f32* toArray(f32* array, u32 offset) const
Writes RGBA components to array
| array | Target array (nullptr for static temp) | |
| offset | Starting offset in array |
Color& fromBufferAttribute(const class BufferAttribute& attribute, u32 index)
Sets color from buffer attribute
| attribute | Buffer attribute holding color data | |
| index | Index into the attribute |
GXColor toGXColor() const
Converts Color to GXColor (mostly used internally in light, material)
Properties
| NAMES | static const map<string, u32> | color names dictionary |
| a | f32 | Alpha component (0.0-1.0) |
| b | f32 | Blue component (0.0-1.0) |
| g | f32 | Green component (0.0-1.0) |
| id | u32 | Unique identifier |
| isColor | bool | Read-only tag |
| name | string | Optional display name |
| r | f32 | Red component (0.0-1.0) |
| uuid | string | UUID string |