Send normalized values back to APC40
[SugarCubes.git] / BenMorrow.pde
CommitLineData
6a4882dd
BM
1class XYZPixel extends SCPattern
2{
3 float xm = model.xMin;
4 float ym = model.yMin;
5 float zm = model.zMin;
6
7 float cubeWidth = 35;
8 float xm2 = model.xMin+cubeWidth;
9 float ym2 = model.yMin+cubeWidth;
10 float zm2 = model.zMin+cubeWidth;
11
12 XYZPixel(GLucose glucose) {
13 super(glucose);
14 //myP = new LXPoint(20,20,20);
15 }
16
17 void run(double deltaMs)
18 {
19 for(LXPoint p : model.points)
20 {
21 if(p.x > xm && p.x<= xm2 && p.y > ym && p.y<= xm2 && p.z<= zm2 && p.z > zm)
22 {
23 colors[p.index] = lx.hsb(lx.getBaseHue()+100, 100, 100);
24
25 }else{
26 colors[p.index] = 0;
27 }
28 }
29 float minIS=min(model.xMax,model.yMax,model.zMax);
30 xm = (xm + 1 ) % minIS;
31 ym = (ym + 1 ) % minIS;
32 zm = (zm + 1 ) % minIS;
33
34 xm2 = xm + cubeWidth;
35 ym2 = ym2 + cubeWidth;
36 zm2 = zm2 + cubeWidth;
37 }
38}
39
40class MultipleCubes extends SCPattern
41{
42 float xm = model.xMin;
43 float ym = model.yMin+10;
44 float zm = model.zMin+5;
45
46 float xma = model.xMin;
47 float xmb = model.xMin;
48
49 float cubeWidth = 35;
50
51 float minIS;
52
53 MultipleCubes(GLucose glucose) {
54 super(glucose);
55 minIS = 200;
56 }
57
58 void drawVirtualCube(float bottomX, float bottomY, float bottomZ, float side, int cubeColor)
59 {
60 for(LXPoint p : model.points)
61 {
62 if(p.x > bottomX && p.x<= bottomX+side && p.y > bottomY && p.y<= bottomY + side && p.z > bottomZ && p.z<= bottomZ+side)
63 {
64 colors[p.index] = cubeColor;
65 }
66 }
67 }
68
69 void clear()
70 {
71 for(int i=0;i<colors.length;i++)
72 {
73 colors[i]=0;
74 }
75 }
76 float side = 29.0;
77 int col;
78 int hueDo;
79 void run(double deltaMs)
80 {
81 boolean up = false;
82 clear();
83 for(int i = 0;i < model.yMax / side; i++)
84 {
85 //println(Math.abs(minIS - xm - 30*(i % 3) - xm + 30*(i % 3)));
86 if(i % 2 ==0)
87 {
88 xm = xma;
89 }else{
90 xm = xmb;
91 }
92 if(Math.abs(minIS - xm - 30*(i % 3) - xm + 30*(i % 3)) < side * 1.5)
93 {
94 hueDo = (hueDo+1) % 255;
95 up = true;
96 }
97 col = lx.hsb(lx.getBaseHue() + hueDo,100,100);
98 drawVirtualCube(minIS-xm- 30*(i % 3), ym+i*side, zm, side, col);
99 drawVirtualCube(xm + 30*(i % 3), ym+i*side, zm, side, col);
100 }
101
102 xma = (xma + 7 ) % minIS;
103 xmb = (xmb + 3) % minIS;
104 //ym = (ym + 1 ) % minIS;
105 //zm = (zm + 1 ) % minIS;
106 }
107}
108
467c8c60
BM
109class TowerParams extends SCPattern
110{
130802e3
BM
111 BasicParameter hueoff = new BasicParameter("Hueoff", 0.0);
112 BasicParameter hueSpan = new BasicParameter("HueRange", 0.0);
467c8c60
BM
113 BasicParameter t1 = new BasicParameter("T1", 0.0);
114 BasicParameter t2 = new BasicParameter("T2", 0.0);
115 BasicParameter t3 = new BasicParameter("T3", 0.0);
116 BasicParameter t4 = new BasicParameter("T4", 0.0);
117 BasicParameter t5 = new BasicParameter("T5", 0.0);
118 BasicParameter t6 = new BasicParameter("T6", 0.0);
119 BasicParameter t7 = new BasicParameter("T7", 0.0);
120 BasicParameter t8 = new BasicParameter("T8", 0.0);
121 BasicParameter t9 = new BasicParameter("T9", 0.0);
122 BasicParameter t10 = new BasicParameter("T10", 0.0);
123 BasicParameter t11 = new BasicParameter("T11", 0.0);
124 BasicParameter t12 = new BasicParameter("T12", 0.0);
125 BasicParameter t13 = new BasicParameter("T13", 0.0);
126 BasicParameter t14 = new BasicParameter("T14", 0.0);
127 BasicParameter t15 = new BasicParameter("T15", 0.0);
128 BasicParameter t16 = new BasicParameter("T16", 0.0);
129
130 ArrayList<BasicParameter> towerParams;
131 int towerSize;
c6ba29cf 132 int colorSpan;
467c8c60
BM
133 TowerParams(GLucose glucose) {
134 super(glucose);
135
136 towerParams = new ArrayList<BasicParameter>();
130802e3
BM
137 addParameter(hueoff);
138 addParameter(hueSpan);
467c8c60
BM
139 towerParams.add(t1);
140 towerParams.add(t2);
141 towerParams.add(t3);
142 towerParams.add(t4);
143 towerParams.add(t5);
144 towerParams.add(t6);
145 towerParams.add(t7);
146 towerParams.add(t8);
147 towerParams.add(t9);
148 towerParams.add(t10);
149 towerParams.add(t11);
150 towerParams.add(t12);
151 towerParams.add(t13);
152 towerParams.add(t14);
153 towerParams.add(t15);
154 towerParams.add(t16);
155 for(BasicParameter p : towerParams)
156 {
157 addParameter(p);
158 }
159 towerSize = model.towers.size();
c6ba29cf 160 colorSpan = 255 / towerSize;
467c8c60
BM
161 }
162
34327c96 163 void run(double deltaMs)
467c8c60
BM
164 {
165 clearALL();
166 Tower t;
167 for(int i=0; i<towerSize ;i++)
168 {
169 t= model.towers.get(i);
2bb56822 170 for(LXPoint p : t.points)
467c8c60
BM
171 {
172 if(p.y<towerParams.get(i).getValuef()*200)
173 {
a41f334c 174 colors[p.index]=lx.hsb(255 * hueoff.getValuef()+colorSpan * hueSpan.getValuef() * i, 255, 255);
467c8c60
BM
175 }
176 }
177 }
178
179 }
180
181 public void clearALL()
182 {
2bb56822 183 for(LXPoint p : model.points)
467c8c60
BM
184 {
185 colors[p.index] = 0;
186 }
187 }
188
189}
a68abe8c
BM
190class Sandbox extends SCPattern
191{
fe0cb084
BM
192 int c=0;
193 int prevC=0;
194 int huerange=255;
195 int pointrange= model.points.size();
196 int striprange= model.strips.size();
197 int facerange= model.faces.size();
198 int cuberange = model.cubes.size();
199 int towerrange = model.towers.size();
200 int counter=0;
a68abe8c 201
47011215 202 Sandbox(GLucose glucose) {
a68abe8c 203 super(glucose);
fe0cb084
BM
204 println("points "+pointrange);
205 println("strips "+striprange);
206 println("faces "+facerange);
207 println("cubes "+cuberange);
208 println("towers "+towerrange);
a68abe8c 209 }
fe0cb084 210
34327c96 211 public void run(double deltaMs) {
fe0cb084
BM
212
213
214 if(counter % 10 ==0)
a68abe8c 215 {
fe0cb084
BM
216 doDraw(c,0);
217 c = (c + 1) % towerrange;
a41f334c 218 long col = lx.hsb(Math.round(Math.random()*255),255,255) ;
fe0cb084 219 doDraw(c,col);
a68abe8c
BM
220 }
221 counter++;
fe0cb084
BM
222
223 }
224
225 public void doDraw(int c,long col)
226 {
227 Tower t= model.towers.get((int) c);
2bb56822 228 for(LXPoint p : t.points)
fe0cb084
BM
229 {
230 colors[p.index] = (int) col;
231 }
a68abe8c 232 }
fe0cb084
BM
233};
234
235class GranimTestPattern extends GranimPattern
236{
237 GranimTestPattern(GLucose glucose)
238 {
239 super(glucose);
3b85aef4
BM
240 addGraphic("myReds",new RedsGraphic(100));
241 int[] dots = {0,128,0,128,0,128,0,128,0,128,0,128};
242 addGraphic("myOtherColors",new ColorDotsGraphic(dots));
243
244 getGraphicByName("myOtherColors").position=100;
27e9754c
BM
245 }
246 int counter=0;
34327c96 247 public void run(double deltaMs)
27e9754c 248 {
3b85aef4 249 clearALL();
27e9754c 250 super.run(deltaMs);
3b85aef4 251
27e9754c
BM
252 if(counter % 3 ==0)
253 {
3b85aef4
BM
254 Graphic reds = getGraphicByName("myReds");
255 Graphic others = getGraphicByName("myOtherColors");
256 reds.position = reds.position + 1 % 19000;
257 others.position = others.position + 10 % 19000;
258 }
259 }
260 public void clearALL()
261 {
cd059b79 262 for(int i = 0; i < colors.length; i++)
3b85aef4 263 {
cd059b79 264 colors[i] = 0;
3b85aef4
BM
265 }
266 }
267
268
269}
270
271class GranimTestPattern2 extends GranimPattern
272{
273 GranimTestPattern2(GLucose glucose)
274 {
275 super(glucose);
276 /*for(int i = 0;i < 100; i++)
277 {
278 Graphic g = addGraphic("myReds_"+i,new RedsGraphic(Math.round(Math.random() * 100)));
279
280 }*/
281 Graphic g = addGraphic("myRandoms",new RandomsGranim(50));
282 g.position = 200;
283
284 }
285 int counter=0;
286 float count=0;
34327c96 287 public void run(double deltaMs)
3b85aef4
BM
288 {
289 clearALL();
290 super.run(deltaMs);
291 Graphic randomsGraphic = getGraphicByName("myRandoms");
292 randomsGraphic.position = Math.round(sin(count)*1000)+5000;
cd059b79 293 count+= 0.005;
3b85aef4
BM
294 }
295 public void clearALL()
296 {
2bb56822 297 for(LXPoint p : model.points)
3b85aef4
BM
298 {
299 colors[p.index] = 0;
27e9754c 300 }
fe0cb084
BM
301 }
302
303
a1d396e5
BM
304};
305
306class DriveableCrossSections extends CrossSections
307{
e1635ff6
BM
308 BasicParameter xd;
309 BasicParameter yd;
310 BasicParameter zd;
311 BasicParameter mode;
a1d396e5
BM
312
313 DriveableCrossSections(GLucose glucose) {
314 super(glucose);
315 }
316
317 public void addParams()
318 {
e1635ff6
BM
319 mode = new BasicParameter("Mode", 0.0);
320 xd = new BasicParameter("XD", 0.0);
321 yd = new BasicParameter("YD", 0.0);
322 zd = new BasicParameter("ZD", 0.0);
323 addParameter(mode);
a1d396e5
BM
324 addParameter(xd);
325 addParameter(yd);
326 addParameter(zd);
1692ded2
BM
327
328 super.addParams();
a1d396e5
BM
329 }
330
e1635ff6
BM
331 public void onParameterChanged(LXParameter p) {
332 if(p == mode)
333 {
334 if(interactive())
335 {
efa0f27b
BM
336 copyValuesToKnobs();
337 }else{
338 copyKnobsToValues();
e1635ff6
BM
339 }
340 }
341 }
a1d396e5 342
efa0f27b
BM
343 void copyValuesToKnobs()
344 {
345 xd.setValue(x.getValue()/200);
346 yd.setValue(y.getValue()/115);
347 zd.setValue(z.getValue()/100);
348 }
349
350 void copyKnobsToValues()
351 {
352 x.setValue(xd.getValue()*200);
353 y.setValue(yd.getValue()*115);
354 z.setValue(zd.getValue()*100);
355 }
356
e1635ff6
BM
357 boolean interactive()
358 {
359 return Math.round(mode.getValuef())>0.5;
360 }
a1d396e5
BM
361
362 public void updateXYZVals()
363 {
e1635ff6
BM
364 if(interactive())
365 {
366 xv = xd.getValuef()*200;
efa0f27b 367 yv = yd.getValuef()*115;
e1635ff6
BM
368 zv = zd.getValuef()*100;
369 }else{
370 super.updateXYZVals();
efa0f27b 371 copyValuesToKnobs();
e1635ff6 372 }
a1d396e5
BM
373 }
374
e28f168c 375}