More DPat Fixes
[SugarCubes.git] / DanHorwitz.pde
index 3b7e1d6ef37074bc5f59e537052e8c51b1021c5c..e8780db26473ad44a31197f7bb9c7a6efd08e98a 100755 (executable)
@@ -14,10 +14,10 @@ public class Pong extends DPat {
                addModulator(y  = new SinLFO(cRad, ydMax - cRad, 0)).trigger(); y.modulateDurationBy(dy);\r
                addModulator(z  = new SinLFO(cRad, zdMax - cRad, 0)).trigger(); z.modulateDurationBy(dz);\r
            pSize       = addParam      ("Size"                 , 0.4   );\r
-           pChoose = addPick   ("Animiation"   , 0     , 3     );\r
+           pChoose = addPick   ("Animiation"   , 0     , 3, new String[] {"Pong", "Ball", "Cone"}      );\r
        }\r
 \r
-       void    StartRun(int deltaMs)   { cRad = xdMax*pSize.Val()/6; }\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
                switch(pChoose.Cur()) {\r
@@ -51,12 +51,13 @@ public class Noise extends DPat
 \r
        Noise(GLucose glucose) {\r
                super(glucose);\r
-               pRotZ   = addParam("RotZ"       , .5 ); pSpeed          = addParam("Fast", .55);\r
-               pDensity= addParam("Dens"       , .5);\r
-               pSymm   = addPick("Symmetry", 0, 4);    pChoose         = addPick("Animation", 1, 6);\r
+               pRotZ   = addParam("RotZ"        , .5 );        pSpeed          = addParam("Fast", .55);\r
+               pDensity= addParam("Dens"        , .5);\r
+               pSymm   = addPick("Symmetry" , 0, 4, new String[] {"None", "X", "Y", "Radial"}  );\r
+               pChoose = addPick("Animation", 1, 6, new String[] {"Drip", "Cloud", "Rain", "Fire", "Machine", "Spark"} );\r
        }\r
 \r
-       void StartRun(int deltaMs) {\r
+       void StartRun(double deltaMs) {\r
                zTime   += deltaMs*(pSpeed.Val()-.5)*.002       ;\r
                zTheta  += deltaMs*(pRotZ .Val()-.5)*.01        ;\r
                rtime   += deltaMs;\r
@@ -113,21 +114,25 @@ public class Play extends DPat
        int             nBeats  =       0;\r
        _DhP    pAmp, pRad;\r
        _DhP    pRotX, pRotY, pRotZ;\r
-       xyz             Theta = new xyz();\r
+       xyz             Theta   = new xyz();\r
+       xyz             TSin    = new xyz();\r
+       xyz             TCos    = new xyz();\r
+       \r
        Pick    pTimePattern, pTempoMult, pShape, pForm;\r
        int             RandCube;\r
 \r
        Play(GLucose glucose) {\r
                super(glucose);\r
-           pAmp                = addParam("Amp" , .2);\r
                pRotX           = addParam("RotX", .5);\r
                pRotY           = addParam("RotY", .5);\r
                pRotZ           = addParam("RotZ", .5);\r
-           pRad                = addParam("Rad" , .1           );\r
-               pTimePattern= addPick ("TimePattern", 0 , 5             );\r
-               pTempoMult      = addPick ("TimeMult"   , 0 , 6         );\r
-               pShape          = addPick ("Shape"              , 0 , 16        );\r
-               pForm           = addPick ("Form"               , 0 , 3         );\r
+           pAmp                = addParam("Amp" , .2);\r
+           pRad                = addParam("Rad"        , .1            );\r
+               pTempoMult      = addPick ("TMult"      , 0 , 6         , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand"   }       );\r
+               pTimePattern= addPick ("TPat"   , 0 , 5         , new String[] {"Bounce", "?", "Roll", "Quant", "Accel" }       );\r
+               pShape          = addPick ("Shape"      , 0 , 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
@@ -135,16 +140,16 @@ public class Play extends DPat
        float   LastBeat=3, LastMeasure=3;\r
        int             CurRandTempo = 1;\r
 \r
-       void StartRun(int deltaMs) {\r
+       void StartRun(double deltaMs) {\r
                t = lx.tempo.rampf();\r
                a = pAmp.Val();\r
 \r
-               Theta.x = pRotX.ZeroOrOne() ? 0 :(pRotX.Val()-.5)*10;\r
-               Theta.y = pRotY.ZeroOrOne() ? 0 :(pRotY.Val()-.5)*10;\r
-               Theta.z = pRotZ.ZeroOrOne() ? 0 :(pRotZ.Val()-.5)*10;\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
+               TCos    .set(cos(Theta.x), cos(Theta.y), cos(Theta.z));\r
 \r
                if (t<LastMeasure) { CurRandTempo = int(random(4)); } LastMeasure = t;\r
-               \r
+\r
                switch (pTempoMult.Cur()) {\r
                        case 0:         t = t;                                                          break;\r
                        case 1:         t = (t*2. )%1.;                                         break;\r
@@ -164,43 +169,42 @@ public class Play extends DPat
                        case 4:         t = t*t*t;                                                      break;\r
                }\r
 \r
-               cMid            = cPrev.interpolate(t,cCur);\r
-               cMidNorm        = cMid.setNorm();\r
+               \r
+               cMid                            = cPrev.interpolate(t,cCur);\r
+               cMidNorm                        = cMid.setNorm();\r
        }\r
 \r
        color CalcPoint(xyz Px) {\r
-               xyz V           = new xyz();\r
-               xyz P           = Px.setNorm();\r
-               if (Theta.x>0)  P = P.RotateZ(xyzHalf, Theta.x);\r
-               if (Theta.y>0)  P = P.RotateZ(xyzHalf, Theta.y);\r
-               if (Theta.z>0)  P = P.RotateZ(xyzHalf, Theta.z);\r
+               xyz V           =       new xyz();\r
+               xyz P           =       Px.setNorm();\r
+                                               P.RotateXYZ(xyzHalf, Theta, TSin, TCos);\r
 \r
                float mp        = min(P.x, P.z);\r
                float yt        = map(t,0,1,.5-a/2,.5+a/2);\r
 \r
                switch (pShape.Cur()) {\r
-                       case 0:         V = new xyz(P.x, yt                                                             , P.z);                                         break;  // bouncing line\r
-                       case 1:         V = new xyz(P.x, map(cos(PI*t * P.x),-1,1,0,1)  , P.z);                                         break;  // top tap\r
-                       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\r
-                       case 3:         V = new xyz(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 = new xyz(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
+                       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 = new xyz(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z);                        break;  // wings\r
-                       case 6:         V = new xyz(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z);                        break;  // wings\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 = new xyz(cMid.x,cMid.y,cMid.z);\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 = new xyz(cMid.x,cMid.y,cMid.z);\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
+                                                       85,c1c(P.y < noise(P.x + NoiseMove/2000.,P.z)*(1+a)-a/2.-.1 ? 1 : 0));                  //\r
                }\r
 \r
 \r