-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.cpp
65 lines (57 loc) · 916 Bytes
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include "Color.h"
Color::Color()
:
r(1.0),
g(1.0),
b(1.0)
{
}
Color::Color(float r, float g, float b)
{
if(r>=0.0 && r<=1.0)
{
this->r = r;
}
else
{
this->r = 1.0;
}
if(g>=0.0 && g<=1.0)
{
this->g = g;
}
else
{
this->g = 1.0;
}
if(b>=0.0 && b<=1.0)
{
this->b = b;
}
else
{
this->b = 1.0;
}
}
Color Color::operator+(const Color& c)
{
this->r = this->r + c.r;
this->g = this->g + c.g;
this->b = this->b + c.b;
return *this;
}
Color Color::operator*(const Color& c)
{
this->r = this->r * c.r;
this->g = this->g * c.g;
this->b = this->b * c.b;
return *this;
}
Color Color::operator*(float scalar)
{
this->r = this->r * scalar;
this->g = this->g * scalar;
this->b = this->b * scalar;
return *this;
}