-
Notifications
You must be signed in to change notification settings - Fork 4
/
ColorGL.pde
86 lines (75 loc) · 1.96 KB
/
ColorGL.pde
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
/*
MidiBalls: A 3d music visualization that uses midi as input
Copyright (C) 2010 Maxime Beauchemin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//Simple class to store colors in OpenGL compatible format
//Processing stores color in an int where 2bytes are used for R, G, B, A
//OpenGL needs float values between 0-1
//This class stores in OpenGL format, removing the need for conversions, thus optimising
class ColorGL
{
float r,g,b;
ColorGL()
{
r=g=b=0;
}
ColorGL(color c)
{
SetColor(c);
}
ColorGL(ColorGL inCgl)
{
r=inCgl.r;
g=inCgl.g;
b=inCgl.b;
}
ColorGL(float inR, float inG, float inB)
{
SetColor(inR, inG, inB);
}
void SetColor(color c)
{
int currR = (c >> 16) & 0xFF; // Like red(), but faster
int currG = (c >> 8) & 0xFF;
int currB = c & 0xFF;
r=(float)currR/255;
g=(float)currG/255;
b=(float)currB/255;
}
void SetColor(float inR, float inG, float inB)
{
r=inR;
g=inG;
b=inB;
}
ColorGL Clone()
{
ColorGL tmp = new ColorGL(r, g, b);
return tmp;
}
void Randomize(float range)
{
r += (random(range)) - range/2;
g += (random(range)) - range/2;
b += (random(range)) - range/2;
FixRange(r);
FixRange(g);
FixRange(b);
}
float FixRange(float a)
{
if (a>1)a=1;
else if (a<0)a=1;
return a;
}
};