-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathColorTracker.pde
96 lines (81 loc) · 2.56 KB
/
ColorTracker.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
86
87
88
89
90
91
92
93
94
95
96
public class ColorTracker {
float deltaMax;
float deltaMin;
float red, green, blue;
boolean incrRed, incrGreen, incrBlue;
float dr, dg, db;
ColorTracker(float redStart, float greenStart, float blueStart, float deltaMin, float deltaMax) {
this.deltaMin = deltaMin;
this.deltaMax = deltaMax;
incrRed = true;
incrBlue = false;
incrGreen = false;
red = redStart;
green = greenStart;
blue = blueStart;
pickRandomDeltas();
}
ColorTracker(float deltaMin, float deltaMax) {
this(random(125, 255), random(0, 125), random(67, 200), deltaMin, deltaMax);
}
void pickRandomDeltas() {
dr = random(deltaMin, deltaMax);
dg = random(deltaMin, deltaMax);
db = random(deltaMin, deltaMax);
}
//call each frame to slowly change colors over time
void incrementColor() {
if (red + blue + green < 255) {
incrRed = true;
incrBlue = true;
incrGreen = true;
pickRandomDeltas();
} else if (red + blue + green > (255 * 2)) {
incrRed = false;
incrBlue = false;
incrGreen = false;
pickRandomDeltas();
}
if (red > 255) {
incrRed = false;
dr = random(deltaMin, deltaMax);
}
if (blue > 255) {
incrBlue = false;
db = random(deltaMin, deltaMax);
}
if (green > 255) {
incrGreen = false;
dg = random(deltaMin, deltaMax);
}
if (red < 0) incrRed = true;
if (blue < 0) incrBlue = true;
if (green < 0) incrGreen = true;
if (incrRed) red += dr;
else red -= dr;
if (incrBlue) blue += db;
else blue -= db;
if (incrGreen) green += dg;
else green -= dg;
}
void pickRandomColor() {
red = random(0, 255);
green = random(0, 255);
blue = random(0, 255);
}
void defineLights() {
lightSpecular(red / 15, red / 15, red / 15);
directionalLight(0, green / 8, blue / 4,
1, 0, 0);
pointLight(min(red*2, 255), green / 4, blue / 4,
200, -150, 0);
pointLight(0, 0, blue,
0, 150, 200);
spotLight(255 - red, 255 - (green / 4), 255 - (blue / 4),
0, 40, 200,
0, -0.5, -0.5,
PI/2, 1);
directionalLight(0, 0, 0,
-1, 0, 0);
}
}