Color class by value built-in

Color with floating-point red, green, blue and alpha channels

Channels are usually in the range 0 to 1. Constructors taking channel values clamp alpha to that range, the other channels are kept as given and arithmetic doesn't clamp at all.

Constructors

Color(const Color&in)
Creates a copy of another color
Color(const vec3&in, float)
Creates a color from a vector and an alpha value
Color(const vec4&in)
Creates a color from a vector
Color(float, float, float)
Creates an opaque color from red, green and blue channels
Color(float, float, float, float)
Creates a color from red, green, blue and alpha channels

Operators

Color opAdd(const Color&in color) const +
Adds two colors channel by channel
Color& opAddAssign(const Color&in v) += C++
Adds another color channel by channel in place
Color& opAssign(const Color&in color) = C++
Copies another color
bool opEquals(const Color&in color) const == C++
Returns whether all four channels are exactly equal
Color opMul(float scalar) const *
Multiplies every channel by a number
Color opMul(const Color&in color) const *
Multiplies the colors channel by channel
Color& opMulAssign(float scalar) *= C++
Multiplies every channel by a number in place
Color& opMulAssign(const Color&in color) *= C++
Multiplies by another color channel by channel in place
Color opSub(const Color&in color) const -
Subtracts two colors channel by channel
Color& opSubAssign(const Color&in v) -= C++
Subtracts another color channel by channel in place

Properties

float a
Alpha (opacity) channel, 0 is fully transparent and 1 is fully opaque
float b
Blue channel, usually in the range 0 to 1
float g
Green channel, usually in the range 0 to 1
float r
Red channel, usually in the range 0 to 1

Constructor documentation

Color::Color(const vec3&in, float)

Creates a color from a vector and an alpha value

The X, Y and Z components of the vector become red, green and blue. Alpha is clamped to the range 0 to 1.

Color::Color(const vec4&in)

Creates a color from a vector

The X, Y, Z and W components become red, green, blue and alpha. Alpha is clamped to the range 0 to 1.

Color::Color(float, float, float, float)

Creates a color from red, green, blue and alpha channels

Alpha is clamped to the range 0 to 1.

Operator documentation

Color Color::opAdd(const Color&in color) const +

Adds two colors channel by channel

Applies to all four channels including alpha. The result isn't clamped.

Color Color::opMul(float scalar) const *

Multiplies every channel by a number

Applies to all four channels including alpha. The result isn't clamped.

Color Color::opMul(const Color&in color) const *

Multiplies the colors channel by channel

Useful for tinting, e.g. multiplying by Color(1.0f, 0.5f, 0.5f) reduces green and blue by half.

Color Color::opSub(const Color&in color) const -

Subtracts two colors channel by channel

Applies to all four channels including alpha. The result isn't clamped.