-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor_Container.cpp
More file actions
173 lines (105 loc) · 3.93 KB
/
Color_Container.cpp
File metadata and controls
173 lines (105 loc) · 3.93 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "Color_Container.h"
using namespace std;
/** Default Constructor for the ColorContainer class
Initializes r, g, b to 0 */
ColorContainer::ColorContainer() {
r = 0;
g = 0;
b = 0;
}
/** Constructor for the ColorContainer class
@param hexIn The (usually) hexadecimal value that will be split into r, g and b values */
ColorContainer::ColorContainer(long hexIn) {
r = (hexIn & 0xFF0000) >> 16;
g = (hexIn & 0x00FF00) >> 8;
b = (hexIn & 0x0000FF);
}
/** Constructor for the ColorContainer class
@param rIn The value to be save to r
@param gIn The value to be save to g
@param bIn The value to be save to b */
ColorContainer::ColorContainer(int rIn, int gIn, int bIn) {
r = rIn;
g = gIn;
b = bIn;
}
/** Constructor for the ColorContainer class
@param CRGBIn A reference to a CRGB instance that will be copied into the ColorContainer */
ColorContainer::ColorContainer(const CRGB &CRGBIn) {
r = CRGBIn.r;
g = CRGBIn.g;
b = CRGBIn.b;
}
/** Set Method for the r variable in the ColorContainer class (if intensity over 255, set to 255; if intensity below 0, set to 0)
@param intensity The value to save to r */
void ColorContainer::setr(int intensity) {
if (intensity < 0) r = 0;
if (intensity > 255) r = 255;
if (intensity >= 0 and intensity <= 255) r = intensity;
}
/** Set Method for the g variable in the ColorContainer class (if intensity over 255, set to 255; if intensity below 0, set to 0)
@param intensity The value to save to g */
void ColorContainer::setg(int intensity) {
if (intensity < 0) g = 0;
if (intensity > 255) g = 255;
if (intensity >= 0 and intensity <= 255) g = intensity;
}
/** Set Method for the b variable in the ColorContainer class (if intensity over 255, set to 255; if intensity below 0, set to 0)
@param intensity The value to save to b */
void ColorContainer::setb(int intensity) {
if (intensity < 0) b = 0;
if (intensity > 255) b = 255;
if (intensity >= 0 and intensity <= 255) b = intensity;
}
/** Set Method for the r, g and b variables in the ColorContainer class (if intensity over 255, set to 255; if intensity below 0, set to 0)
@param rIntensity The value to save to r
@param gIntensity The value to save to g
@param bIntensity The value to save to b */
void ColorContainer::setrgb(int rIntensity, int gIntensity, int bIntensity) {
setr(rIntensity);
setg(gIntensity);
setb(bIntensity);
return;
}
/** Set Method for the r, g and b variables in the ColorContainer class using long hexadecimal input
@param hexIn The value containing r, g, and b values */
void ColorContainer::setrgb(long hexIn) {
r = (hexIn & 0xFF0000) >> 16;
g = (hexIn & 0x00FF00) >> 8;
b = (hexIn & 0x0000FF);
return;
}
/** Set Method for the r, g and b variables in the ColorContainer class using CRGB input
@param CRGBIn A reference to a CRGB instance that will be copied into the ColorContainer */
void ColorContainer::setrgb(const CRGB &CRGBIn) {
r = CRGBIn.r;
g = CRGBIn.g;
b = CRGBIn.b;
}
/** Special Set Method for the ColorContainer class
Sets r, g, b to 0 */
void ColorContainer::blackout() {
r = 0;
g = 0;
b = 0;
}
/** Get Method for the r variable in the ColorContainer class
@return The value of r in the invoking instance */
int ColorContainer::getr() { return r; }
/** Get Method for the g variable in the ColorContainer class
@return The value of g in the invoking instance */
int ColorContainer::getg() { return g; }
/** Get Method for the b variable in the ColorContainer class
@return The value of b in the invoking instance */
int ColorContainer::getb() { return b; }
/** Get Method for the r, g and b variables in the ColorContainer class
@return The r, g and b values, formatted into a 6-digit hexadecimal long integer */
long ColorContainer::getColorHex() {
long temp;
temp = r;
temp <<= 8;
temp |= g;
temp <<= 8;
temp |= b;
return temp;
}