-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.cpp
62 lines (57 loc) · 985 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
#include "Color.h"
Color::Color(double red, double green, double blue)
{
double *param[] = {&red, &green, &blue};
for (int i=0; i<3; i++)
{
if (*param[i] > 1)
*param[i] = 1;
if (*param[i] < 0)
*param[i] = 0;
}
r = red;
g = green;
b = blue;
}
Color::Color(int red, int green, int blue)
{
Color((double) red / 256.0, (double) green / 256.0, (double) green / 256.0);
}
Color::Color(int color)
{
switch (color)
{
case WHITE:
Color(1.0, 1.0, 1.0);
break;
case BLACK:
Color(0.0, 0.0, 0.0);
break;
case RED:
Color(1.0, 0.0, 0.0);
break;
case GREEN:
Color(0.0, 1.0, 0.0);
break;
case BLUE:
Color(0.0, 0.0, 1.0);
break;
default:
Color();
break;
}
}
Color::Color()
{
Color(0.0, 0.0, 0.0);
}
float *Color::toArray() const
{
float *result;
result = new float[4];
result[0] = (float) r;
result[1] = (float) g;
result[2] = (float) b;
result[3] = 1.0f;
return &result[0];
}