merged slee's lx changes
[SugarCubes.git] / AlexGreen.pde
1 class SineSphere extends SCPattern {
2 private SawLFO yrot = new SawLFO(0, TWO_PI, 3000);
3 private SawLFO yrot2 = new SawLFO(0, -TWO_PI, 8000);
4 public BasicParameter huespread = new BasicParameter("Hue", 0, 180);
5 public BasicParameter widthparameter= new BasicParameter("Width", .2);
6 private int pitch = 0;
7 private int channel = 0;
8 private int velocity = 0;
9 public final LXProjection sinespin;
10 public final LXProjection sinespin2;
11 float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax));
12 Pick Sshape;
13
14 //to-do: how to sync all hues across sphery's via one basicparameter
15 //public BasicParameter huespread = new BasicParameter("HueSpread", 180, 360);
16 public BasicParameter rotationx = new BasicParameter("rotx", 0, 0, 1 );
17 public BasicParameter rotationy = new BasicParameter("roty", 1, 0, 1);
18 public BasicParameter rotationz = new BasicParameter("rotz", 0, 0, 1);
19
20 public final PVector P = new PVector();
21
22 class Sphery {
23 float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci
24 private SinLFO vibration;
25 private SinLFO surface;
26 private SinLFO vx;
27 private SinLFO xbounce;
28 public SinLFO ybounce;
29 private SinLFO zbounce;
30 float vibration_min, vibration_max, vperiod;
31
32 //public BasicParameter huespread;
33 public BasicParameter bouncerate;
34 public BasicParameter bounceamp;
35 public BasicParameter vibrationrate;
36 public final PVector circlecenter = new PVector();
37
38 public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_min, float vibration_max, float vperiod)
39 {
40 this.f1xcenter = f1xcenter;
41 this.f1ycenter = f1ycenter;
42 this.f1zcenter = f1zcenter;
43 this.vibration_min = vibration_min;
44 this.vibration_max = vibration_max;
45 this.vperiod = vperiod;
46 //addParameter(bounceamp = new BasicParameter("Amp", .5));
47 //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate);
48 //addParameter(vibrationrate = new BasicParameter("vibration", 1000, 10000));
49 //addParameter(widthparameter = new BasicParameter("Width", .2));
50
51
52 addModulator( vx = new SinLFO(500, 10000, 100000)).trigger() ;
53 //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
54 addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000./lx.tempo.bpm())).trigger(); //bounce.modulateDurationBy
55
56 //addModulator(bounceamp); //ybounce.setMagnitude(bouncerate);
57 addModulator( vibration = new SinLFO(vibration_min , vibration_max, 10000)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm());
58
59 }
60
61 //for an ellipse
62 // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float f2xcenter, float f2ycenter, float f2zcenter,
63 // float vibration_min, float vibration_max, float vperiod)
64
65 // {
66 // this.f1xcenter = f1xcenter;
67 // this.f1ycenter = f1ycenter;
68 // this.f1zcenter = f1zcenter;
69 // this.f2xcenter = f2xcenter;
70 // this.f2ycenter = f2ycenter;
71 // this.f2zcenter = f2zcenter;
72 // this.vibration_min = vibration_min;
73 // this.vibration_max = vibration_max;
74 // this.vperiod = vperiod;
75 // //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
76 // addModulator(ybounce).trigger();
77 // addModulator( vibration = new SinLFO(vibration_min , vibration_max, lx.tempo.rampf())).trigger(); //vibration.modulateDurationBy(vx);
78 // addParameter(widthparameter = new BasicParameter("Width", .1));
79 // //addParameter(huespread = new BasicParameter("bonk", .2));
80
81 // }
82
83
84
85 void setVibrationPeriod(double period){
86 // to-do: make this conditional upon time signature
87
88 vibration.setPeriod(period);
89
90 }
91
92
93 float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z)
94 {
95 return dist(px, py, pz, f1x, f1y, f1z);
96 }
97 //void updatespherey(deltaMs, )
98
99 float quadrant(PVector q) {
100 float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) );
101
102
103 return map(qtheta, -PI/2, PI/2, 160-huespread.getValuef(), 240 +huespread.getValuef());
104 //if (q.x > f1xcenter ) {return 140 ;}
105 //else {return 250;}
106 }
107 color spheryvalue (PVector p, float f1xcenter, float f1ycenter, float f1zcenter) {
108 circlecenter.set(f1xcenter, f1ycenter, f1zcenter);
109
110
111 //switch(sShpape.cur() ) {}
112
113 float b = max(0, 100 - 100*widthparameter.getValuef()*abs(p.dist(circlecenter)
114 - vibration.getValuef() ) );
115
116 if (b <= 0) {
117 return 0;
118 }
119
120 return lx.hsb(
121 constrain(quadrant(p), 0, 360),
122 80,
123 b
124 );
125 }
126 color ellipsevalue(float px, float py, float pz , float f1xc, float f1yc, float f1zc, float f2xc, float f2yc, float f2zc)
127 {
128 //switch(sShpape.cur() ) {}
129 return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) ,
130 max(0, 100 - 100*widthparameter.getValuef() *
131 abs( (dist(px, py, pz, f1xc, ybounce.getValuef(), f1zc) +
132 (dist(px, py , pz, f2xc, ybounce.getValuef(), f2zc) ) )/2
133 - 1.2*vibration.getValuef() ) ) ) ;
134 }
135
136 void run(double deltaMs) {
137 float vv = vibration.getValuef();
138 float ybv = ybounce.getValuef();
139
140 }
141
142 }
143
144 // public boolean gridPressed(int row, int co){
145 // midiengine.grid.setState();
146
147 // return true;
148
149 // }
150
151 public boolean noteOn(Note note) {
152 pitch= note.getPitch();
153 velocity=note.getVelocity();
154 channel=note.getChannel();
155 return true;
156 }
157
158 final Sphery[] spherys;
159
160 SineSphere(GLucose glucose)
161 {
162 super(glucose);
163 sinespin = new LXProjection(model);
164 sinespin2 = new LXProjection(model);
165 addParameter(huespread);
166 addParameter(rotationx);
167 addParameter(rotationy);
168 addParameter(rotationz);
169 addModulator(yrot).trigger();
170 addModulator(yrot2).trigger();
171
172 //addParameter(huespread);
173 //Sshape = addPick("Shape", , 1);
174 spherys = new Sphery[] {
175 new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/16, modelrad/8, 3000),
176 new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000),
177 new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300),
178
179 new Sphery(.3*model.xMax, .4*model.yMax, .6*model.zMax, modelrad/16, modelrad/8, 4000),
180 new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000),
181 new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300),
182
183 };
184 }
185
186 // public void onParameterChanged(LXParameter parameter)
187 // {
188
189
190 // for (Sphery s : spherys) {
191 // if (s == null) continue;
192 // double bampv = s.bounceamp.getValue();
193 // double brv = s.bouncerate.getValue();
194 // double tempobounce = lx.tempo.bpm();
195 // if (parameter == s.bounceamp)
196 // {
197 // s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv);
198 // }
199 // else if ( parameter == s.bouncerate )
200 // {
201 // s.ybounce.setDuration(120000./tempobounce);
202 // }
203 // }
204 // }
205
206 public void run( double deltaMs) {
207 double t = lx.tempo.ramp();
208 double bpm = lx.tempo.bpm();
209 //spherys[0].run(deltaMs);
210 //spherys[1].run(deltaMs);
211 //spherys[2].run(deltaMs);
212 //spherys[3].run(deltaMs);]
213 sinespin.reset()
214 .center()
215 // .scale(1.3,1.3,1.3)
216 // Rotate around the origin (now the center of the car) about an y-vector
217 .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
218 .translate(model.cx, model.cy, model.cz);
219 switch (pitch)
220 {
221 case 53: t = .5*t; bpm = .5*bpm; break;
222
223 case 54: t = t; bpm = bpm; break;
224
225 case 55: t = 2*t; bpm = 2*bpm; break;
226
227 default: t= t; bpm = bpm;
228 }
229
230
231
232 for ( Sphery s: spherys){
233 s.setVibrationPeriod(480000/bpm);
234 s.vibration.setBasis(t);
235 }
236 sinespin.reset()
237
238
239 // Translate so the center of the car is the origin, offset
240 .center()
241 // .scale(1.3,1.3,1.3)
242 // Rotate around the origin (now the center of the car) about an y-vector
243 .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
244 .translate(model.cx, model.cy, model.cz);
245
246
247
248
249
250 for (LXVector p: sinespin)
251 // for (Point p: model.points)
252 {
253 P.set(p.x, p.y, p.z);
254 // PVector P = new PVector(p.x, p.y, p.z);
255 color c = #000000;
256 c = blendIfColor(c, spherys[1].spheryvalue(P, .75*model.xMax, model.yMax/2, model.zMax/2), ADD);
257 c = blendIfColor(c, spherys[0].spheryvalue(P, model.xMax/4, model.yMax/4, model.zMax/2), ADD);
258 c = blendIfColor(c, spherys[2].spheryvalue(P, model.xMax/2, model.yMax/2, model.zMax/2),ADD);
259
260
261 colors[p.index] = c;
262
263
264 }
265 sinespin2.reset()
266 .center()
267 .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
268 .translate(model.cx,model.cy,model.cz);
269
270 for (LXVector p: sinespin2)
271 { color c = 0;
272 // PVector P = new PVector(p.x, p.y, p.z);
273 P.set(p.x, p.y, p.z);
274 c = blendIfColor(c, spherys[3].spheryvalue(P, .3*model.xMax, .7*model.yMax, .6*model.zMax),ADD);
275
276 colors[p.index] = blendIfColor(colors[p.index], c , ADD);
277
278 }
279
280 }
281
282 color blendIfColor(color c1, color c2, int mode) {
283 if (c2 != 0) {
284 return blendColor(c1, c2, mode);
285 }
286 return c1;
287 }
288
289
290 // color c = 0;
291 // c = blendColor(c, spherys[3].ellipsevalue(Px.x, Px.y, Px.z, model.xMax/4, model.yMax/4, model.zMax/4, 3*model.xMax/4, 3*model.yMax/4, 3*model.zMax/4),ADD);
292 // return c;
293 // }
294 // return lx.hsb(0,0,0);
295 // // else if(spheremode ==2)
296 // { color c = 0;
297 // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) );
298
299 // }
300
301
302 // }
303
304 }
305
306 class CubeCurl extends SCPattern{
307 float CH, CW, diag;
308 ArrayList<PVector> cubeorigin = new ArrayList<PVector>();
309 ArrayList<PVector> centerlist = new ArrayList<PVector>();
310 private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 );
311
312 private SinLFO bg = new SinLFO(180, 220, 3000);
313
314 CubeCurl(GLucose glucose){
315 super(glucose);
316 addModulator(curl).trigger();
317 addModulator(bg).trigger();
318 this.CH = Cube.EDGE_HEIGHT;
319 this.CW = Cube.EDGE_WIDTH;
320 this.diag = sqrt(CW*CW + CW*CW);
321
322
323 ArrayList<PVector> centerlistrelative = new ArrayList<PVector>();
324 for (int i = 0; i < model.cubes.size(); i++){
325 Cube a = model.cubes.get(i);
326 cubeorigin.add(new PVector(a.x, a.y, a.z));
327 centerlist.add(new PVector(a.cx, a.cy, a.cz) );
328
329 }
330
331 }
332 //there is definitely a better way of doing this!
333 PVector centerofcube(int i) {
334 Cube c = model.cubes.get(i);
335
336 println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z );
337 // PVector cubeangle = new PVector(c.rx, c.ry, c.rz);
338 println("raw x angle: " + c.rx + "raw y angle: " + c.ry + "raw z angle: " + c.rz);
339 PVector cubecenter = new PVector(c.x + CW/2, c.y + CH/2, c.z + CW/2);
340 println("cubecenter unrotated: " + cubecenter.x + " " +cubecenter.y + " " +cubecenter.z );
341 PVector centerrot = new PVector(cos(c.rx)*CW/2 - sin(c.rx)*CW/2, cubecenter.y, cos(c.rz)*CW/2 + sin(c.rz)*CW/2);
342 // nCos*(y-o.y) - nSin*(z-o.z) + o.y
343 cubecenter = PVector.add(new PVector(c.x, c.y, c.z), centerrot);
344 println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " ");
345
346
347 return cubecenter;
348 }
349
350
351 void run(double deltaMs){
352 for (int i =0; i < model.cubes.size(); i++) {
353 Cube c = model.cubes.get(i);
354 float cfloor = c.y;
355
356 // if (i%3 == 0){
357
358 // for (LXPoint p : c.points ){
359 // // colors[p.index]=color(0,0,0);
360 // //float dif = (p.y - c.y);
361 // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD);
362 // }
363 // }
364
365 // else if (i%3 == 1) {
366
367 // for (LXPoint p: c.points){
368 // colors[p.index]=color(0,0,0);
369 // float dif = (p.y - c.y);
370 // // colors[p.index] =
371 // // color(bg.getValuef(),
372 // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100),
373 // // 100 - 10*abs(dif - curl.getValuef()), ADD );
374 // }
375 // }
376 // else if (i%3 == 2){
377 // centerlist[i].sub(cubeorigin(i);
378 for (LXPoint p: c.points) {
379 PVector pv = new PVector(p.x, p.y, p.z);
380 colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 );
381 // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), );
382
383
384 }
385
386
387 //}
388
389 }
390 }
391 }
392
393 class HueTestHSB extends SCPattern{
394 BasicParameter HueT = new BasicParameter("Hue", .5);
395 BasicParameter SatT = new BasicParameter("Sat", .5);
396 BasicParameter BriT = new BasicParameter("Bright", .5);
397
398 HueTestHSB(GLucose glucose) {
399 super(glucose);
400 addParameter(HueT);
401 addParameter(SatT);
402 addParameter(BriT);
403 }
404 void run(double deltaMs){
405
406 for (LXPoint p : model.points) {
407 color c = 0;
408 c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD);
409 colors[p.index]= c;
410 }
411 int now= millis();
412 if (now % 1000 <= 20)
413 {
414 println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef());
415 }
416 }
417
418 }