more dpat fixes
authorbb3dan <gitdan@citopia.com>
Fri, 27 Sep 2013 01:30:29 +0000 (21:30 -0400)
committerbb3dan <gitdan@citopia.com>
Fri, 27 Sep 2013 01:30:35 +0000 (21:30 -0400)
DanHorwitz.pde
DanUtil.pde

index a51f0a407a7484dd3a9dd1ec99e10095cf8f3415..96101809f59680b0bf91b23f0d156db0f04ddc2f 100755 (executable)
@@ -7,25 +7,25 @@ public class Pong extends DPat {
 \r
        Pong(GLucose glucose) {\r
                super(glucose);\r
-               cRad = xdMax/15;\r
+               cRad = mMax.x/10;\r
                addModulator(dx = new SinLFO(6000,  500, 30000  )).trigger();\r
                addModulator(dy = new SinLFO(3000,  500, 22472  )).trigger();\r
                addModulator(dz = new SinLFO(1000,  500, 18420  )).trigger();\r
-               addModulator(x  = new SinLFO(cRad, xdMax - cRad, 0)).trigger(); x.modulateDurationBy(dx);\r
-               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
+               addModulator(x  = new SinLFO(cRad, mMax.x - cRad, 0)).trigger();        x.modulateDurationBy(dx);\r
+               addModulator(y  = new SinLFO(cRad, mMax.y - cRad, 0)).trigger();        y.modulateDurationBy(dy);\r
+               addModulator(z  = new SinLFO(cRad, mMax.z - cRad, 0)).trigger();        z.modulateDurationBy(dz);\r
            pSize       = addParam      ("Size"                 , 0.4   );\r
            pChoose = addPick   ("Animiation"   , 0     , 3, new String[] {"Pong", "Ball", "Cone"}      );\r
        }\r
 \r
-       void    StartRun(double deltaMs)        { cRad = xdMax*pSize.Val()/6; }\r
+       void    StartRun(double deltaMs)        { cRad = mMax.x*pSize.Val()/6; }\r
        color   CalcPoint(xyz p)                {\r
                v.set(x.getValuef(), y.getValuef(), z.getValuef());\r
                switch(pChoose.Cur()) {\r
-               case 0: vMir.set(xyzdMax); vMir.subtract(p);\r
+               case 0: vMir.set(mMax); 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
+               case 2: vMir.set(mMax.x/2,0,mMax.z/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
@@ -109,17 +109,17 @@ public class Noise extends DPat
 \r
        color CalcPoint(xyz P) {\r
                color c = 0;\r
-               P.RotateZ(xyzMid, zSin, zCos);\r
+               P.RotateZ(mCtr, zSin, zCos);\r
                \r
-               if (iSymm == XSym && P.x > xdMax/2) P.x = xdMax-P.x;\r
-               if (iSymm == YSym && P.y > ydMax/2) P.y = ydMax-P.y;\r
+               if (iSymm == XSym && P.x > mMax.x/2) P.x = mMax.x-P.x;\r
+               if (iSymm == YSym && P.y > mMax.y/2) P.y = mMax.y-P.y;\r
 \r
                for (int i=0;i<_ND; i++) if (N[i].Active()) {\r
                        NDat  n     = N[i];\r
                        float zx    = zTime * n.speed * n.sinAngle,\r
                                  zy    = zTime * n.speed * n.cosAngle;\r
                        \r
-                       float b     = (iSymm==RadSym ? noise(zTime*n.speed+n.xoff-Dist(P,xyzMid)/n.xz)\r
+                       float b     = (iSymm==RadSym ? noise(zTime*n.speed+n.xoff-Dist(P,mCtr)/n.xz)\r
                                                                                 : noise(P.x/n.xz+zx+n.xoff,P.y/n.yz+zy+n.yoff,P.z/n.zz+n.zoff))\r
                                                        *1.8;\r
 \r
@@ -133,11 +133,29 @@ public class Noise extends DPat
 //----------------------------------------------------------------------------------------------------------------------------------\r
 public class Play extends DPat\r
 {\r
+       public class rAngle {\r
+               float   prvA, dstA, c;\r
+               float   prvR, dstR, r;          \r
+               float   _cos, _sin, x, y;\r
+               float   fixAngle        (float a, float b) { return a<b ?\r
+                                                                               (abs(a-b) > abs(a+2*PI-b) ? a : a+2*PI) :\r
+                                                                               (abs(a-b) > abs(a-2*PI-b) ? a : a-2*PI) ; }\r
+               float   getX(float r)   {       return mCtr.x + _cos*r; }\r
+               float   getY(float r)   {       return mCtr.y + _sin*r; }\r
+               void    move()                  {       c               = interp(t,prvA,dstA); \r
+                                                                       r               = interp(t,prvR,dstR);\r
+                                                                       _cos    = cos(c);       _sin    = sin(c);\r
+                                      x                = getX(r);      y               = getY(r);              }               \r
+               void    set()                   {       prvA    = dstA;         dstA    = random(2*PI);         prvA = fixAngle(prvA, dstA);\r
+                                                                       prvR    = dstR;         dstR    = random(mCtr.y);                                                                       }\r
+       }\r
        int             nBeats  =       0;\r
        DParam  pAmp, pRad;\r
        DParam  pRotX, pRotY, pRotZ;\r
 \r
        float   t,amp;\r
+       rAngle  a1 = new rAngle(), a2 = new rAngle(),\r
+                       a3 = new rAngle(), a4 = new rAngle();\r
        xyz             cPrev   = new xyz(), cRand      = new xyz(),\r
                        cMid    = new xyz(), V          = new xyz(),\r
                        Theta   = new xyz(), TSin       = new xyz(),\r
@@ -157,11 +175,10 @@ public class Play extends DPat
                pRotZ           = addParam("RotZ", .5);\r
            pAmp                = addParam("Amp" , .2);\r
            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"      , 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
+               pTempoMult      = addPick ("TMult"      , 0 , 6         , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand"   }       );\r
+               pTimePattern= addPick ("TPat"   , 6 , 8         , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel", "Deccel", "Slide", "Rand"}   );\r             pShape          = addPick ("Shape"      , 8 , 12        , new String[] {"Line", "Tap", "V", "RandV", "Pyramid", "Wings", "W2", "Clock",\r
+                                                                                                                                       "RSphere", "Sphere", "Cone", "Noise" }                                  );\r
+               pForm           = addPick ("Form"       , 0 , 3         , new String[] {"Bar", "Volume", "Fade"}                                                                );\r
        }\r
 \r
        void StartRun(double deltaMs) {\r
@@ -173,12 +190,12 @@ public class Play extends DPat
                TCos    .set(cos(Theta.x), cos(Theta.y), cos(Theta.z));\r
 \r
                if (t<LastMeasure) {\r
-                       if (random(2) < 1) CurRandTempo = int(random(4));\r
-                       if (random(2) < 1) CurRandTPat  = int(random(5));\r
+                       if (random(3) < 1) { CurRandTempo = int(random(4)); if (CurRandTempo == 3) CurRandTempo = int(random(4));       }\r
+                       if (random(3) < 1) { CurRandTPat  = pShape.Cur() > 6 ? 2+int(random(5)) : int(random(7));                                       }\r
                } LastMeasure = t;\r
                        \r
                int nTempo = pTempoMult  .Cur(); if (nTempo == 5) nTempo = CurRandTempo;\r
-               int nTPat  = pTimePattern.Cur(); if (nTPat  == 5) nTPat  = CurRandTPat ;\r
+               int nTPat  = pTimePattern.Cur(); if (nTPat  == 7) nTPat  = CurRandTPat ;\r
 \r
                switch (nTempo) {\r
                        case 0:         t = t;                                                          break;\r
@@ -188,61 +205,83 @@ public class Play extends DPat
                        case 4:         t = (t*16.)%1.;                                         break;\r
                }\r
 \r
-               if (t<LastBeat) { cPrev.set(cRand); cRand.setRand(); } LastBeat = t;\r
+               if (t<LastBeat) {\r
+                       cPrev.set(cRand); cRand.setRand();\r
+                       a1.set(); a2.set(); a3.set(); a4.set();\r
+               } LastBeat = t;\r
 \r
                switch (nTPat) {\r
-                       case 0:         t = sin(PI*t);                                          break;\r
-                       case 1:         t = norm(sin(2*PI*(t+PI/2)),-1,1);      break;\r
-                       case 2:         t = t;                                                          break;\r
-                       case 3:         t = constrain(int(t*8)/7.,0,1);         break;\r
-                       case 4:         t = t*t*t;                                                      break;\r
+                       case 0:         t = sin(PI*t);                                                  break;  // bounce\r
+                       case 1:         t = norm(sin(2*PI*(t+PI/2)),-1,1);              break;  // sin\r
+                       case 2:         t = t;                                                                  break;  // roll\r
+                       case 3:         t = constrain(int(t*8)/7.,0,1);                 break;  // quant\r
+                       case 4:         t = t*t*t;                                                              break;  // accel\r
+                       case 5:         t = sin(PI*t*.5);                                               break;  // deccel\r
+                       case 6:         t = .5*(1-cos(PI*t));                                   break;  // slide\r
                }\r
                \r
+               \r
                cMid.set                (cPrev);        cMid.interpolate        (t,cRand);\r
                cMidNorm.set    (cMid);         cMidNorm.setNorm();\r
+\r
+               a1.move(); a2.move(); a3.move(); a4.move();\r
        }\r
 \r
        color CalcPoint(xyz Px) {\r
-               Px.zoomX(1.3);\r
+               if (Theta.x != 0) Px.RotateX(mCtr, TSin.x, TCos.x);\r
+               if (Theta.y != 0) Px.RotateY(mCtr, TSin.y, TCos.y);\r
+               if (Theta.z != 0) Px.RotateZ(mCtr, TSin.z, TCos.z);\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(Pn.x, Pn.z);\r
                float yt        = map(t,0,1,.5-amp/2,.5+amp/2);\r
+               float rad       = pRad.getValuef();\r
 \r
                switch (pShape.Cur()) {\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
+               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:         return color(0,0, min(\r
+                                               distToSeg(Px.x, Px.y, a1.getX(70),a1.getY(70), mCtr.x, mCtr.y),\r
+                                               distToSeg(Px.x, Px.y, a2.getX(40),a2.getY(40), mCtr.x, mCtr.y)) <rad*40?100:0); // clock\r
+\r
+//             case 8:         return color(0,0,c1c(.9+2*pRad.getValuef() - Px.distance(a1.x,a1.y)*.03) );             // sphere - radial\r
 \r
+               case 8:         float r = amp*200;\r
+                                       return color(0,0, min(\r
+                                               distToSeg(Px.x, Px.y, a1.getX(r),a1.getY(r), a2.getX(r),a2.getY(r)),\r
+                                               distToSeg(Px.x, Px.y, a2.getX(r),a2.getY(r), a3.getX(r),a3.getY(r)),\r
+                                               distToSeg(Px.x, Px.y, a3.getX(r),a3.getY(r), a4.getX(r),a4.getY(r)),\r
+                                               distToSeg(Px.x, Px.y, a4.getX(r),a4.getY(r), a1.getX(r),a1.getY(r))\r
+                                               ) <rad*40?100:0); // shape\r
+\r
+\r
+               case 9:         return color(0,0,c1c(.9+2*pRad.getValuef() - cMid.distance(Px)*.03) );          // sphere - radial\r
+\r
+               case 10:        return color(0,0,c1c(1 - CalcCone(Px,cMid,mCtr) * 0.02 > .5?1:0));                              // cone\r
+\r
+               case 11:        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
+\r
+               default:        return color(0,0,0);\r
+               }\r
 \r
                switch (pForm.Cur()) {\r
-                       case 0:         return color(0,0,c1c(1 - V.distance(Pn)/pRad.getValuef() > .5?1:0));\r
+                       case 0:         return color(0,0,c1c(1 - V.distance(Pn)/rad > .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
+                       case 2:         return color(0,0,c1c(1 - V.distance(Pn)/rad));\r
 \r
                        default:        return color(0,0,c1c(Pn.y < V.y ?1:0));\r
                }\r
index c098524b1541a7f8753d20259c2a7ff2350ffd47..7b0c17d5e5ad911521bde23fad5d2975085f4df6 100644 (file)
@@ -1,10 +1,27 @@
 //----------------------------------------------------------------------------------------------------------------------------------
-float          xdMax,ydMax,zdMax;
+xyz                    mMax, mCtr, mHalf;
 int                    NumApcRows = 5, NumApcCols = 8;
 DGlobals       DG = new DGlobals();
 
-boolean btwn  (int             a,int    b,int          c)              { return a >= b && a <= c;      }
-boolean btwn  (double  a,double b,double       c)              { return a >= b && a <= c;      }
+boolean btwn   (int            a,int    b,int          c)              { return a >= b && a <= c;      }
+boolean btwn   (double         a,double b,double       c)              { return a >= b && a <= c;      }
+float  interp  (float a, float b, float c) { return (1-a)*b + a*c; }
+float  randctr (float a) { return random(a) - a*.5; }
+float  min             (float a, float b, float c, float d) { return min(min(a,b),min(c,d)); }
+
+float  distToSeg       (float x, float y, float x1, float y1, float x2, float y2) {
+       float A                         = x - x1, B = y - y1, C = x2 - x1, D = y2 - y1;
+       float dot                       = A * C + B * D, len_sq = C * C + D * D;
+       float xx, yy,param      = dot / len_sq;
+       
+       if (param < 0 || (x1 == x2 && y1 == y2)) {      xx = x1; yy = y1; }
+       else if (param > 1) {                                           xx = x2; yy = y2; }
+       else {                                                                          xx = x1 + param * C;
+                                                                                               yy = y1 + param * D; }
+       float dx = x - xx, dy = y - yy;
+       return sqrt(dx * dx + dy * dy);
+}
+
 
 public class Pick {
        int     NumPicks, Default       ,       CurRow  , CurCol        ,
@@ -51,19 +68,22 @@ public class DParam extends BasicParameter {
 public class xyz {     float x,y,z;
                        xyz() {x=y=z=0;}
                        xyz(Point p                                       ) {x=p.fx     ; y=p.fy; z=p.fz;}
+                       xyz(xyz p                                         ) {set(p);                             }
                        xyz(float _x,float _y,float _z) {x=_x   ; y=_y  ; z=_z  ;}
        void    set(Point p                                       ) {x=p.fx     ; y=p.fy; z=p.fz;}
        void    set(xyz p                                         ) {x=p.x      ; y=p.y ; z=p.z ;}
        void    set(float _x,float _y,float _z) {x=_x   ; y=_y  ; z=_z  ;}
 
-       void    zoomX   (float zx)                              {x = x*zx - xdMax*(zx-1)/2;                             }
-       void    zoomY   (float zy)                              {y = y*zy - ydMax*(zy-1)/2;                             }
+       void    zoomX   (float zx)                              {x = x*zx - mMax.x*(zx-1)/2;                            }
+       void    zoomY   (float zy)                              {y = y*zy - mMax.y*(zy-1)/2;                            }
 
        float   distance(xyz b)                                 {return dist(x,y,z,b.x,b.y,b.z);                }
+       float   distance(float _x, float _y)    {return dist(x,y,_x,_y);                                }
        float   dot     (xyz b)                                 {return x*b.x + y*b.y + z*b.z;                  }
        void    add             (xyz b)                                 {x += b.x; y += b.y; z += b.z;                  }
        void    add             (float b)                               {x += b  ; y += b  ; z += b  ;                  }
        void    subtract(xyz b)                                 {x -= b.x; y -= b.y; z -= b.z;                  }
+       void    scale   (float b)                               {x *= b  ; y *= b  ; z *= b  ;                  }
 
        void    RotateZ   (xyz o, float nSin, float nCos) {
                float nX = nCos*(x-o.x) - nSin*(y-o.y) + o.x;
@@ -83,11 +103,8 @@ public class xyz {  float x,y,z;
                z = nZ; x = nX;
        }
 
-       void    setRand ()                                              { x = random(xdMax); y = random(ydMax); z = random(zdMax);      }
-       void    setNorm ()                                              { x /= xdMax; y /= ydMax; z /= zdMax;                                           }
-       
-       float   interp (float a, float b, float c) { return (1-a)*b + a*c; }
-
+       void    setRand ()                                              { x = random(mMax.x); y = random(mMax.y); z = random(mMax.z);   }
+       void    setNorm ()                                              { x /= mMax.x; y /= mMax.y; z /= mMax.z;                                                }
        void    interpolate(float i, xyz d)             { x = interp(i,x,d.x); y = interp(i,y,d.y); z = interp(i,z,d.z); }
 }
 //----------------------------------------------------------------------------------------------------------------------------------
@@ -166,7 +183,7 @@ public class DGlobals {
                int row = note.getPitch(), col = note.getChannel();
                for (int i=0; i<CurPat.picks.size(); i++) if (GetPick(i).set(row, col))           return;
                for (int i=0; i<CurPat.bools.size(); i++) if (GetBool(i).set(row, col, true)) return;
-               println("row: " + row + "  col:   " + col);
+               //println("row: " + row + "  col:   " + col);
        }
 }
 //----------------------------------------------------------------------------------------------------------------------------------
@@ -179,19 +196,16 @@ public class DPat extends SCPattern
        float           zSpinHue        = 0;
        float           LastQuant       = -1, LastJog = -1;
        int             nPoint  , nPoints;
-       xyz                     xyzHalf         = new xyz(.5,.5,.5),
-                               xyzdMax         = new xyz(),
-                               xyzMid          = new xyz(),
-                               xyzJog          = new xyz(0,0,0);
+       xyz                     xyzJog = new xyz(), vT1 = new xyz(), vT2 = new xyz();
+       xyz                     modmin;
        
        float           NoiseMove       = random(10000);
        DParam          pSharp, pQuantize, pSaturate;
-       DBool           pXsym, pYsym, pZsym, pJog;
+       DBool           pXsym, pYsym, pRsym, pXdup, pXtrip, pJog;
        float           Dist     (xyz a, xyz b)                         { return dist(a.x,a.y,a.z,b.x,b.y,b.z);         }
        int                     c1c              (float a)                                      { return int(100*constrain(a,0,1));                     }
-       float           CalcCone (xyz v1, xyz v2, xyz c)        {       v1.subtract(c); v2.subtract(c);
-                                                                                                               return degrees( acos ( v1.dot(v2) /
-                                                                                                                       (sqrt(v1.dot(v1)) * sqrt(v2.dot(v2)) ) ));      }
+       float           CalcCone (xyz v1, xyz v2, xyz c)        { vT1.set(v1); vT2.set(v2); vT1.subtract(c); vT2.subtract(c);
+                                                                                                               return degrees( acos ( vT1.dot(vT2) / (sqrt(vT1.dot(vT1)) * sqrt(vT2.dot(vT2)) ) ));    }
        void            StartRun(double deltaMs)                        {                                                               }
        color           CalcPoint(xyz p)                                        { return color(0,0,0);                  }
        boolean         IsActive()                                                      { return this == DG.CurPat;                                                                                             }
@@ -199,6 +213,7 @@ public class DPat extends SCPattern
        void            onInactive()                                            { UpdateState(); }
        void            onActive  ()                                            { UpdateState(); }
        void            UpdateState()                                           { if (IsFocused() != IsActive()) { if (IsFocused()) DG.Activate(this); else DG.Deactivate(this); } }
+       color           blend3(color c1, color c2, color c3){ return blendColor(c1,blendColor(c2,c3,ADD),ADD);                                          }
 
        DParam          addParam(String label, double value) {
                DParam P = new DParam(label, value);
@@ -215,22 +230,22 @@ public class DPat extends SCPattern
 
        DPat(GLucose glucose) {
                super(glucose);
+               pSharp          =       addParam("Shrp",  0 );
+               pQuantize       =       addParam("Qunt",  0 );
+               pSaturate       =       addParam("Sat" ,  .5);
+               nPoints         =       model.points.size();
+               pXsym           =       new DBool("X-SYM", false, 49, 0);       bools.add(pXsym );
+               pYsym           =       new DBool("Y-SYM", false, 49, 1);       bools.add(pYsym );
+               pRsym           =       new DBool("R-SYM", false, 49, 2);       bools.add(pRsym );
+               pXdup           =       new DBool("X-DUP", false, 49, 3);       bools.add(pXdup );
+               pJog            =       new DBool("JOGGER",false, 49, 4);       bools.add(pJog  );
+               modmin          =       new xyz(model.xMin, model.yMin, model.zMin);
+               mMax            =       new xyz(model.xMax, model.yMax, model.zMax); mMax.subtract(modmin);
+               mCtr            =       new xyz(mMax); mCtr.scale(.5);
+               mHalf           =       new xyz(.5,.5,.5);
+               //println (model.xMin + " " + model.yMin + " " +  model.zMin);
+               //println (model.xMax + " " + model.yMax + " " +  model.zMax);
                DG.Init();
-               pSharp          =  addParam("Shrp",  0 );
-               pQuantize       =  addParam("Qunt",  0 );
-               pSaturate       =  addParam("Sat" ,  .5);
-               
-               nPoints         =  model.points.size();
-               xdMax           =  model.xMax;
-               ydMax           =  model.yMax;
-               zdMax           =  model.zMax;
-               xyzdMax         =  new xyz(xdMax,ydMax,zdMax);
-               xyzMid          =  new xyz(xdMax/2, ydMax/2, zdMax/2);
-               
-               bools.add(pXsym         = new DBool("X-SYM", false, 49, 0));
-               bools.add(pYsym         = new DBool("Y-SYM", false, 49, 1));
-               bools.add(pZsym         = new DBool("Z-SYM", false, 49, 2));
-               bools.add(pJog          = new DBool("JOGGER",false, 49, 3));
        }
 
        void run(double deltaMs)
@@ -252,31 +267,27 @@ public class DPat extends SCPattern
                        float f = LastQuant; LastQuant = tRamp; if (tRamp > f) return;
                }
        
-       
                if (pJog.b) {
                        float tRamp     = (lx.tempo.rampf() % .25);
-                       if (tRamp < LastJog) 
-                               xyzJog.set(random(xdMax*.2)-.1,
-                                                  random(ydMax*.2)-.1,
-                                                  random(zdMax*.2)-.1);
+                       if (tRamp < LastJog) xyzJog.set(randctr(mMax.x*.2), randctr(mMax.y*.2), randctr(mMax.z*.2));
                        LastJog = tRamp; 
                }
 
                for (Point p : model.points)    { nPoint++;
                        P.set(p);
+                       P.subtract(modmin);
                        if (pJog.b)     P.add(xyzJog);
-                       if (DG._Spark () > 0)   P.y += DG._Spark () * (noise(P.x,P.y+NoiseMove/30  ,P.z)*ydMax - ydMax/2.);
-                       if (DG._Wiggle() > 0)   P.y += DG._Wiggle() * (noise(P.x/(xdMax*.3)-NoiseMove/1500.) - .5) * (ydMax/2.);
+                       if (DG._Spark () > 0)   P.y += DG._Spark () * (noise(P.x,P.y+NoiseMove/30  ,P.z)*mMax.y - mMax.y/2.);
+                       if (DG._Wiggle() > 0)   P.y += DG._Wiggle() * (noise(P.x/(mMax.x*.3)-NoiseMove/1500.) - .5) * (mMax.y/2.);
 
-                       color cOld = colors[p.index]; pSave.set(P);
-                       color cNew = CalcPoint(P);
-
-                       if (pXsym.b)    { P.set(pSave); tP.set(xdMax-P.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); }
-                       if (pYsym.b)    { P.set(pSave); tP.set(P.x,ydMax-P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); }
-                       if (pZsym.b)    { P.set(pSave); tP.set(P.x,P.y,zdMax-P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); }
+                       color cNew, cOld = colors[p.index];
+                                                       { tP.set(P);                                                                    cNew = CalcPoint(tP);                                                   }
+                       if (pXsym.b)    { tP.set(mMax.x-P.x,P.y,P.z);                                   cNew = blendColor(cNew, CalcPoint(tP), ADD);    }
+                       if (pYsym.b)    { tP.set(P.x,mMax.y-P.y,P.z);                                   cNew = blendColor(cNew, CalcPoint(tP), ADD);    }
+                       if (pRsym.b)    { tP.set(mMax.x-P.x,mMax.y-P.y,mMax.z-P.z);             cNew = blendColor(cNew, CalcPoint(tP), ADD);    }
+                       if (pXdup.b)    { tP.set((P.x+mMax.x*.5)%mMax.x,P.y,P.z);               cNew = blendColor(cNew, CalcPoint(tP), ADD);    }
 
                        float                                                           b = brightness(cNew)/100.;
-
                        if (pSharp.Val()>0)                             b = b < .5 ? pow(b,fSharp) : 1-pow(1-b,fSharp);
                        if (DG._Trails()>0 && fQuant == 0)      b = max(b, (float) (brightness(cOld)/100. - (1-DG._Trails()) * deltaMs/200.));
 
@@ -285,6 +296,9 @@ public class DPat extends SCPattern
                                saturation(cNew) + 100*(fSaturate*2-1),
                                100 *  b * DG._Dim()
                        );
+
+//                     colors[p.index] = color(0,0, p.fx >= modmin.x && p.fy >= modmin.y && p.fz >= modmin.z &&
+//                             p.fx <= modmin.x+mMax.x && p.fy <= modmin.y+mMax.y && p.fz <= modmin.z+mMax.z ? 100 : 0); 
                }
        }
 }