-
Notifications
You must be signed in to change notification settings - Fork 1
/
Color.h
82 lines (67 loc) · 1.57 KB
/
Color.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef COLOR_H
#define COLOR_H
#include <iostream>
#include <string>
using namespace std;
class Color {
private:
double r, g, b;
public:
double getRed() { return r; };
double getGreen() { return g; };
double getBlue() { return b; };
Color();
Color(double inR, double inG, double inB);
Color(const Color &rhs);
Color& operator=(const Color &rhs);
friend Color operator* (double x, const Color& y);
friend Color operator* (const Color& x, double y);
friend Color operator* (const Color& x, const Color& y);
friend Color operator+ (const Color& x, const Color& y);
friend ostream& operator<< (ostream &out, Color &cColor);
};
Color::Color() {
r = 0.0;
g = 0.0;
b = 0.0;
}
Color::Color(double inR, double inG, double inB) {
r = inR;
g = inG;
b = inB;
}
Color::Color(const Color &rhs) {
r = rhs.r;
g = rhs.g;
b = rhs.b;
}
Color& Color::operator=(const Color &rhs) {
if (this == &rhs) {
return *this;
}
r = rhs.r;
g = rhs.g;
b = rhs.b;
return *this;
}
Color operator* (double x, const Color& y) {
return Color(y.r * x, y.g * x, y.b * x);
}
Color operator* (const Color& x, double y) {
return y * x;
}
Color operator* (const Color& x, const Color& y) {
return Color(x.r * y.r, x.g * y.g, x.b * y.b);
}
Color operator+ (const Color& x, const Color& y) {
return Color(x.r + y.r, x.g + y.g, x.b + y.b);
}
ostream& operator<< (ostream &out, Color &v)
{
out << "Color "
<< v.r << " "
<< v.g << " "
<< v.b;
return out;
}
#endif