+public class Play extends DPat
+{
+ int nBeats = 0;
+ _P pAmp, pRotX, pRotY, pRotZ, pRad;
+ Pick pTimePattern, pTempoMult, pShape;
+
+ Play(GLucose glucose) {
+ super(glucose);
+ addParameter(pAmp = new _P("Amp" , .2 ));
+ addParameter(pRotX = new _P("RotX", 0 ));
+ addParameter(pRotY = new _P("RotY", 0 ));
+ addParameter(pRotZ = new _P("RotZ", 0 ));
+ addParameter(pRad = new _P("Rad" , .1 ));
+
+ pTimePattern = addPick("TPat", 0 , 5 );
+ pTempoMult = addPick("TMul", 5 , 6 );
+ pShape = addPick("Shap", 8 , 10 );
+
+ lx.tempo.setBpm(30);
+ }
+
+ float t,a;
+ xyz cPrev = new xyz(), cCur = new xyz(), cMid = new xyz(), cMidNorm;
+ float LastBeat=3, LastMeasure=3;
+ int CurRandTempo = 1;
+
+ void StartRun(int deltaMs) {
+ t = lx.tempo.rampf();
+ a = pAmp.Val();
+
+ if (t<LastMeasure) { CurRandTempo = int(random(4)); } LastMeasure = t;
+
+ switch (pTempoMult.Cur()) {
+ case 0: t = t; break;
+ case 1: t = (t*2. )%1.; break;
+ case 2: t = (t*4. )%1.; break;
+ case 3: t = (t*8. )%1.; break;
+ case 4: t = (t*16.)%1.; break;
+ case 5: t = (t*pow(2,CurRandTempo))%1.; break;
+ }
+
+ if (t<LastBeat) { cPrev = cCur; cCur = cCur.setRand(); } LastBeat = t;
+
+ switch (pTimePattern.Cur()) {
+ case 0: t = sin(PI*t); break;
+ case 1: t = norm(sin(2*PI*(t+PI/2)),-1,1); break;
+ case 2: t = t; break;
+ case 3: t = constrain(int(t*8)/7.,0,1); break;
+ case 4: t = t*t*t; break;
+ }
+
+ cMid = cPrev.interpolate(t,cCur);
+ cMidNorm = cMid.setNorm();
+ }
+
+ color CalcPoint(Point p) {
+ xyz V = new xyz(0,0,0);
+ xyz P = new xyz(p).setNorm(). RotateX(xyzHalf,pRotX.Val()*PI*2).
+ RotateY(xyzHalf,pRotY.Val()*PI*2).
+ RotateZ(xyzHalf,pRotZ.Val()*PI*2);
+ xyz Px = new xyz(p);
+
+ float mp = min(P.x, P.z);
+ float yt = map(t,0,1,.5-a/2,.5+a/2);
+ switch (pShape.Cur()) {
+
+ case 0: V = new xyz(P.x, yt , P.z); break; // bouncing line
+ case 1: V = new xyz(P.x, map(cos(PI*t * P.x),-1,1,0,1) , P.z); break; // top tap
+ case 2: V = new xyz(P.x, a*map(P.x<.5?P.x:1-P.x,0,.5 ,0,t-.5)+.5, P.z); break; // V shape
+ case 3: V = new xyz(P.x, P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :
+ map(P.x,cMidNorm.x,1, yt,.5), P.z); break; // Random V shape
+
+ case 4: V = new xyz(P.x, .5*(P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :
+ map(P.x,cMidNorm.x,1, yt,.5)) +
+ .5*(P.z < cMidNorm.z ? map(P.z,0,cMidNorm.z, .5,yt) :
+ map(P.z,cMidNorm.z,1, yt,.5)), P.z); break; // Random Pyramid shape
+
+ case 5: V = new xyz(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z); break; // wings
+ case 6: V = new xyz(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z); break; // wings
+
+
+ case 7: V = new xyz(cMid.x,cMid.y,cMid.z);
+ return color(0,0,c1c(1 - (V.distance(Px) > (pRad.getValuef()+.1)*100?1:0)) ); // sphere
+
+ case 8: V = new xyz(cMid.x,cMid.y,cMid.z);
+ return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0)); // cone
+
+ }
+
+ return color(0,0,c1c(1 - V.distance(P)/pRad.getValuef() > .5?1:0));
+ }
+}
+//----------------------------------------------------------------------------------------------------------------------------------
\ No newline at end of file