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