-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.cpp
More file actions
55 lines (42 loc) · 983 Bytes
/
Color.cpp
File metadata and controls
55 lines (42 loc) · 983 Bytes
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
#include "Color.hpp"
Color::Color()
: R(0.0), G(0), B(0)
{}
Color::Color(double r, double g, double b)
: R(r), G(g), B(b)
{}
double Color::getR() const {
return R;
}
double Color::getG() const {
return G;
}
double Color::getB() const {
return B;
}
Color Color::add(const Color& other) const {
return Color(R + other.R, G + other.G, B + other.B);
}
Color Color::add(double value) const {
return Color(R + value, G + value, B + value);
}
Color Color::operator+(const Color& other) const {
return add(other);
}
Color Color::operator+(double value) const {
return add(value);
}
Color Color::mult_scalar(double value) const {
return Color(R * value, G * value, B * value);
}
Color Color::operator*(double value) const {
return mult_scalar(value);
}
void Color::cap() {
if (R > 1.0) R = 1.0;
if (G > 1.0) G = 1.0;
if (B > 1.0) B = 1.0;
if (R < 0.0) R = 0.0;
if (G < 0.0) G = 0.0;
if (B < 0.0) B = 0.0;
}