-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLightThing.pde
144 lines (122 loc) · 2.98 KB
/
LightThing.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// LightThing
class LightThing
{
float fader;
boolean enabled;
String comment;
color colour;
float hue;
float saturation;
float brightness;
float intensity;
float R, G, B;
// Constructor
LightThing(boolean status, float fader, float hue)
{
this.enabled = status;
this.comment = "";
this.fader = fader;
this.hue = hue;
this.saturation = MAX_SATURATION;
this.brightness = MAX_BRIGHTNESS;
colorMode(HSB, MAX_HUE, MAX_SATURATION, MAX_BRIGHTNESS);
this.colour = color(hue, saturation, brightness);
this.intensity = 0;
calcRGB();
}
void change(float fader, float hue, float saturation, float brightness) {
this.enabled = true;
this.fader = fader;
this.hue = hue;
this.saturation = saturation;
this.brightness = brightness;
this.intensity = brightness;
calcRGB();
}
void calcRGB() {
colorMode(RGB, 255);
R = (this.colour >> 16) & 0xFF;
G = (this.colour >> 8) & 0xFF;
B = this.colour & 0xFF;
}
// fade
void fade(float fader) {
intensity = constrain(intensity * fader, 0, brightness);
}
// beat
void beat(float level) {
if (enabled) {
intensity = brightness * level;
}
}
// getRGB
float[] getRGB() {
float[] rgb = new float[3];
rgb[0] = intensity * R;
rgb[1] = intensity * G;
rgb[2] = intensity * B;
return rgb;
}
// getColor
color getRGBColor() {
colorMode(RGB, 255);
return color(intensity * R, intensity * B, intensity * B);
}
color getHSBColor() {
colorMode(HSB, MAX_HUE, MAX_SATURATION, MAX_BRIGHTNESS);
return color(hue, saturation, intensity * brightness);
}
// Get original color
color getOrigColor() {
colorMode(RGB, 255);
return color(R, G, B);
}
// flip
void flip() {
enabled = !enabled;
}
}
// BeatThing
class BeatThing extends LightThing
{
char type;
// Constructor
BeatThing(char type, float fader, float hue) {
super(true, fader, hue);
this.type = type;
}
void beat(float level, float scaledFader) {
switch(type) {
case 'k':
if (bd.isKick()) super.beat(level); else super.fade(scaledFader);
break;
case 's':
if (bd.isSnare()) super.beat(level); else super.fade(scaledFader);
break;
case 'h':
if (bd.isHat()) super.beat(level); else super.fade(scaledFader);
break;
}
}
}
// EffectThing
//class EffectThing extends LightThing
//{
// // Constructor
// EffectThing(float hue, float saturation, float brightness) {
// enabled = status;
// this.fader = EFFECT_FADER;
// this.hue = hue;
// this.saturation = saturation;
// this.brightness = MAX_BRIGHTNE;
//
// intensity = brightness;
//
// colorMode(HSB, MAX_HUE, MAX_SATURATION, MAX_BRIGHTNESS);
// colour = color(hue, saturation, brightness);
// colorMode(RGB, 255);
// R = (colour >> 16) & 0xFF;
// G = (colour >> 8) & 0xFF;
// B = colour & 0xFF;
// }
//}