1 class SineSphere extends SCPattern {
2 private SawLFO yrot = new SawLFO(0, TWO_PI, 3000);
3 private SawLFO yrot2 = new SawLFO(0, -TWO_PI, 8000);
4 public BasicParameter huespread = new BasicParameter("Hue", 0, 180);
5 public BasicParameter widthparameter= new BasicParameter("Width", .2);
7 private int channel = 0;
8 private int velocity = 0;
10 public final LXProjection sinespin;
11 public final LXProjection sinespin2;
12 float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax));
15 //to-do: how to sync all hues across sphery's via one basicparameter
16 //public BasicParameter huespread = new BasicParameter("HueSpread", 180, 360);
17 public BasicParameter rotationx = new BasicParameter("rotx", 0, 0, 1 );
18 public BasicParameter rotationy = new BasicParameter("roty", 1, 0, 1);
19 public BasicParameter rotationz = new BasicParameter("rotz", 0, 0, 1);
21 public final PVector P = new PVector();
24 float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci
25 private SinLFO vibration;
26 private SinLFO surface;
28 private SinLFO xbounce;
29 public SinLFO ybounce;
30 private SinLFO zbounce;
31 float vibration_min, vibration_max, vperiod;
33 //public BasicParameter huespread;
34 public BasicParameter bouncerate;
35 public BasicParameter bounceamp;
36 public BasicParameter vibrationrate;
37 public final PVector circlecenter = new PVector();
39 public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_min, float vibration_max, float vperiod)
41 this.f1xcenter = f1xcenter;
42 this.f1ycenter = f1ycenter;
43 this.f1zcenter = f1zcenter;
44 this.vibration_min = vibration_min;
45 this.vibration_max = vibration_max;
46 this.vperiod = vperiod;
47 //addParameter(bounceamp = new BasicParameter("Amp", .5));
48 //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate);
49 //addParameter(vibrationrate = new BasicParameter("vibration", 1000, 10000));
50 //addParameter(widthparameter = new BasicParameter("Width", .2));
53 addModulator( vx = new SinLFO(500, 10000, 100000)).trigger() ;
54 //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
55 addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000)).trigger(); //bounce.modulateDurationBy
57 //addModulator(bounceamp); //ybounce.setMagnitude(bouncerate);
58 addModulator( vibration = new SinLFO(vibration_min , vibration_max, 10000)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm());
63 // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float f2xcenter, float f2ycenter, float f2zcenter,
64 // float vibration_min, float vibration_max, float vperiod)
67 // this.f1xcenter = f1xcenter;
68 // this.f1ycenter = f1ycenter;
69 // this.f1zcenter = f1zcenter;
70 // this.f2xcenter = f2xcenter;
71 // this.f2ycenter = f2ycenter;
72 // this.f2zcenter = f2zcenter;
73 // this.vibration_min = vibration_min;
74 // this.vibration_max = vibration_max;
75 // this.vperiod = vperiod;
76 // //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
77 // addModulator(ybounce).trigger();
78 // addModulator( vibration = new SinLFO(vibration_min , vibration_max, lx.tempo.rampf())).trigger(); //vibration.modulateDurationBy(vx);
79 // addParameter(widthparameter = new BasicParameter("Width", .1));
80 // //addParameter(huespread = new BasicParameter("bonk", .2));
86 void setVibrationPeriod(double period){
87 // to-do: make this conditional upon time signature
89 vibration.setPeriod(period);
94 float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z)
96 return dist(px, py, pz, f1x, f1y, f1z);
98 //void updatespherey(deltaMs, )
100 float quadrant(PVector q) {
101 float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) );
104 return map(qtheta, -PI/2, PI/2, 160-huespread.getValuef(), 240 +huespread.getValuef());
105 //if (q.x > f1xcenter ) {return 140 ;}
108 color spheryvalue (PVector p, float f1xcenter, float f1ycenter, float f1zcenter) {
109 circlecenter.set(f1xcenter, f1ycenter, f1zcenter);
112 //switch(sShpape.cur() ) {}
114 float b = max(0, 100 - 100*widthparameter.getValuef()*abs(p.dist(circlecenter)
115 - vibration.getValuef() ) );
122 constrain(quadrant(p), 0, 360),
127 color ellipsevalue(float px, float py, float pz , float f1xc, float f1yc, float f1zc, float f2xc, float f2yc, float f2zc)
129 //switch(sShpape.cur() ) {}
130 return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) ,
131 max(0, 100 - 100*widthparameter.getValuef() *
132 abs( (dist(px, py, pz, f1xc, ybounce.getValuef(), f1zc) +
133 (dist(px, py , pz, f2xc, ybounce.getValuef(), f2zc) ) )/2
134 - 1.2*vibration.getValuef() ) ) ) ;
137 void run(double deltaMs) {
138 float vv = vibration.getValuef();
139 float ybv = ybounce.getValuef();
145 // public boolean gridPressed(int row, int co){
146 // midiengine.grid.setState();
152 public boolean noteOn(Note note) {
153 pitch= note.getPitch();
154 velocity=note.getVelocity();
155 channel=note.getChannel();
159 public boolean gridPressed(int row, int col) {
160 pitch = row; channel = col;
161 cur = NumApcCols*(pitch-53)+col;
162 //setState(row, col, 0 ? 1 : 0);
167 final Sphery[] spherys;
169 SineSphere(GLucose glucose)
172 sinespin = new LXProjection(model);
173 sinespin2 = new LXProjection(model);
174 addParameter(huespread);
175 addParameter(rotationx);
176 addParameter(rotationy);
177 addParameter(rotationz);
178 addModulator(yrot).trigger();
179 addModulator(yrot2).trigger();
181 //addParameter(huespread);
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),
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),
195 // public void onParameterChanged(LXParameter parameter)
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)
206 // s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv);
208 // else if ( parameter == s.bouncerate )
210 // s.ybounce.setDuration(120000./tempobounce);
215 public void run( double deltaMs) {
216 double t = lx.tempo.ramp();
217 double bpm = lx.tempo.bpm();
221 // .scale(1.3,1.3,1.3)
222 // Rotate around the origin (now the center of the car) about an y-vector
223 .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
224 .translate(model.cx, model.cy, model.cz);
228 case 1: t = .5*t; bpm = .5*bpm; break;
230 case 2: t = t; bpm = bpm; break;
232 case 3: t = 2*t; bpm = 2*bpm; break;
234 default: t= t; bpm = bpm;
237 for ( Sphery s: spherys){
239 s.setVibrationPeriod(480000/bpm);
240 s.vibration.setBasis(t);
246 // Translate so the center of the car is the origin, offset
248 // .scale(1.3,1.3,1.3)
249 // Rotate around the origin (now the center of the car) about an y-vector
250 .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
251 .translate(model.cx, model.cy, model.cz);
257 for (LXVector p: sinespin)
258 // for (Point p: model.points)
260 P.set(p.x, p.y, p.z);
261 // PVector P = new PVector(p.x, p.y, p.z);
263 c = blendIfColor(c, spherys[1].spheryvalue(P, .75*model.xMax, model.yMax/2, model.zMax/2), ADD);
264 c = blendIfColor(c, spherys[0].spheryvalue(P, model.xMax/4, model.yMax/4, model.zMax/2), ADD);
265 c = blendIfColor(c, spherys[2].spheryvalue(P, model.xMax/2, model.yMax/2, model.zMax/2),ADD);
274 .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
275 .translate(model.cx,model.cy,model.cz);
277 for (LXVector p: sinespin2)
279 // PVector P = new PVector(p.x, p.y, p.z);
280 P.set(p.x, p.y, p.z);
281 c = blendIfColor(c, spherys[3].spheryvalue(P, .3*model.xMax, .7*model.yMax, .6*model.zMax),ADD);
283 colors[p.index] = blendIfColor(colors[p.index], c , ADD);
289 color blendIfColor(color c1, color c2, int mode) {
291 return blendColor(c1, c2, mode);
298 // 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);
301 // return lx.hsb(0,0,0);
302 // // else if(spheremode ==2)
304 // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) );
313 class CubeCurl extends SCPattern{
315 ArrayList<PVector> cubeorigin = new ArrayList<PVector>();
316 ArrayList<PVector> centerlist = new ArrayList<PVector>();
317 private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 );
319 private SinLFO bg = new SinLFO(180, 220, 3000);
321 CubeCurl(GLucose glucose){
323 addModulator(curl).trigger();
324 addModulator(bg).trigger();
325 this.CH = Cube.EDGE_HEIGHT;
326 this.CW = Cube.EDGE_WIDTH;
327 this.diag = sqrt(CW*CW + CW*CW);
330 ArrayList<PVector> centerlistrelative = new ArrayList<PVector>();
331 for (int i = 0; i < model.cubes.size(); i++){
332 Cube a = model.cubes.get(i);
333 cubeorigin.add(new PVector(a.x, a.y, a.z));
334 centerlist.add(new PVector(a.cx, a.cy, a.cz) );
339 //there is definitely a better way of doing this!
340 PVector centerofcube(int i) {
341 Cube c = model.cubes.get(i);
343 //println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z );
344 // PVector cubeangle = new PVector(c.rx, c.ry, c.rz);
345 //println("raw x angle: " + c.rx + "raw y angle: " + c.ry + "raw z angle: " + c.rz);
346 //PVector cubecenter = new PVector(c.x + CW/2, c.y + CH/2, c.z + CW/2);
347 //println("cubecenter unrotated: " + cubecenter.x + " " +cubecenter.y + " " +cubecenter.z );
348 //PVector 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);
349 // nCos*(y-o.y) - nSin*(z-o.z) + o.y
350 //cubecenter = PVector.add(new PVector(c.x, c.y, c.z), centerrot);
351 //println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " ");
352 PVector cubecenter = new PVector(c.cx, c.cy, c.cz);
358 void run(double deltaMs){
359 for (int i =0; i < model.cubes.size(); i++) {
360 Cube c = model.cubes.get(i);
365 // for (LXPoint p : c.points ){
366 // // colors[p.index]=color(0,0,0);
367 // //float dif = (p.y - c.y);
368 // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD);
372 // else if (i%3 == 1) {
374 // for (LXPoint p: c.points){
375 // colors[p.index]=color(0,0,0);
376 // float dif = (p.y - c.y);
377 // // colors[p.index] =
378 // // color(bg.getValuef(),
379 // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100),
380 // // 100 - 10*abs(dif - curl.getValuef()), ADD );
383 // else if (i%3 == 2){
384 // centerlist[i].sub(cubeorigin(i);
385 for (LXPoint p: c.points) {
386 PVector pv = new PVector(p.x, p.y, p.z);
387 colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 );
388 // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), );
400 class HueTestHSB extends SCPattern{
401 BasicParameter HueT = new BasicParameter("Hue", .5);
402 BasicParameter SatT = new BasicParameter("Sat", .5);
403 BasicParameter BriT = new BasicParameter("Bright", .5);
405 HueTestHSB(GLucose glucose) {
411 void run(double deltaMs){
413 for (LXPoint p : model.points) {
415 c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD);
419 if (now % 1000 <= 20)
421 println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef());