-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorFunctions.pde
75 lines (68 loc) · 2.01 KB
/
ColorFunctions.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
/**Generates a random color for the road (not too dark, not too bright)*/
color RandomWallColor()
{
float min_brightness=255*3*MIN_BRIGHTNESS;
float max_brightness=255*3*MAX_BRIGHTNESS;
int r = int(random(255));
int g = int(random(255));
int b = int(random(255));
float brightness = max(r+g+b,1);
if(r+g+b<min_brightness)
{
r*= min_brightness/brightness;
g*= min_brightness/brightness;
b*= min_brightness/brightness;
}
if(r+g+b>max_brightness)
{
r*= max_brightness/brightness;
g*= max_brightness/brightness;
b*= max_brightness/brightness;
}
return color(r,g,b);
//return color(256,256,256);
}
/**Gets from a color current to a color target with the speed speed*/
color GetNextColor(color current, color target, int speed)
{
if(red(current)>red(target))
{
current = color(max(red(target),red(current)-speed),green(current), blue(current));
}
if(red(current)<red(target))
{
current = color(min(red(target),red(current)+speed),green(current), blue(current));
}
if(blue(current)>blue(target))
{
current = color(red(current),green(current), max(blue(target),blue(current)-speed));
}
if(blue(current)<blue(target))
{
current = color(red(current),green(current), min(blue(target),blue(current)+speed));
}
if(green(current)>green(target))
{
current = color(red(current), max(green(target),green(current)-speed), blue(current));
}
if(green(current)<green(target))
{
current = color(red(current), min(green(target),green(current)+speed), blue(current));
}
return current;
}
/**RGB inversion*/
color RGBtoGBR(color origin)
{
return color(green(origin), blue(origin), red(origin));
}
/**intensify or attenuates a color with a float f*/
color MultiplyColor(color c, float f)
{
return color(red(c)*f, green(c)*f, blue(c)*f);
}
/**Returns the negative color of c*/
color Negative(color c)
{
return color(256-red(c), 256-green(c), 256-blue(c));
}