-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColour.cpp
More file actions
89 lines (71 loc) · 1.38 KB
/
Colour.cpp
File metadata and controls
89 lines (71 loc) · 1.38 KB
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
83
84
85
86
87
88
89
#include "Colour.h"
using namespace std;
Colour::Colour()
{
_red = 0;
_blue = 0;
_green = 0;
}
Colour::Colour(const Colour& col)
{
_red = col._red;
_blue = col._blue;
_green = col._green;
}
Colour::Colour(int r,int g,int b)
{
_red = r;
_green = g;
_blue = b;
}
Colour::~Colour()
{
//left blank
}
void Colour::assignColour(int r,int g,int b)
{
_red = r;
_green = g;
_blue = b;
}
int Colour::getRed() const
{
return _red;
}
int Colour::getBlue() const
{
return _blue;
}
int Colour::getGreen() const
{
return _green;
}
bool Colour::operator==(const Colour& col)
{
if(_red == col._red && _green == col._green && _blue == col._blue)
return true;
return false;
}
Colour const& Colour::operator=(Colour const &c)
{
_red = c._red;
_blue = c._blue;
_green = c._green;
return *this;
}
Colour& operator+(Colour c1,Colour c2)
{
Colour *res = new Colour();
res->_red = c1._red + c2._red;
if(res->_red > 255) res->_red = 255;
res->_green = c1._green + c2._green;
if(res->_green > 255) res->_green = 255;
res->_blue = c1._blue + c2._blue;
if(res->_blue> 255) res->_blue = 255;
return *res;//returns a reference so that it can directly be used with the output stream
}
ostream& operator<<(ostream &os, Colour &c)
{
os << c._red << " " << c._green << " " << c._blue;
return os;
}