-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColor.cpp
46 lines (38 loc) · 1.04 KB
/
Color.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Color.hpp"
Color::Color(double r, double g, double b)
{
this->r = r;
this->g = g;
this->b = b;
}
void Color::printColor() const
{
cout << '[' << r << ',' << g << ',' << b << ']' << endl;
}
Color Color::HexToRgb(const string& hexValue)
{
double r = stoi(hexValue.substr(1, 2), nullptr, 16) / 255.0;
double g = stoi(hexValue.substr(3, 2), nullptr, 16) / 255.0;
double b = stoi(hexValue.substr(5, 2), nullptr, 16) / 255.0;
return Color(r, g, b);
}
Color Color::operator+(Color other) const
{
return Color(this->r + other.r, this->g + other.g, this->b + other.b);
}
Color Color::operator-(Color other) const
{
return Color(this->r - other.r, this->g - other.g, this->b - other.b);
}
Color Color::operator*(double number) const
{
return Color(this->r * number, this->g * number, this->b * number);
}
Color operator*(double number, const Color& vector)
{
return vector * number;
}
Color Color::operator/(double number) const
{
return Color(this->r / number, this->g / number, this->b / number);
}