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