-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.cpp
executable file
·120 lines (95 loc) · 1.64 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Color.cpp
*
*
* Created by Donald House on 9/24/08.
* Copyright 2008 Clemson University. All rights reserved.
*
*/
#include "Color.h"
Color::Color(float r0, float g0, float b0, float a0){
set(r0, g0, b0, a0);
}
Color::Color(const Color &c){
set(c);
}
void Color::set(const Color &c){
set(c.r, c.g, c.b, c.a);
}
void Color::set(float r0, float g0, float b0, float a0){
r = r0;
g = g0;
b = b0;
a = a0;
}
const Color &Color::operator=(const Color &c){
r = c.r;
g = c.g;
b = c.b;
a = c.a;
return *this;
}
float *Color::glcolor(){
return &r;
}
float &Color::operator[](int i){ // colors can be accesed as array
switch(i){
case 0:
return r;
break;
case 1:
return g;
break;
case 2:
return b;
break;
case 3:
default:
return a;
break;
}
}
Color Color::operator+(const Color &c){
Color rc;
rc.r = r + c.r;
rc.g = g + c.g;
rc.b = b + c.b;
rc.a = a + c.a;
return rc;
}
Color Color::operator*(const Color &c){
Color rc;
rc.r = r * c.r;
rc.g = g * c.g;
rc.b = b * c.b;
rc.a = a * c.a;
return rc;
}
Color Color::operator*(float s){
Color rc;
rc.r = s * r;
rc.g = s * g;
rc.b = s * b;
rc.a = s * a;
return rc;
}
Color Color::operator/(float s){
Color rc;
rc.r = r / s;
rc.g = g / s;
rc.b = b / s;
rc.a = a / s;
return rc;
}
Color operator*(float s, const Color &c){
Color rc;
rc.r = s * c.r;
rc.g = s * c.g;
rc.b = s * c.b;
rc.a = s * c.a;
return rc;
}
ostream& operator<< (ostream& os, const Color& c){
os << "(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")";
return os;
}