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