removed DParam
authorbb3dan <gitdan@citopia.com>
Wed, 23 Oct 2013 18:27:09 +0000 (14:27 -0400)
committerbb3dan <gitdan@citopia.com>
Wed, 23 Oct 2013 18:27:09 +0000 (14:27 -0400)
DanHorwitz.pde
DanUtil.pde

index 741ff46694d7f33e917aaee89da2c5bfd3f5912d..a645489790e2e9f3ccffc451fc3b5da461cc47cc 100644 (file)
@@ -1,7 +1,7 @@
 //----------------------------------------------------------------------------------------------------------------------------------
 public class Pong extends DPat {
        SinLFO x,y,z,dx,dy,dz;
-       float cRad;     DParam pSize;
+       float cRad;     BasicParameter pSize;
        Pick    pChoose;
        xyz     v = new xyz(), vMir =  new xyz();
 
@@ -18,7 +18,7 @@ public class Pong extends DPat {
            pChoose = addPick   ("Animiation"   , 0, 2, new String[] {"Pong", "Ball", "Cone"}   );
        }
 
-       void    StartRun(double deltaMs)        { cRad = mMax.x*pSize.Val()/6; }
+       void    StartRun(double deltaMs)        { cRad = mMax.x*val(pSize)/6; }
        color   CalcPoint(xyz p)                {
                v.set(x.getValuef(), y.getValuef(), z.getValuef());
                v.z=0;p.z=0;// ignore z dimension
@@ -27,7 +27,7 @@ public class Pong extends DPat {
                                return lx.hsb(lxh(),100,c1c(1 - min(v.distance(p), v.distance(vMir))*.5/cRad));         // balls
                case 1: return lx.hsb(lxh(),100,c1c(1 - v.distance(p)*.5/cRad));                                                        // ball
                case 2: vMir.set(mMax.x/2,0,mMax.z/2);
-                               return lx.hsb(lxh(),100,c1c(1 - CalcCone(p,v,vMir) * max(.02,.45-pSize.Val())));        // spot
+                               return lx.hsb(lxh(),100,c1c(1 - CalcCone(p,v,vMir) * max(.02,.45-val(pSize))));         // spot
                }
                return lx.hsb(0,0,0);
        }
@@ -49,13 +49,13 @@ public class NDat {
 
 public class Noise extends DPat
 {
-       int                     CurAnim, iSymm;
-       int             XSym=1,YSym=2,RadSym=3;
-       float           zTime , zTheta=0, zSin, zCos, rtime, ttime;
-       DParam          pSpeed , pDensity, pSharp;
-       Pick            pChoose, pSymm;
-       int                     _ND = 4;
-       NDat            N[] = new NDat[_ND];
+       int                             CurAnim, iSymm;
+       int                     XSym=1,YSym=2,RadSym=3;
+       float                   zTime , zTheta=0, zSin, zCos, rtime, ttime;
+       BasicParameter  pSpeed , pDensity, pSharp;
+       Pick                    pChoose, pSymm;
+       int                             _ND = 4;
+       NDat                    N[] = new NDat[_ND];
 
        Noise(GLucose glucose) {
                super(glucose);
@@ -70,8 +70,8 @@ public class Noise extends DPat
        void onActive() { zTime = random(500); zTheta=0; rtime = 0; ttime = 0; }
 
        void StartRun(double deltaMs) {
-               zTime   += deltaMs*(pSpeed.Val()-.5)*.002       ;
-               zTheta  += deltaMs*(pSpin .Val()-.5)*.01        ;
+               zTime   += deltaMs*(val(pSpeed)-.5)*.002        ;
+               zTheta  += deltaMs*(val(pSpin )-.5)*.01 ;
                rtime   += deltaMs;
                iSymm    = pSymm.Cur();
                zSin    = sin(zTheta);
@@ -85,19 +85,19 @@ public class Noise extends DPat
                        
                        switch(CurAnim) {
                        //                          hue xz yz zz den mph angle
-                       case 0: N[0].set(0  ,75 ,75 ,150,45 ,3  ,0  ); pSharp.set(1 ); break;   // drip
-                       case 1: N[0].set(0  ,100,100,200,45 ,3  ,180); pSharp.set(0 ); break;   // clouds
-                       case 2: N[0].set(0  ,2  ,400,2  ,20 ,3  ,0  ); pSharp.set(.5); break;   // rain
+                       case 0: N[0].set(0  ,75 ,75 ,150,45 ,3  ,0  ); pSharp.setValue(1 ); break;      // drip
+                       case 1: N[0].set(0  ,100,100,200,45 ,3  ,180); pSharp.setValue(0 ); break;      // clouds
+                       case 2: N[0].set(0  ,2  ,400,2  ,20 ,3  ,0  ); pSharp.setValue(.5); break;      // rain
                        case 3: N[0].set(40 ,100,100,200,10 ,1  ,180); 
-                                       N[1].set(0  ,100,100,200,10 ,5  ,180); pSharp.set(0 ); break;   // fire 1
+                                       N[1].set(0  ,100,100,200,10 ,5  ,180); pSharp.setValue(0 ); break;      // fire 1
                        case 4: N[0].set(0  ,40 ,40 ,40 ,15 ,2.5,180);
                                        N[1].set(20 ,40 ,40 ,40 ,15 ,4  ,0  );
                                        N[2].set(40 ,40 ,40 ,40 ,15 ,2  ,90 );
-                                       N[3].set(60 ,40 ,40 ,40 ,15 ,3  ,-90); pSharp.set(.5); break; // machine
+                                       N[3].set(60 ,40 ,40 ,40 ,15 ,3  ,-90); pSharp.setValue(.5); break; // machine
                        case 5: N[0].set(0  ,400,100,2  ,15 ,3  ,90 );
                                        N[1].set(20 ,400,100,2  ,15 ,2.5,0  );
                                        N[2].set(40 ,100,100,2  ,15 ,2  ,180);
-                                       N[3].set(60 ,100,100,2  ,15 ,1.5,270); pSharp.set(.5); break; // spark
+                                       N[3].set(60 ,100,100,2  ,15 ,1.5,270); pSharp.setValue(.5); break; // spark
                        }
                }
                
@@ -114,8 +114,8 @@ public class Noise extends DPat
                if (CurAnim == 6 || CurAnim == 7) {
                        P.setNorm();
                        return lx.hsb(lxh(),100, 100 * (
-                                                       constrain(1-50*(1-pDensity.Val())*abs(P.y-sin(zTime*10  + P.x*(300))*.5 - .5),0,1) + 
-                       (CurAnim == 7 ? constrain(1-50*(1-pDensity.Val())*abs(P.x-sin(zTime*10  + P.y*(300))*.5 - .5),0,1) : 0))
+                                                       constrain(1-50*(1-val(pDensity))*abs(P.y-sin(zTime*10  + P.x*(300))*.5 - .5),0,1) + 
+                       (CurAnim == 7 ? constrain(1-50*(1-val(pDensity))*abs(P.x-sin(zTime*10  + P.y*(300))*.5 - .5),0,1) : 0))
                        );
                }                       
 
@@ -131,7 +131,7 @@ public class Noise extends DPat
                                                                                 : noise(P.x/n.xz+zx+n.xoff,P.y/n.yz+zy+n.yoff,P.z/n.zz+n.zoff))
                                                        *1.8;
 
-                       b +=    n.den/100 -.4 + pDensity.Val() -1;
+                       b +=    n.den/100 -.4 + val(pDensity) -1;
                        c =     blendColor(c,lx.hsb(lxh()+n.hue,100,c1c(b)),ADD);
                }
                return c;
@@ -158,7 +158,7 @@ public class Play extends DPat
        }
 
        int             nBeats  =       0;
-       DParam  pAmp, pRadius, pBounce;
+       BasicParameter  pAmp, pRadius, pBounce;
 
        float   t,amp,rad,bnc;
        float   zTheta=0;
@@ -222,12 +222,12 @@ public class Play extends DPat
 
        void StartRun(double deltaMs) {
                t       = lx.tempo.rampf();
-               amp = pAmp.Val();
-               rad     = pRadius.getValuef();
-               bnc     = pBounce.getValuef();          
-               zTheta  += deltaMs*(pSpin .Val()-.5)*.01;
+               amp = pAmp              .getValuef();
+               rad     = pRadius       .getValuef();
+               bnc     = pBounce       .getValuef();           
+               zTheta  += deltaMs*(val(pSpin)-.5)*.01;
 
-               Theta   .set(pRotX.Val()*PI*2, pRotY.Val()*PI*2, pRotZ.Val()*PI*2 + zTheta);
+               Theta   .set(val(pRotX)*PI*2, val(pRotY)*PI*2, val(pRotZ)*PI*2 + zTheta);
                TSin    .set(sin(Theta.x), sin(Theta.y), sin(Theta.z));
                TCos    .set(cos(Theta.x), cos(Theta.y), cos(Theta.z));
 
@@ -375,8 +375,8 @@ class dCursor {
 
        boolean isDone  ()                                                                      { return pos==posStop;                                                                           }
        boolean atDest  ()                                                                      { return vCur.s==vDest.s || 
-                                                                                                                                pointDist(vCur.getPoint(0), vDest.getPoint(0)) < 12 || 
-                                                                                                                                pointDist(vCur.getPoint(0), vDest.getPoint(15))< 12;}
+                                                                                                                                xyDist(vCur.getPoint(0), vDest.getPoint(0)) < 12 || 
+                                                                                                                                xyDist(vCur.getPoint(0), vDest.getPoint(15))< 12;}
        void    setCur  (dVertex _v, int _p)                            { p2=null; vCur=_v; pos=_p; pickNext();                                          }
        void    setCur  (dPixel  _p)                                            { setCur(_p.v, _p.pos);                                                                          }
        void    setNext (dVertex _v, int _p, int _s)            { vNext = _v; posNext = _p<<12; posStop = _s<<12;                        }
@@ -392,7 +392,7 @@ class dCursor {
                if (bRandEval) {
                        if (random(nTurns) < 1) setNext(v,p,s); return; }
                else {
-                       float d = pointDist(v.getPoint(15), vDest.getPoint(0));
+                       float d = xyDist(v.getPoint(15), vDest.getPoint(0));
                        if (d <  minDist)                                       { minDist=d; setNext(v,p,s); }
                        if (d == minDist && random(2)<1)        { minDist=d; setNext(v,p,s); }
                }
@@ -407,7 +407,9 @@ class dCursor {
        void    pickNext()      {
                bRandEval = random(.05+destSpeed) < .05; minDist=500; nTurns=0;
                evaluate(vCur.c0, 0, 16);       evaluate(vCur.c1, 0, 16);
+               evaluate(vCur.c2, 0, 16);       evaluate(vCur.c3, 0, 16);
                evalTurn(vCur.t0);                      evalTurn(vCur.t1);
+               evalTurn(vCur.t2);                      evalTurn(vCur.t3);
        }
 
        Point   p1, p2; int i2;
index 097c61f38598afd49e1ad284310122444e6f3d6d..4d922940fa907b1e47bd48c0f4060976d2fae5df 100644 (file)
@@ -6,8 +6,9 @@ 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   pointDist(Point p1, Point p2) { return dist(p1.x,p1.y,p1.z,p2.x,p2.y,p2.z); }
+float  min             (float a, float b, float c, float d) { return min(min(a,b),min(c,d));   }
+float   pointDist(Point p1, Point p2) { return dist(p1.x,p1.y,p1.z,p2.x,p2.y,p2.z);    }
+float   xyDist   (Point p1, Point p2) { return dist(p1.x,p1.y,p2.x,p2.y);                              }
 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;
@@ -57,12 +58,6 @@ public class DBool {
        }
 }
 
-public class DParam extends BasicParameter {
-       double  dflt;
-       DParam  (String label, double value)            { super(label,value); dflt=value;               }
-       void    set                     (double value)                  { super.setValue(value);                                }
-       float   Val                     ()                                              { return getValuef();                                   }
-}
 //----------------------------------------------------------------------------------------------------------------------------------
 public class xyz {     float x,y,z;    // extends pVector; eliminate half of the functions
                        xyz() {x=y=z=0;}
@@ -111,7 +106,6 @@ public class DPat extends SCPattern
 {
        ArrayList<Pick>   picks  = new ArrayList<Pick>  ();
        ArrayList<DBool>  bools  = new ArrayList<DBool> ();
-       ArrayList<DParam> params = new ArrayList<DParam>();
 
        MidiOutput  APCOut;
        int                     nMaxRow         = 53;
@@ -121,9 +115,9 @@ public class DPat extends SCPattern
        xyz                     xyzJog = new xyz(), vT1 = new xyz(), vT2 = new xyz();
        xyz                     modmin;
 
-       float           NoiseMove       = random(10000);
-       DParam          pSpark, pWave, pRotX, pRotY, pRotZ, pSpin, pTransX, pTransY;
-       DBool           pXsym, pYsym, pRsym, pXdup, pXtrip, pJog, pGrey;
+       float                   NoiseMove       = random(10000);
+       BasicParameter  pSpark, pWave, pRotX, pRotY, pRotZ, pSpin, pTransX, pTransY;
+       DBool                   pXsym, pYsym, pRsym, pXdup, pXtrip, pJog, pGrey;
 
        float           lxh             ()                                                      { return lx.getBaseHuef();                                      }
        int                     c1c              (float a)                                      { return round(100*constrain(a,0,1));           }
@@ -132,15 +126,12 @@ public class DPat extends SCPattern
        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 lx.hsb(0,0,0);                 }
-       color           blend3(color c1, color c2, color c3){ return blendColor(c1,blendColor(c2,c3,ADD),ADD);                                          }
+       void            StartRun(double deltaMs)                        { }
+       color           CalcPoint(xyz p)                                        { return lx.hsb(0,0,0); }
+       color           blend3(color c1, color c2, color c3){ return blendColor(c1,blendColor(c2,c3,ADD),ADD); }
+       float           val             (BasicParameter p)                      { return p.getValuef(); }
 
-       DParam          addParam(String label, double value) {
-               DParam P = new DParam(label, value);
-               super.addParameter(P);
-               params.add(P); return P;
-       }
+       BasicParameter  addParam(String label, double value) { return new BasicParameter(label, value); }
 
        Pick            addPick(String name, int def, int _max, String[] desc) {
                Pick P          = new Pick(name, def, _max+1, nMaxRow, desc); 
@@ -165,7 +156,6 @@ public class DPat extends SCPattern
 
        void            onInactive()                    { uiDebugText.setText(""); }
        void            onReset()                               {
-               for (int i=0; i<params.size(); i++) params.get(i).reset();
                for (int i=0; i<bools .size(); i++) bools.get(i).reset();
                for (int i=0; i<picks .size(); i++) picks.get(i).reset();
                presetManager.dirty(this); 
@@ -230,7 +220,7 @@ public class DPat extends SCPattern
                NoiseMove       += deltaMs; NoiseMove = NoiseMove % 1e7;
                StartRun                (deltaMs);
                xyz P                   = new xyz(), tP = new xyz(), pSave = new xyz();
-               xyz pTrans              = new xyz(pTransX.Val()*200-100, pTransY.Val()*100-50,0);
+               xyz pTrans              = new xyz(val(pTransX)*200-100, val(pTransY)*100-50,0);
                nPoint  = 0;
 
                if (pJog.b) {
@@ -240,7 +230,7 @@ public class DPat extends SCPattern
                }
 
                // precalculate this stuff
-               float wvAmp = pWave.Val(), sprk = pSpark.Val();
+               float wvAmp = val(pWave), sprk = val(pSpark);
                if (wvAmp > 0) {
                        for (int i=0; i<ceil(mMax.x)+1; i++)
                                yWaveNz[i] = wvAmp * (noise(i/(mMax.x*.3)-(2e3+NoiseMove)/1500.) - .5) * (mMax.y/2.);
@@ -278,10 +268,10 @@ class dTurn {
 }
 
 class dVertex {
-       dVertex c0, c1,                 // connections on the cube
-                       opp, same;              // opp - same strip, opp direction
-                                                       // same - same strut, diff strip, dir
-       dTurn   t0, t1;
+       dVertex c0, c1, c2, c3,         // connections on the cube
+                       opp, same;                      // opp - same strip, opp direction
+                                                               // same - same strut, diff strip, dir
+       dTurn   t0, t1, t2, t3;
        Strip   s;
        int     dir, ci;                // dir -- 1 or -1.
                                                        // ci  -- color index
@@ -293,18 +283,30 @@ class dVertex {
 //----------------------------------------------------------------------------------------------------------------------------------
 class dPixel   { dVertex v; int pos; dPixel(dVertex _v, int _pos) { v=_v; pos=_pos; } }
 class dLattice {
-       void    addTurn(dVertex v0, int pos0, dVertex v1, int pos1) {   dTurn t = new dTurn(pos0, v1, pos1); if (v0.t0 == null) v0.t0=t; else v0.t1=t; }
+       void    addTurn  (dVertex v0, int pos0, dVertex v1, int pos1) { dTurn t = new dTurn(pos0, v1, pos1); 
+                                                                                                                                       if (v0.t0 == null) { v0.t0=t; return; }
+                                                                                                                                       if (v0.t1 == null) { v0.t1=t; return; }
+                                                                                                                                       if (v0.t2 == null) { v0.t2=t; return; }
+                                                                                                                                       if (v0.t3 == null) { v0.t3=t; return; }
+                                                                                                                               }
        float   dist2    (Strip s1, int pos1, Strip s2, int pos2)       {       return pointDist(s1.points.get(pos1), s2.points.get(pos2)); }
        float   pd2      (Point p1, float x, float y, float z)          {       return dist(p1.x,p1.y,p1.z,x,y,z); }
        boolean sameSame (Strip s1, Strip s2)                                           {       return max(dist2(s1, 0, s2, 0), dist2(s1,15, s2,15)) < 5 ;      }       // same strut, same direction
        boolean sameOpp  (Strip s1, Strip s2)                                           {       return max(dist2(s1, 0, s2,15), dist2(s1,15, s2,0 )) < 5 ;      }       // same strut, opp direction
        boolean sameBar  (Strip s1, Strip s2)                                           {       return sameSame(s1,s2) || sameOpp(s1,s2);                                       }       // 2 strips on same strut
+
+
        void    addJoint (dVertex v1, dVertex v2) {
                // should probably replace parallel but further with the new one
                if (v1.c0 != null && sameBar(v2.s, v1.c0.s)) return;
                if (v1.c1 != null && sameBar(v2.s, v1.c1.s)) return;
+               if (v1.c2 != null && sameBar(v2.s, v1.c2.s)) return;
+               if (v1.c3 != null && sameBar(v2.s, v1.c3.s)) return;
+
                if              (v1.c0 == null) v1.c0 = v2; 
                else if (v1.c1 == null) v1.c1 = v2; 
+               else if (v1.c2 == null) v1.c2 = v2; 
+               else if (v1.c3 == null) v1.c3 = v2;
        }
 
        dVertex v0(Strip s) { return (dVertex)s.obj1; }
@@ -358,7 +360,6 @@ class dLattice {
                        if (d>5) continue;
                        addTurn(v0(s1), pos1, v0(s2), pos2); addTurn(v1(s1), 15-pos1, v0(s2), pos2); 
                        addTurn(v0(s2), pos2, v0(s1), pos1); addTurn(v1(s2), 15-pos2, v0(s1), pos1);
-
                }}
        }
 }