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