new pattern (Worms) for lattice
authorbb3dan <github@bb3systems.com>
Fri, 4 Oct 2013 23:27:55 +0000 (19:27 -0400)
committerbb3dan <github@bb3systems.com>
Fri, 4 Oct 2013 23:27:55 +0000 (19:27 -0400)
DanHorwitz.pde
SugarCubes.pde
_Internals.pde
_Mappings.pde

index 3d72b5fddfd68c49beff96b763fc5a713c708284..2ea3991b4377f967c94ecb04976537f0cca98022 100755 (executable)
@@ -165,7 +165,7 @@ public class Play extends DPat
        float   t,amp,rad,bnc;\r
        float   zTheta=0;\r
        ArrayList<rWave> waves = new ArrayList<rWave>(10);\r
-       \r
+\r
        rAngle  a1 = new rAngle(), a2 = new rAngle(),\r
                        a3 = new rAngle(), a4 = new rAngle();\r
        xyz             cPrev   = new xyz(), cRand      = new xyz(),\r
@@ -185,7 +185,8 @@ public class Play extends DPat
                pBounce         = addParam("Bnc"        , .2    );\r
            pAmp                = addParam("Amp"        , .2    );\r
                pTempoMult      = addPick ("TMult"      , 0 , 5         , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand"   }       );\r
-               pTimePattern= addPick ("TPat"   , 6 , 7         , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel", "Deccel", "Slide", "Rand"}   );\r             pShape          = addPick ("Shape"      , 3 , 15        , new String[] {"Line", "Tap", "V", "RandV",\r
+               pTimePattern= addPick ("TPat"   , 6 , 7         , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel", "Deccel", "Slide", "Rand"}   );\r
+               pShape          = addPick ("Shape"      , 3 , 15        , new String[] {"Line", "Tap", "V", "RandV",\r
                                                                                                                                        "Pyramid", "Wings", "W2", "Clock",\r
                                                                                                                                        "Triangle", "Quad", "Sphere", "Cone",\r
                                                                                                                                        "Noise", "Wave", "?", "?"}                                              );\r
@@ -347,3 +348,224 @@ public class Play extends DPat
        }\r
 }\r
 //----------------------------------------------------------------------------------------------------------------------------------\r
+// 0 - TLB, L (b), BLB, B (l)          // Fwd , Down, Back, Up\r
+// 4 - TLF, F (l), BLF, L (f)          // Fwd , Down, Back, Up\r
+// 8 - TRF, R (f), BRF, F (r)          // Back, Down, Fwd , Up\r
+// 12- TRB, B (r), BRB, R (b)          // Back, Down, Fwd , Up\r
+// 1->7, 15->9\r
+\r
+class dBolt {\r
+       dStrip v, h;\r
+       int    vpos, hpos;\r
+       dBolt(dStrip _v, dStrip _h, int _vpos, int _hpos) {\r
+               v=_v; h=_h; vpos=_vpos; hpos=_hpos;\r
+               if (v.b0 == null) { v.b0=this; h.b0=this; } \r
+               else                      { v.b1=this; h.b1=this; }\r
+       }\r
+}\r
+\r
+class dVertex {\r
+       dStrip  s1      , s2    ;\r
+       int     dir1, dir2      ;\r
+       dVertex(dStrip s, int d) {\r
+               int _a = (s.iS%4==1)? (d==1? 5: 3) :\r
+                                (s.iS%4==3)? (d==1? 9:11) :\r
+                                (d==1)         ? (s.Top()?4:12)   : (s.Top()?12:4);\r
+               dir1 = d * (s.isVert() ? -1 : 1);\r
+               dir2 = d;\r
+               s1       = DL_.DS[s.iCube() + ((s.iS+_a) % 16)];\r
+               s2       = DL_.DS[d == 1 ?      (s.idx == s.iFace()+3 ? s.idx-3 : s.idx+1):\r
+                                                               (s.idx == s.iFace()   ? s.idx+3 : s.idx-1)];\r
+               swapout(1 , 6);\r
+               swapout(15,-6);\r
+       }\r
+       void swapout(int a, int b) {\r
+               if (s1.iS == a) { s1 = DL_.DS[s1.idx + b]; dir1 = -dir1; }\r
+               if (s2.iS == a) { s2 = DL_.DS[s2.idx + b]; dir2 = -dir2; }\r
+       }\r
+\r
+}\r
+\r
+class dStrip  { // THIS WAS SUCH A PAIN!\r
+       int row, col, ci, idx, iS, axis;        // 1-y, 2-left, 3-right\r
+       Strip s; \r
+       boolean bTop;   // direction: top ccw, bottom cw.\r
+\r
+       boolean Top   (){       return axis!=1 &&  bTop ;               }\r
+       boolean Bottom(){       return axis!=1 && !bTop;                }\r
+       boolean isVert(){       return axis==1;                                 }\r
+       boolean isHorz(){       return axis!=1;                                 }\r
+       int     iCube (){       return 16*floor(idx/16);                }\r
+       int     iFace (){       return iCube() + 4*floor(iS/4); }\r
+\r
+       void    init(Strip _s, int _i, int _row, int _col)  {\r
+               idx = _i; row = _row; col = _col; s = _s;\r
+               iS      = idx%16; bTop = (iS%4==0);\r
+               ci  = s.points.get(0).index;\r
+               DL_.DQ[col][row] = iCube();\r
+               switch (iS) {\r
+                       case 4: case 6 : case 12: case 14:      axis=2; break;\r
+                       case 0: case 2 : case 8 : case 10:      axis=3; break;\r
+                       default:                                                        axis=1; break;\r
+               }\r
+       }\r
+\r
+       void addBolts() {\r
+               v0 = new dVertex(this, 1);\r
+               v1 = new dVertex(this,-1);\r
+\r
+\r
+               if (iS == 7 && col != 0 && row != 0)                                                                    // left bottom\r
+                       new dBolt(this, DL_.GetStrip(row-1,col-1,(col % 2 == 1) ? 8 : 12),  \r
+                                                       4, (col % 2 == 1) ? 6 : 9);     \r
+\r
+               if (iS == 7 && col != 0 && row < MaxCubeHeight*2-2)                                     // left top\r
+                       new dBolt(this, DL_.GetStrip(row+1,col-1,(col % 2 == 1) ? 10 : 14), \r
+                                                       11, (col % 2 == 1) ? 9 : 6);\r
+\r
+               if (iS == 9 && col < NumBackTowers-1 && row < MaxCubeHeight*2-2)                // right top\r
+                       new dBolt(this, DL_.GetStrip(row+1,col+1,(col % 2 == 1) ? 6 : 2), \r
+                                                       4, (col % 2 == 1) ? 6 : 9);\r
+\r
+               if (iS == 9 && col < NumBackTowers-1 && row != 0)                                               // right bottom\r
+                       new dBolt(this, DL_.GetStrip(row-1,col+1,(col % 2 == 1) ? 4 : 0), \r
+                                                       11, (col % 2 == 1) ? 9 : 6);\r
+       }\r
+\r
+       dBolt   b0, b1;\r
+       dVertex v0, v1;\r
+}\r
+\r
+class dCursor {\r
+       dStrip  s, sNext;\r
+       int     nLast,pos,posNext,end;  // 0 - 65535\r
+       int     dir;                    // 1 or -1\r
+       color   clr;\r
+       \r
+       dCursor(color _c) { clr=_c;}\r
+\r
+       boolean isDone()                                        { return pos==end; }\r
+       void    set(dStrip _s, int _dir)        { \r
+                       s=_s; dir=_dir; pos = 0; end=65536; nLast=-1; sNext=null;\r
+       }\r
+\r
+       boolean MakeTurn(dBolt b) {\r
+               int nEnd=       (s.isVert() ? b.vpos : b.hpos) <<12;\r
+                       nEnd=   (dir==1 ? nEnd : 65536-nEnd);\r
+               if (nEnd < pos) return false;\r
+               if (s.isVert()) { sNext = b.h; posNext = b.hpos<<12; end = nEnd; }\r
+               else                    { sNext = b.v; posNext = b.vpos<<12; end = nEnd; }\r
+               return true;\r
+       }\r
+\r
+       void    PickNext()      {\r
+               if (sNext != null) {\r
+                       if (end == 65536) exit();\r
+                       end                     = 65536;        \r
+                       pos                     = posNext;\r
+                       dir                     = randDir(); \r
+                       if (dir<0) pos = end-pos;\r
+                       s                       = sNext; sNext = null;\r
+                       nLast           = -1;\r
+                       return;// could switch again!!\r
+               } else {\r
+                       dVertex v = (dir == 1 ? s.v0 : s.v1);\r
+                       int r = floor(random(2));\r
+                       set(r==0 ? v.s1 : v.s2,r==0 ? v.dir1 : v.dir2);\r
+               }\r
+\r
+               // plan to turn the corner\r
+               if (random(6)<1 && s.b0 != null && MakeTurn(s.b0)) return;\r
+               if (random(6)<1 && s.b1 != null && MakeTurn(s.b1)) return;\r
+       }\r
+}\r
+\r
+int randDir() { return round(random(1))*2-1; }\r
+\r
+class dLattice {\r
+       int             iTowerStrips=-1;\r
+       dStrip[]        DS = new dStrip[glucose.model.strips.size()];\r
+       int[][]         DQ = new int[NumBackTowers][MaxCubeHeight*2];\r
+\r
+       int             nStrips() { return iTowerStrips; }\r
+       dStrip GetStrip (int row, int col, int off) { return DS[DQ[col][row]+off]; }\r
+       dLattice() {\r
+               DL_=this;\r
+               int   col = 0, row = -2, i=-1;\r
+               for (Strip strip : glucose.model.strips  ) { i++; \r
+                       if (i % 16 == 0) row+=2;\r
+                       if (row >= MaxCubeHeight*2-1) { col++; row = (col%2==1)?1:0; }\r
+                       if (col >= NumBackTowers) continue;\r
+                       iTowerStrips++  ;\r
+                       dStrip s = DS[iTowerStrips] = new dStrip();\r
+                       s.init(strip, iTowerStrips, row, col);\r
+               }\r
+\r
+               for (int j=0; j<iTowerStrips; j++) DS[j].addBolts();\r
+       }\r
+       dStrip  rand()                          { return DS[floor(random(iTowerStrips))];               }\r
+       void    setRand(dCursor c)      { c.set(rand(),randDir());                      }\r
+}\r
+\r
+dLattice DL_;\r
+//----------------------------------------------------------------------------------------------------------------------------------\r
+class Graph extends SCPattern {\r
+\r
+       int draw(dCursor c, int nAmount) {\r
+               int nFrom       = max(c.nLast+1,c.pos >> 12);\r
+               int     nTo     = min(15,(c.pos+nAmount) >> 12); c.nLast=nTo;\r
+               int     nMv     = min(nAmount, c.end-c.pos);\r
+                       c.pos   += nMv;\r
+               for (int i = nFrom; i <= nTo; i++) {\r
+                       int n = c.s.ci + (c.dir>0 ? i : 15-i);\r
+                       colors[n] = c.clr;\r
+               }\r
+               return nAmount - nMv;\r
+       }\r
+\r
+       float   StripsPerSec    = 6;\r
+       float   TrailTime               = 1500;\r
+       int     Cursors                 = 40;\r
+       dCursor cur[] = new dCursor[Cursors];\r
+\r
+       Graph(GLucose glucose) { \r
+               super(glucose); \r
+               if (DL_ == null) DL_ = new dLattice();\r
+               for (int i=0; i<Cursors; i++) { cur[i] = new dCursor(color(random(360),50+random(50),50+random(50))); DL_.setRand(cur[i]); }\r
+       }\r
+\r
+       void run(double deltaMs) {\r
+                       //Test Joints\r
+               if (false) {\r
+                       for (int j=0; j<DL_.nStrips(); j++) {\r
+                                               dStrip s =DL_.DS[j]; dBolt d = s.b0;\r
+                                               if (d != null) {for (int i=0;i<16;i++) {\r
+                                                       if (s == d.v && i <= d.vpos) colors[d.v.ci+i]   = color(0,0,30);\r
+                                                       if (s == d.h && i <= d.hpos) colors[d.h.ci+i]   = color(0,0,30);\r
+                                               }}\r
+\r
+                                               d = s.b1; \r
+                                               if (d != null) {for (int i=0;i<16;i++) {\r
+                                                       if (s == d.v && i >= d.vpos) colors[d.v.ci+i]   = color(0,0,30);\r
+                                                       if (s == d.h && i >= d.hpos) colors[d.h.ci+i]   = color(0,0,30);\r
+                                               }}\r
+                       }\r
+               } else {\r
+                       for (int i=0; i<Cursors; i++) {\r
+                               int nLeft = floor((float)deltaMs*.001*StripsPerSec * 65536);\r
+                               while(nLeft > 0) {      \r
+                                       nLeft = draw(cur[i], nLeft);\r
+                                       if (cur[i].isDone()) cur[i].PickNext(); \r
+                               }\r
+                       }\r
+\r
+                       for (int i=0,s=model.points.size(); i<s; i++) {\r
+                               float b = brightness(colors[i]); \r
+                               color c = colors[i];\r
+                               if (b>0) colors[i] = color(hue(c), saturation(c), \r
+                                               (float)(b-100*deltaMs/TrailTime));\r
+                       }\r
+               }\r
+       }\r
+}\r
+//----------------------------------------------------------------------------------------------------------------------------------\r
index 0f5ca26c08a6c07597df45d2f822d8e72329c2f4..bf545b533d69984bfb0dde20bc1d5d2eabf0876f 100644 (file)
 
 LXPattern[] patterns(GLucose glucose) {
   return new LXPattern[] {
+
     
     // Slee
+    new Swarm(glucose),
     new ViolinWave(glucose),
     new BouncyBalls(glucose),
-    new Swarm(glucose),
     new SpaceTime(glucose),
     new ShiftingPlane(glucose),
     new AskewPlanes(glucose),
@@ -44,8 +45,9 @@ LXPattern[] patterns(GLucose glucose) {
 
     // DanH
     new Noise(glucose),
-    new Play(glucose),
-    new Pong(glucose),
+    new Play (glucose),
+    new Pong (glucose),
+    new Worms(glucose),
 
     // Alex G
     new SineSphere(glucose),
index 4dd145a80d62964c190e6ff1bea08d84261c53a6..5738ed21078afa6f64ef7ed42c3bb1c7897bdad3 100644 (file)
@@ -39,6 +39,9 @@ final float TRAILER_WIDTH = 240;
 final float TRAILER_DEPTH = 97;
 final float TRAILER_HEIGHT = 33;
 
+final int MaxCubeHeight = 7;
+final int NumBackTowers = 9;
+
 int targetFramerate = 60;
 int startMillis, lastMillis;
 
index 6a6294edab9c02fd8a6a44de714451f65867a441..9e487f0cf2656c455529a925d3b01462051894a5 100644 (file)
@@ -71,18 +71,19 @@ public Model buildModel() {
 
   ////////////////////////////////////////////////////////////////////////
   // dan's proposed lattice
-  ArrayList<StaggeredTower> scubes = new ArrayList<StaggeredTower>();
-  for (int i=0; i<9; i++) scubes.add(new StaggeredTower(
-               (i+1)*CW,                                                // x
-               (i % 2 == 0) ? 0 : CH * 2./3.,   // y
-        - ((i % 2 == 0) ? 0 : 11) + 97  ,   // z
-          -135, (i % 2 == 0) ? 7 : 6));         // num cubes
-
-  ArrayList<Cube> dcubes = new ArrayList<Cube>();
-  for (int i=0; i<7; i++) {
-       if (i>0) dcubes.add(new Cube(-6+CW*4/3*i             , 0, 0, 0, 0, 0, WRR));    
-                        dcubes.add(new Cube(-6+CW*4/3*i+CW*2/3., CH*.5, 0, 0, 0, 0, WRR));     
-  }
+       ArrayList<StaggeredTower> scubes = new ArrayList<StaggeredTower>();
+       if (NumBackTowers != 9) exit();
+       for (int i=0; i<NumBackTowers; i++) scubes.add(new StaggeredTower(
+                 (i+1)*CW,                                                             // x
+                 (i % 2 == 0) ? 0 : CH * 2./3.         ,   // y
+                - ((i % 2 == 0) ? 0 : 11) + 97         ,   // z
+                -135, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight-1));         // num cubes
+       
+       ArrayList<Cube> dcubes = new ArrayList<Cube>();
+       for (int i=1; i<6; i++) {
+               if (i>1) dcubes.add(new Cube(-6+CW*4/3*i             , 0, 0, 0, 0, 0, WRR));    
+                                dcubes.add(new Cube(-6+CW*4/3*i+CW*2/3., CH*.5, 0, 0, 0, 0, WRR));     
+       }
 
   //////////////////////////////////////////////////////////////////////
   //      BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!!        //
@@ -91,7 +92,7 @@ public Model buildModel() {
   // These guts just convert the shorthand mappings into usable objects
   ArrayList<Tower> towerList = new ArrayList<Tower>();
   ArrayList<Cube> tower;
-  Cube[] cubes = new Cube[80];
+  Cube[] cubes = new Cube[100];
   int cubeIndex = 1;  
   float px, pz, ny;
   for (TowerMapping tm : towerCubes) {
@@ -106,9 +107,6 @@ public Model buildModel() {
     towerList.add(new Tower(tower));
   }
 
-  for (Cube cube : singleCubes) cubes[cubeIndex++] = cube;
-  for (Cube cube : dcubes)             cubes[cubeIndex++] = cube;
-
   for (StaggeredTower st : scubes) {
     tower = new ArrayList<Cube>();
     for (int i=0; i < st.n; i++)
@@ -116,7 +114,10 @@ public Model buildModel() {
     towerList.add(new Tower(tower));
   }
 
-  return new Model(towerList, cubes, bassBox, speakers);
+  for (Cube cube : singleCubes) cubes[cubeIndex++] = cube;
+  for (Cube cube : dcubes)             cubes[cubeIndex++] = cube;
+
+ return new Model(towerList, cubes, bassBox, speakers);
 }
 
 /**