55 lines
1.0 KiB
C++
55 lines
1.0 KiB
C++
|
|
#include "Color.h"
|
|
|
|
const Color Color::black = Color(0, 0, 0);
|
|
const Color Color::white = Color(1, 1, 1);
|
|
const Color Color::red = Color(1, 0, 0);
|
|
const Color Color::green = Color(0, 1, 0);
|
|
const Color Color::blue = Color(0, 0, 1);
|
|
|
|
Color::Color()
|
|
{
|
|
r = g = b = 0.0;
|
|
}
|
|
|
|
Color::Color(double r, double g, double b)
|
|
{
|
|
this->r = r;
|
|
this->g = g;
|
|
this->b = b;
|
|
}
|
|
|
|
Color Color::operator*(double scale)
|
|
{
|
|
return Color(r * scale, g * scale, b * scale);
|
|
}
|
|
|
|
Color Color::operator/(double scale)
|
|
{
|
|
return Color(r / scale, g / scale, b / scale);
|
|
}
|
|
|
|
Color & Color::operator+=(const Color & other)
|
|
{
|
|
r += other.r;
|
|
g += other.g;
|
|
b += other.b;
|
|
}
|
|
|
|
Color & Color::operator-=(const Color & other)
|
|
{
|
|
r += other.r;
|
|
g += other.g;
|
|
b += other.b;
|
|
}
|
|
|
|
Color operator+(const Color & c1, const Color & c2)
|
|
{
|
|
return Color(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b);
|
|
}
|
|
|
|
Color operator-(const Color & c1, const Color & c2)
|
|
{
|
|
return Color(c1.r - c2.r, c1.g - c2.g, c1.b - c2.b);
|
|
}
|