codac 2.0.0
Loading...
Searching...
No Matches
codac2::Color Struct Reference

Color structure, in RGBA or HSVA format. More...

#include <codac2_Color.h>

Public Member Functions

 Color ()
 Default constructor.
 
 Color (const std::array< float, 3 > &xyz, Model m_=Model::RGB)
 Constructor from an array of 3 floats.
 
 Color (const std::array< float, 4 > &xyza, Model m_=Model::RGB)
 Constructor from an array of 4 floats.
 
 Color (const std::initializer_list< float > xyza, Model m_=Model::RGB)
 Constructor from an initializer list of floats.
 
 Color (const std::string &hex_str)
 Constructor from a hex string.
 
const Modelmodel () const
 Getter for the color model.
 
std::string hex_str () const
 Converts the color to a hex string in html format.
 
codac2::Vector vec () const
 Converts the color to a codac2::Vector.
 
Color rgb () const
 Converts the color to RGB format.
 
Color hsv () const
 Converts the color to HSV format.
 

Static Public Member Functions

static Color none ()
 Empty color (transparent white)
 
static Color black (float alpha=1.)
 Black color.
 
static Color white (float alpha=1.)
 White color.
 
static Color green (float alpha=1.)
 Green color.
 
static Color blue (float alpha=1.)
 Blue color.
 
static Color cyan (float alpha=1.)
 Cyan color.
 
static Color yellow (float alpha=1.)
 Yellow color.
 
static Color red (float alpha=1.)
 Red color.
 
static Color dark_gray (float alpha=1.)
 Dark gray color.
 
static Color purple (float alpha=1.)
 Light gray color.
 
static Color dark_green (float alpha=1.)
 Dark green color.
 

Detailed Description

Color structure, in RGBA or HSVA format.

This class is used to represent a Color, either in RGBA or HSVA format. It inherits from std::array<float,4> and provides methods to convert between different color models.

For RGBA, the values are in the range [0,255].

For HSVA, the values are in the range [0,360] for hue and [0,100] for saturation, value and alpha.

Predefined Colors are also available.

Constructor & Destructor Documentation

◆ Color() [1/5]

codac2::Color::Color ( )
explicit

Default constructor.

All values are set to 0

◆ Color() [2/5]

codac2::Color::Color ( const std::array< float, 3 > & xyz,
Model m_ = Model::RGB )
explicit

Constructor from an array of 3 floats.

Parameters
xyzArray of 3 floats (RGB or HSV values)
m_Color model (RGB or HSV)

◆ Color() [3/5]

codac2::Color::Color ( const std::array< float, 4 > & xyza,
Model m_ = Model::RGB )
explicit

Constructor from an array of 4 floats.

Parameters
xyzaArray of 4 floats (RGBA or HSVA values)
m_Color model (RGB or HSV)

◆ Color() [4/5]

codac2::Color::Color ( const std::initializer_list< float > xyza,
Model m_ = Model::RGB )
explicit

Constructor from an initializer list of floats.

Parameters
xyzaInitializer list of floats (RGB, RGBA, HSV or HSVA values)
m_Color model (RGB or HSV)

◆ Color() [5/5]

codac2::Color::Color ( const std::string & hex_str)
explicit

Constructor from a hex string.

Parameters
hex_strHex string in html format (e.g. #ff0000 or #ff0000ff)

Member Function Documentation

◆ model()

const Model & codac2::Color::model ( ) const
inline

Getter for the color model.

Returns
The color model (RGB or HSV)
95{ return m; }

◆ hex_str()

std::string codac2::Color::hex_str ( ) const

Converts the color to a hex string in html format.

Returns
The color as a hex string (e.g. #ff0000 or #ff0000ff)

◆ vec()

codac2::Vector codac2::Color::vec ( ) const

Converts the color to a codac2::Vector.

Returns
The color as a codac2::Vector

◆ rgb()

Color codac2::Color::rgb ( ) const

Converts the color to RGB format.

Returns
The Color in RGB format

◆ hsv()

Color codac2::Color::hsv ( ) const

Converts the color to HSV format.

Returns
The Color in HSV format

◆ black()

static Color codac2::Color::black ( float alpha = 1.)
inlinestatic

Black color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
162{ return Color({0., 0., 0., (float) (alpha*255.)}); };
Color()
Default constructor.

◆ white()

static Color codac2::Color::white ( float alpha = 1.)
inlinestatic

White color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
169{ return Color({255., 255., 255., (float) (alpha*255.)}); };

◆ green()

static Color codac2::Color::green ( float alpha = 1.)
inlinestatic

Green color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
176{ return Color({144., 242., 0., (float) (alpha*255.)}); };

◆ blue()

static Color codac2::Color::blue ( float alpha = 1.)
inlinestatic

Blue color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
183{ return Color({0., 98., 198., (float) (alpha*255.)}); };

◆ cyan()

static Color codac2::Color::cyan ( float alpha = 1.)
inlinestatic

Cyan color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
190{ return Color({75., 207., 250., (float) (alpha*255.)}); };

◆ yellow()

static Color codac2::Color::yellow ( float alpha = 1.)
inlinestatic

Yellow color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
197{ return Color({255., 211., 42., (float) (alpha*255.)}); };

◆ red()

static Color codac2::Color::red ( float alpha = 1.)
inlinestatic

Red color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
204{ return Color({209., 59., 0., (float) (alpha*255.)}); };

◆ dark_gray()

static Color codac2::Color::dark_gray ( float alpha = 1.)
inlinestatic

Dark gray color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
211{ return Color({112., 112., 112., (float) (alpha*255.)}); };

◆ purple()

static Color codac2::Color::purple ( float alpha = 1.)
inlinestatic

Light gray color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
218{ return Color({154., 0., 170., (float) (alpha*255.)}); };

◆ dark_green()

static Color codac2::Color::dark_green ( float alpha = 1.)
inlinestatic

Dark green color.

Parameters
alphaAlpha value between 0. (transparent) and 1. (opaque)
225{ return Color({94., 158., 0., (float) (alpha*255.)}); };

The documentation for this struct was generated from the following file: