class LM_ColorVector

The ColorVector class is used to represent a color. The rgb_color class is also used to represent colors, but ColorVector's are useful when you need to perform mathematical operations on colors.

Member Variables

r (float)

The red component of the color. Values can range from 0 to 1.


g (float)

The green component of the color. Values can range from 0 to 1.


b (float)

The blue component of the color. Values can range from 0 to 1.


a (float)

The alpha (or opacity) component of the color. Values can range from 0 to 1. An alpha of 0 is a totally transparent color, while a value of 1 indicates a totally opaque color.

Member Functions

void Set(r, g, b, a=1.0)

Set the value of a color. This function is an alternative to setting the r, g, b and a values individually. If you leave out the a value, it will default to 1.0.

r (float): the r value you wish to set
g (float): the g value you wish to set
b (float): the b value you wish to set
a (float): the a value you wish to set (defaults to 1.0)
Return value: none

void Set(color)

Set the value of a color by copying an existing color.

vec (rgb_color): an rgb_color object whose value you wish to copy
Return value: none

void Set(color)

Set the value of a color by copying an existing color.

vec (ColorVector): another ColorVector object whose value you wish to copy
Return value: none

float Mag()

Computes the magnitude of a color vector.

Return value (float): the color's magnitude (length)

float SquaredMag()

Computes the squared magnitude of a color vector.

Return value (float): the color's squared magnitude

void Normalize()

Normalizes a ColorVector. This process ensures that each of the r, g, b and a values is within the range 0 to 1.

Return value: none

void Invert()

Inverts a color.

Return value: none

bool IsBlack()

Returns true if a color is pure black, false otherwise.

Return value (bool): true if the color is pure black, false otherwise

bool IsWhite()

Returns true if a color is pure white, false otherwise.

Return value (bool): true if the color is pure white, false otherwise

bool IsOpaque()

Returns true if a color is totally opaque, false otherwise.

Return value (bool): true if the color is totally opaque, false otherwise

bool IsTransparent()

Returns true if a color is totally transparent, false otherwise.

Return value (bool): true if the color is totally transparent, false otherwise

rgb_color AsColorStruct()

Converts a ColorVector into an rgb_color object, returning the new object.

Return value (rgb_color): a new rgb_color object with the equivalent color values as the original ColorVector

ColorVector operator+(color)

Adds two colors and returns the result as a new color. This operator makes it possible to add two colors as if they were regular numbers. Example: c = a + b.

color (ColorVector): a color to add to the first one
Return value (ColorVector): the sum of two colors

ColorVector operator-(color)

Subtracts one color from another and returns the result as a new color. This operator makes it possible to subtract colors as if they were regular numbers. Example: c = a - b.

color (ColorVector): a color to subtract from the first one
Return value (ColorVector): the difference of two colors

ColorVector operator*(color)

Multiplies one color by another and returns the result as a new color. This operator makes it possible to multiply colors as if they were regular numbers. Example: c = a * b.

color (ColorVector): a color to multiply by the first one
Return value (ColorVector): the result of mutliplying two colors

ColorVector operator*(num)

Multiplies a color by a number, returning the result as a new color. Example: c2 = c * 3.

num (float): a number to multiply the color by
Return value (ColorVector): the original color, multiplied by the number "num"

ColorVector operator/(num)

Divides a color by a number, returning the result as a new color. Example: c2 = c / 3.

num (float): a number to divide the color by
Return value (ColorVector): the original color, divided by the number "num"
  1. class LM_ColorVector @ ColorVector {
  2. LM_ColorVector();
  3. ~LM_ColorVector();
  4.  
  5. void Set(real cr, real cg, real cb);
  6. void Set(real cr, real cg, real cb, real ca);
  7. void Set(rgb_color col);
  8. void Set(const LM_ColorVector &col);
  9. real Mag();
  10. real SquaredMag();
  11. void Normalize();
  12. void Invert();
  13. bool IsBlack();
  14. bool IsWhite();
  15. bool IsOpaque();
  16. bool IsTransparent();
  17. rgb_color AsColorStruct() const;
  18.  
  19. LM_ColorVector operator+(const LM_ColorVector &col2);
  20. LM_ColorVector operator-(const LM_ColorVector &col2);
  21. LM_ColorVector operator*(const LM_ColorVector &col2);
  22. LM_ColorVector operator*(real f);
  23. LM_ColorVector operator/(real f);
  24.  
  25. real r;
  26. real g;
  27. real b;
  28. real a;
  29. };