43 struct Color :
public std::array<float,4>
65 explicit Color(
const std::array<float,3>& xyz,
Model m_ = Model::RGB);
73 explicit Color(
const std::array<float,4>& xyza,
Model m_ = Model::RGB);
81 explicit Color(
const std::initializer_list<float> xyza,
Model m_ = Model::RGB);
113 codac2::Vector
vec()
const;
143 if (c.m == Model::RGB)
144 os <<
"RGB Color (" << c[0] <<
"," << c[1] <<
"," << c[2] <<
"," << c[3] <<
")";
145 else if (c.m == Model::HSV)
146 os <<
"HSV Color (" << c[0] <<
"," << c[1] <<
"," << c[2] <<
"," << c[3] <<
")";
162 static Color black(
float alpha = 1.) {
return Color({0., 0., 0., (float) (alpha*255.)}); };
169 static Color white(
float alpha = 1.) {
return Color({255., 255., 255., (float) (alpha*255.)}); };
176 static Color green(
float alpha = 1.) {
return Color({144., 242., 0., (float) (alpha*255.)}); };
183 static Color blue(
float alpha = 1.) {
return Color({0., 98., 198., (float) (alpha*255.)}); };
190 static Color cyan(
float alpha = 1.) {
return Color({75., 207., 250., (float) (alpha*255.)}); };
197 static Color yellow(
float alpha = 1.) {
return Color({255., 211., 42., (float) (alpha*255.)}); };
204 static Color red(
float alpha = 1.) {
return Color({209., 59., 0., (float) (alpha*255.)}); };
218 static Color purple(
float alpha = 1.) {
return Color({154., 0., 170., (float) (alpha*255.)}); };
228 template <std::
size_t N>
229 static std::array<float, N> to_array(
const std::initializer_list<float>& list) {
230 assert(list.size() == N);
231 std::array<float, N> arr;
232 std::copy(list.begin(), list.end(), arr.begin());
Model
Color model (RGB or HSV)
Definition codac2_Color.h:28
codac2::Vector vec() const
Converts the color to a codac2::Vector.
static Color green(float alpha=1.)
Green color.
Definition codac2_Color.h:176
Color(const std::initializer_list< float > xyza, Model m_=Model::RGB)
Constructor from an initializer list of floats.
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.
static Color purple(float alpha=1.)
Light gray color.
Definition codac2_Color.h:218
static Color black(float alpha=1.)
Black color.
Definition codac2_Color.h:162
static Color blue(float alpha=1.)
Blue color.
Definition codac2_Color.h:183
static Color red(float alpha=1.)
Red color.
Definition codac2_Color.h:204
static Color dark_green(float alpha=1.)
Dark green color.
Definition codac2_Color.h:225
Color rgb() const
Converts the color to RGB format.
static Color yellow(float alpha=1.)
Yellow color.
Definition codac2_Color.h:197
Color(const std::string &hex_str)
Constructor from a hex string.
Color hsv() const
Converts the color to HSV format.
static Color cyan(float alpha=1.)
Cyan color.
Definition codac2_Color.h:190
static Color white(float alpha=1.)
White color.
Definition codac2_Color.h:169
static Color dark_gray(float alpha=1.)
Dark gray color.
Definition codac2_Color.h:211
static Color none()
Empty color (transparent white)
Definition codac2_Color.h:155
std::string hex_str() const
Converts the color to a hex string in html format.
friend std::ostream & operator<<(std::ostream &os, const Color &c)
Overload of the << operator for the Color class.
Definition codac2_Color.h:141
const Model & model() const
Getter for the color model.
Definition codac2_Color.h:95
Color()
Default constructor.