-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.h
66 lines (59 loc) · 1.12 KB
/
Color.h
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
#ifndef COLOR_H
#define COLOR_H
#include "Constants.h"
struct HSB3f {
float h, s, b;
HSB3f(float h, float s, float b) : h(h), s(s), b(b) {}
};
struct RGB3f {
float r, g, b;
RGB3f() {r = g = b = 1.0f;}
RGB3f(float r, float g, float b) : r(r), g(g), b(b) {}
RGB3f(HSB3f hsb) {
float H = hsb.h / 60.0f, S = hsb.s, B = hsb.b;
if(S == 0.0f) {
*this = RGB3f(B, B, B);
return;
}
float Hi = floor(H);
float f = H - Hi;
float p = B * (1 - S);
float q = B * (1 - f * S);
float t = B * (1 - (1 - f) * S);
float v = B;
switch ((int)Hi) {
case 0:
*this = RGB3f(v, t, p);
break;
case 1:
*this = RGB3f(q, v, p);
break;
case 2:
*this = RGB3f(p, v, t);
break;
case 3:
*this = RGB3f(p, q, v);
break;
case 4:
*this = RGB3f(t, p, v);
break;
default:
*this = RGB3f(v, p, q);
}
}
static RGB3f RandomBrightColor() {
return HSB3f(randf() * 360.0f, 0.8f, 0.8f);
}
operator float *() {
return (float *)this;
}
};
class Colors {
public:
static RGB3f White;
static RGB3f Black;
static RGB3f RandomBrightColor() {
return HSB3f(randf() * 360.0f, 0.8f, 0.8f);
}
};
#endif