11
Color():r(0), g(0), b(0) {}
12
explicit Color(float i):r(i), g(i), b(i) {}
13
explicit Color(float i, float j, float k):r(i), g(j), b(k) {}
14
Color(const Color &c):r(c.r), g(c.g), b(c.b) {}
18
void set(float i) { r=g=b=i; }
19
void set(float i, float j, float k) { r=i; g=j; b=k; }
21
Color operator+(const Color &c) const { return Color(r+c.r, g+c.g, b+c.b); }
22
Color operator-(const Color &c) const { return Color(r-c.r, g-c.g, b-c.b); }
23
Color operator*(float s) const { return Color(r*s, g*s, b*s); }
24
friend Color operator*(float s, const Color &c) { return Color(c.r*s, c.g*s, c.b*s); }
25
Color operator*(const Color &c) const { return Color(r*c.r, g*c.g, b*c.b); }
26
Color operator/(float s) const { if (s!=0) s=1.f/s; return Color(r*s, g*s, b*s); }
27
Color& operator+=(const Color &c) { r+=c.r; g+=c.g; b+=c.b; return *this; }
28
Color& operator-=(const Color &c) { r-=c.r; g-=c.g; b-=c.b; return *this; }
29
Color& operator*=(float s) { r*=s; g*=s; b*=s; return *this; }
30
Color& operator*=(const Color &c) { r*=c.r; g*=c.g; b*=c.b; return *this; }
31
Color& operator/=(float s) { if (s!=0) s=1.f/s; r*=s; g*=s; b*=s; return *this; }
32
float& operator[](int i) { return rgb[i]; } // no bounds check!
33
float operator[](int i) const { return rgb[i]; } // no bounds check!
36
struct { float r, g, b; };
41
Color rgb2hsl(const Color& rgb);
42
Color hsl2rgb(const Color& hsl);