updates on dpat
[SugarCubes.git] / DanHorwitz.pde
index d73b6c48191cc3580e32035e472984e5c99780dc..a51f0a407a7484dd3a9dd1ec99e10095cf8f3415 100755 (executable)
@@ -2,7 +2,8 @@
 public class Pong extends DPat {\r
        SinLFO x,y,z,dx,dy,dz; \r
        float cRad;     DParam pSize;\r
-       Pick  pChoose;\r
+       Pick    pChoose;\r
+       xyz     v = new xyz(), vMir =  new xyz();\r
 \r
        Pong(GLucose glucose) {\r
                super(glucose);\r
@@ -19,14 +20,16 @@ public class Pong extends DPat {
 \r
        void    StartRun(double deltaMs)        { cRad = xdMax*pSize.Val()/6; }\r
        color   CalcPoint(xyz p)                {\r
-               xyz v = new xyz(x.getValuef(), y.getValuef(), z.getValuef());\r
+               v.set(x.getValuef(), y.getValuef(), z.getValuef());\r
                switch(pChoose.Cur()) {\r
-               case 0: return color(0,0,c1c(1 - min(v.distance(p), v.distance(xyzdMax.minus(p)))*.5/cRad));                    // balls\r
-               case 1: return color(0,0,c1c(1 - v.distance(p)*.5/cRad));                                                                                               // ball\r
-               case 2: return color(0,0,c1c(1 - CalcCone(p,v,new xyz(xdMax/2,0,zdMax/2)) * max(.02,.45-pSize.Val())));  // spot\r
+               case 0: vMir.set(xyzdMax); vMir.subtract(p);\r
+                               return color(0,0,c1c(1 - min(v.distance(p), v.distance(vMir))*.5/cRad));        // balls\r
+               case 1: return color(0,0,c1c(1 - v.distance(p)*.5/cRad));                                                       // ball\r
+               case 2: vMir.set(xdMax/2,0,zdMax/2);\r
+                               return color(0,0,c1c(1 - CalcCone(p,v,vMir) * max(.02,.45-pSize.Val())));       // spot\r
                }\r
                return color(0,0,0);\r
-       }               \r
+       }\r
 }\r
 //----------------------------------------------------------------------------------------------------------------------------------\r
 public class NDat {\r
@@ -80,19 +83,19 @@ public class Noise extends DPat
                        \r
                        switch(CurAnim) {\r
                        //                          hue sat xz  yz  zz  den mph angle\r
-                       case 0: N[0].set(0  ,0  ,75 ,75 ,150,45 ,3  ,0  ); pSharp.Set(1 ); break;       // drip\r
-                       case 1: N[0].set(0  ,0  ,100,100,200,45 ,3  ,180); pSharp.Set(0 ); break;       // clouds\r
-                       case 2: N[0].set(0  ,0  ,2  ,400,2  ,20 ,3  ,0  ); pSharp.Set(.5); break;       // rain\r
+                       case 0: N[0].set(0  ,0  ,75 ,75 ,150,45 ,3  ,0  ); pSharp.set(1 ); break;       // drip\r
+                       case 1: N[0].set(0  ,0  ,100,100,200,45 ,3  ,180); pSharp.set(0 ); break;       // clouds\r
+                       case 2: N[0].set(0  ,0  ,2  ,400,2  ,20 ,3  ,0  ); pSharp.set(.5); break;       // rain\r
                        case 3: N[0].set(40 ,1  ,100,100,200,10 ,1  ,180); \r
-                                       N[1].set(0  ,1  ,100,100,200,10 ,5  ,180); pSharp.Set(0 ); break;       // fire 1\r
+                                       N[1].set(0  ,1  ,100,100,200,10 ,5  ,180); pSharp.set(0 ); break;       // fire 1\r
                        case 4: N[0].set(0  ,1  ,40 ,40 ,40 ,15 ,2.5,180);\r
                                        N[1].set(20 ,1  ,40 ,40 ,40 ,15 ,4  ,0  );\r
                                        N[2].set(40 ,1  ,40 ,40 ,40 ,15 ,2  ,90 );\r
-                                       N[3].set(60 ,1  ,40 ,40 ,40 ,15 ,3  ,-90); pSharp.Set(.5); break; // machine\r
+                                       N[3].set(60 ,1  ,40 ,40 ,40 ,15 ,3  ,-90); pSharp.set(.5); break; // machine\r
                        case 5: N[0].set(0  ,1  ,400,100,2  ,15 ,3  ,90 );\r
                                        N[1].set(20 ,1  ,400,100,2  ,15 ,2.5,0  );\r
                                        N[2].set(40 ,1  ,100,100,2  ,15 ,2  ,180);\r
-                                       N[3].set(60 ,1  ,100,100,2  ,15 ,1.5,270); pSharp.Set(.5); break; // spark\r
+                                       N[3].set(60 ,1  ,100,100,2  ,15 ,1.5,270); pSharp.set(.5); break; // spark\r
                        }\r
 \r
                        DG.UpdateLights();\r
@@ -133,10 +136,17 @@ public class Play extends DPat
        int             nBeats  =       0;\r
        DParam  pAmp, pRad;\r
        DParam  pRotX, pRotY, pRotZ;\r
-       xyz             Theta   = new xyz();\r
-       xyz             TSin    = new xyz();\r
-       xyz             TCos    = new xyz();\r
-       \r
+\r
+       float   t,amp;\r
+       xyz             cPrev   = new xyz(), cRand      = new xyz(),\r
+                       cMid    = new xyz(), V          = new xyz(),\r
+                       Theta   = new xyz(), TSin       = new xyz(),\r
+                       TCos    = new xyz(), cMidNorm = new xyz(),\r
+                       Pn              = new xyz();\r
+       float   LastBeat=3, LastMeasure=3;\r
+       int             CurRandTempo = 1, CurRandTPat = 1;\r
+\r
+\r
        Pick    pTimePattern, pTempoMult, pShape, pForm;\r
        int             RandCube;\r
 \r
@@ -149,19 +159,14 @@ public class Play extends DPat
            pRad                = addParam("Rad"        , .1            );\r
                pTempoMult      = addPick ("TMult"      , 5 , 6         , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand"   }       );\r
                pTimePattern= addPick ("TPat"   , 5 , 6         , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel", "Rand"       }       );\r
-               pShape          = addPick ("Shape"      , 0 , 10        , new String[] {"Line", "Tap", "V", "RandV", "Pyramid",\r
+               pShape          = addPick ("Shape"      , 4 , 10        , new String[] {"Line", "Tap", "V", "RandV", "Pyramid",\r
                                                                                                                                        "Wings", "W2", "Sphere", "Cone", "Noise" }      );\r
                pForm           = addPick ("Form"       , 0 , 3         , new String[] {"Bar", "Volume", "Fade"                                 }       );\r
        }\r
 \r
-       float   t,a;\r
-       xyz             cPrev = new xyz(), cCur = new xyz(), cMid = new xyz(), cMidNorm;\r
-       float   LastBeat=3, LastMeasure=3;\r
-       int             CurRandTempo = 1, CurRandTPat = 1;\r
-\r
        void StartRun(double deltaMs) {\r
-               t = lx.tempo.rampf();\r
-               a = pAmp.Val();\r
+               t       = lx.tempo.rampf();\r
+               amp = pAmp.Val();\r
 \r
                Theta   .set(pRotX.Val()*PI*2, pRotY.Val()*PI*2, pRotZ.Val()*PI*2);\r
                TSin    .set(sin(Theta.x), sin(Theta.y), sin(Theta.z));\r
@@ -183,7 +188,7 @@ public class Play extends DPat
                        case 4:         t = (t*16.)%1.;                                         break;\r
                }\r
 \r
-               if (t<LastBeat) { cPrev = cCur; cCur = cCur.setRand(); } LastBeat = t;\r
+               if (t<LastBeat) { cPrev.set(cRand); cRand.setRand(); } LastBeat = t;\r
 \r
                switch (nTPat) {\r
                        case 0:         t = sin(PI*t);                                          break;\r
@@ -192,54 +197,54 @@ public class Play extends DPat
                        case 3:         t = constrain(int(t*8)/7.,0,1);         break;\r
                        case 4:         t = t*t*t;                                                      break;\r
                }\r
-\r
                \r
-               cMid                            = cPrev.interpolate(t,cCur);\r
-               cMidNorm                        = cMid.setNorm();\r
+               cMid.set                (cPrev);        cMid.interpolate        (t,cRand);\r
+               cMidNorm.set    (cMid);         cMidNorm.setNorm();\r
        }\r
 \r
        color CalcPoint(xyz Px) {\r
-               xyz V           =                       new xyz();\r
-               xyz P           =                       Px.setNorm();\r
-               if (Theta.x != 0)               P.RotateX(xyzHalf, TSin.x, TCos.x);\r
-               if (Theta.y != 0)               P.RotateY(xyzHalf, TSin.y, TCos.y);\r
-               if (Theta.z != 0)               P.RotateZ(xyzHalf, TSin.z, TCos.z);\r
+               Px.zoomX(1.3);\r
+               \r
+               Pn.set(Px); Pn.setNorm();\r
+               if (Theta.x != 0)               Pn.RotateX(xyzHalf, TSin.x, TCos.x);\r
+               if (Theta.y != 0)               Pn.RotateY(xyzHalf, TSin.y, TCos.y);\r
+               if (Theta.z != 0)               Pn.RotateZ(xyzHalf, TSin.z, TCos.z);\r
 \r
-               float mp        = min(P.x, P.z);\r
-               float yt        = map(t,0,1,.5-a/2,.5+a/2);\r
+               float mp        = min(Pn.x, Pn.z);\r
+               float yt        = map(t,0,1,.5-amp/2,.5+amp/2);\r
 \r
                switch (pShape.Cur()) {\r
-                       case 0:         V.set(P.x, yt                                                     , P.z);                                                       break;  // bouncing line\r
-                       case 1:         V.set(P.x, map(cos(PI*t * P.x),-1,1,0,1)  , P.z);                                                       break;  // top tap\r
-                       case 2:         V.set(P.x, a*map(P.x<.5?P.x:1-P.x,0,.5 ,0,t-.5)+.5, P.z);                                       break;  // V shape\r
-                       case 3:         V.set(P.x, P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :\r
-                                                                                                         map(P.x,cMidNorm.x,1, yt,.5), P.z);                   break;  //  Random V shape\r
-\r
-                       case 4:         V.set(P.x,      .5*(P.x < cMidNorm.x ?  map(P.x,0,cMidNorm.x, .5,yt) :\r
-                                                                                                                       map(P.x,cMidNorm.x,1, yt,.5)) +\r
-                                                                       .5*(P.z < cMidNorm.z ?  map(P.z,0,cMidNorm.z, .5,yt) :\r
-                                                                                                                       map(P.z,cMidNorm.z,1, yt,.5)), P.z);    break;  //  Random Pyramid shape\r
-                                                                                                                       \r
-                       case 5:         V.set(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z);                                      break;  // wings\r
-                       case 6:         V.set(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z);                                      break;  // wings\r
-\r
-                       case 7:         V.set(cMid.x,cMid.y,cMid.z);\r
-                                               return color(0,0,c1c(1 - (V.distance(Px) > (pRad.getValuef()+.1)*150?1:0)) );           // sphere\r
-\r
-                       case 8:         V.set(cMid.x,cMid.y,cMid.z);\r
-                                               return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0));                                       // cone\r
-\r
-                       case 9:         return color(100 + noise(P.x,P.y,P.z + (NoiseMove+50000)/1000.)*200,\r
-                                                       85,c1c(P.y < noise(P.x + NoiseMove/2000.,P.z)*(1+a)-a/2.-.1 ? 1 : 0));                  //\r
+                       case 0: V.set(Pn.x, yt                                                          , Pn.z);                                                        break;  // bouncing line\r
+                       case 1: V.set(Pn.x, map(cos(PI*t * Pn.x),-1,1,0,1)  , Pn.z);                                                    break;  // top tap\r
+                       case 2: V.set(Pn.x, amp*map(Pn.x<.5?Pn.x:1-Pn.x,0,.5 ,0,t-.5)+.5, Pn.z);                                break;  // V shape\r
+                       case 3: V.set(Pn.x, Pn.x < cMidNorm.x ? map(Pn.x,0,cMidNorm.x, .5,yt) :\r
+                                                                                                       map(Pn.x,cMidNorm.x,1, yt,.5), Pn.z);                   break;  //  Random V shape\r
+\r
+                       case 4: V.set(Pn.x,     .5*(Pn.x < cMidNorm.x ?         map(Pn.x,0,cMidNorm.x, .5,yt) :\r
+                                                                                                                       map(Pn.x,cMidNorm.x,1, yt,.5)) +\r
+                                                               .5*(Pn.z < cMidNorm.z ?         map(Pn.z,0,cMidNorm.z, .5,yt) :\r
+                                                                                                                       map(Pn.z,cMidNorm.z,1, yt,.5)), Pn.z);  break;  //  Random Pyramid shape\r
+                                                                                                               \r
+                       case 5: V.set(Pn.x, amp*map((Pn.x-.5)*(Pn.x-.5),0,.25,0,t-.5)+.5, Pn.z);                                break;  // wings\r
+                       case 6: V.set(Pn.x, amp*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, Pn.z);                                  break;  // wings\r
+\r
+                       case 7: V.set(cMid); return color(0,0,c1c(1 - (V.distance(Px) > (pRad.getValuef()+.1)*150?1:0)) );      // sphere\r
+                       case 8: V.set(cMid); return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0));                          // cone\r
+                       case 9: \r
+                               \r
+                               \r
+                       case 10:        return color(100 + noise(Pn.x,Pn.y,Pn.z + (NoiseMove+50000)/1000.)*200,\r
+                                                       85,c1c(Pn.y < noise(Pn.x + NoiseMove/2000.,Pn.z)*(1+amp)-amp/2.-.1 ? 1 : 0));                   // noise\r
+                       default:        return color(0,0,0);\r
                }\r
 \r
 \r
                switch (pForm.Cur()) {\r
-                       case 0:         return color(0,0,c1c(1 - V.distance(P)/pRad.getValuef() > .5?1:0));\r
-                       case 1:         return color(0,0,c1c(P.y < V.y ?1:0));\r
-                       case 2:         return color(0,0,c1c(1 - V.distance(P)/pRad.getValuef()));\r
+                       case 0:         return color(0,0,c1c(1 - V.distance(Pn)/pRad.getValuef() > .5?1:0));\r
+                       case 1:         return color(0,0,c1c(Pn.y < V.y ?1:0));\r
+                       case 2:         return color(0,0,c1c(1 - V.distance(Pn)/pRad.getValuef()));\r
 \r
-                       default:        return color(0,0,c1c(P.y < V.y ?1:0));\r
+                       default:        return color(0,0,c1c(Pn.y < V.y ?1:0));\r
                }\r
        }\r
 }\r