-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTestPatterns.pde
202 lines (163 loc) · 6.05 KB
/
TestPatterns.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* This file has a bunch of example patterns, each illustrating the key
* concepts and tools of the LX framework.
*/
public class HueTestPattern extends LXPattern {
private final BoundedParameter colorChangeSpeed = new BoundedParameter("SPD", 5000, 0, 10000);
private final SinLFO whatColor = new SinLFO(0, 360, colorChangeSpeed);
public HueTestPattern(LX lx) {
super(lx);
addParameter(colorChangeSpeed);
addModulator(whatColor).trigger();
}
public void run(double deltaMs){
for (LXPoint p : model.points) {
float h = whatColor.getValuef();
int s = 100;
int b = 70;
colors[p.index] = LX.hsb(h,s,b);
}
}
}
public class FaceIteratorTest extends LEDomePattern implements LXParameterListener {
private final SawLFO currIndex = new SawLFO(0, ((LEDome)model).faces.size(), ((LEDome)model).faces.size() * 300);
private final BoundedParameter selectedFace = new BoundedParameter("SEL", 0, 0, ((LEDome)model).faces.size() - 1);
public FaceIteratorTest(LX lx) {
super(lx);
addParameter(selectedFace);
addModulator(currIndex).start();
}
public void run(double deltaMs) {
int index = (int) currIndex.getValuef();
int selectedIndex = (int) selectedFace.getValuef();
for(int i = 0; i < model.faces.size(); i++) {
LEDomeFace face = model.faces.get(i);
if(!face.hasLights()) { continue; }
float bv = (i == index || i == selectedIndex) ? 100.0 : 0.0;
for(LXPoint p : face.points) {
colors[p.index] = LX.hsb(120, 90, bv);
}
}
}
public void onParameterChanged(LXParameter parameter) {
if (parameter != this.selectedFace) { return; }
int selectedIndex = (int) selectedFace.getValuef();
LEDomeFace face = model.faces.get(selectedIndex);
if(!face.hasLights()) { return; }
println("Face stats for " + selectedIndex);
println("Center x: " + face.xf());
println("Center y: " + face.yf());
println("Center z: " + face.zf());
for(LXPoint p: face.points) {
println("Point index: " + p.index);
println(" x: " + p.x);
println(" y: " + p.y);
println(" z: " + p.z);
println(" theta: " + p.theta);
println(" azimuth: " + p.azimuth);
}
println();
}
}
class EdgeIteratorTest extends LEDomePattern {
private final SawLFO currIndex = new SawLFO(0, ((LEDome)model).edges.size(), ((LEDome)model).edges.size() * 200);
private final BoundedParameter selectedEdge = new BoundedParameter("SEL", 0, 0, ((LEDome)model).edges.size() - 1);
public EdgeIteratorTest(LX lx) {
super(lx);
addParameter(selectedEdge);
addModulator(currIndex).start();
}
public void run(double deltaMs) {
int index = (int) currIndex.getValuef();
int selectedIndex = (int) selectedEdge.getValuef();
LEDomeEdge edge = this.model.edges.get(index);
LEDomeEdge selectedEdge = this.model.edges.get(selectedIndex);
for(LXPoint p : model.points) {
float bv = (edge.onEdge(p) || selectedEdge.onEdge(p)) ? 100.0 : 0.0;
colors[p.index] = LX.hsb(120, 90, bv);
}
}
}
public class LayerDemoPattern extends LEDomePattern {
private final LEDomeAudioParameterFull colorSpread = new LEDomeAudioParameterFull("Clr", 0.5, 0, 3);
private final BoundedParameter stars = new BoundedParameter("Stars", 100, 0, 100);
public LayerDemoPattern(LX lx) {
super(lx);
colorSpread.setModulationRange(.6);
addParameter(colorSpread);
addParameter(stars);
addLayer(new CircleLayer(lx));
addLayer(new RodLayer(lx));
for (int i = 0; i < 200; ++i) {
addLayer(new StarLayer(lx));
}
}
public void run(double deltaMs) {
// The layers run automatically
}
private class CircleLayer extends LXLayer {
private final SinLFO xPeriod = new SinLFO(3400, 7900, 11000);
private final SinLFO brightnessX = new SinLFO(model.xMin, model.xMax, xPeriod);
private CircleLayer(LX lx) {
super(lx);
addModulator(xPeriod).start();
addModulator(brightnessX).start();
}
public void run(double deltaMs) {
// The layers run automatically
float falloff = 100 / (4*FEET);
for (LXPoint p : model.points) {
float yWave = model.yRange/2 * sin(p.x / model.xRange * PI);
float distanceFromCenter = dist(p.x, p.y, model.cx, model.cy);
float distanceFromBrightness = dist(p.x, abs(p.y - model.cy), brightnessX.getValuef(), yWave);
colors[p.index] = LXColor.hsb(
lx.palette.getHuef() + colorSpread.getValuef() * distanceFromCenter,
100,
max(0, 100 - falloff*distanceFromBrightness)
);
}
}
}
private class RodLayer extends LXLayer {
private final SinLFO zPeriod = new SinLFO(2000, 5000, 9000);
private final SinLFO zPos = new SinLFO(model.zMin, model.zMax, zPeriod);
private RodLayer(LX lx) {
super(lx);
addModulator(zPeriod).start();
addModulator(zPos).start();
}
public void run(double deltaMs) {
for (LXPoint p : model.points) {
float b = 100 - dist(p.x, p.y, model.cx, model.cy) - abs(p.z - zPos.getValuef());
if (b > 0) {
addColor(p.index, LXColor.hsb(
lx.palette.getHuef() + p.azimuth,
100,
b
));
}
}
}
}
private class StarLayer extends LXLayer {
private final TriangleLFO maxBright = new TriangleLFO(0, stars, random(2000, 8000));
private final SinLFO brightness = new SinLFO(-1, maxBright, random(3000, 9000));
private int index = 0;
private StarLayer(LX lx) {
super(lx);
addModulator(maxBright).start();
addModulator(brightness).start();
pickStar();
}
private void pickStar() {
index = (int) random(0, model.size-1);
}
public void run(double deltaMs) {
if (brightness.getValuef() <= 0) {
pickStar();
} else {
addColor(index, LXColor.hsb(lx.palette.getHuef(), 50, brightness.getValuef()));
}
}
}
}