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