Merge branch 'master' of https://github.com/sugarcubes/SugarCubes into realmapping
authorMark Slee <mcslee@Mark-Slees-MacBook-Pro.local>
Wed, 21 Aug 2013 07:49:30 +0000 (00:49 -0700)
committerMark Slee <mcslee@Mark-Slees-MacBook-Pro.local>
Wed, 21 Aug 2013 08:09:45 +0000 (01:09 -0700)
Conflicts:
code/GLucose.jar
code/HeronLX.jar

JackStahl.pde
ShaheenGandhi.pde
SugarCubes.pde
_Mappings.pde
_PandaDriver.pde
code/GLucose.jar
code/HeronLX.jar

index 9cd6bf145dacb473d2b04d8ec84b517ca807eee5..05e2ec66e7c1ebdee6de1147ca31f60e87a11875 100644 (file)
@@ -73,9 +73,9 @@ class Swim extends SCPattern {
  * The idea here is to do another sin wave pattern, but with less rotation and more of a breathing / heartbeat affect with spheres above / below the wave.
  * This is not done.
  */
-class Breathe extends SCPattern {
+class Balance extends SCPattern {
 
-  final BasicParameter hueScale = new BasicParameter("HUE", 0.3);
+  final BasicParameter hueScale = new BasicParameter("Hue", 0.4);
 
   class Sphere {
     float x, y, z;
@@ -85,22 +85,28 @@ class Breathe extends SCPattern {
   // Projection stuff
   private final Projection projection;
 
-  SinLFO sphere1Z = new SinLFO(0, 80, 15323);
-  SinLFO sphere2Z = new SinLFO(-80, 0, 8323);
-  SawLFO rotation = new SawLFO(- PI / 16, PI / 16, 7334);
+  SinLFO sphere1Z = new SinLFO(0, 0, 15323);
+  SinLFO sphere2Z = new SinLFO(0, 0, 8323);
+  SinLFO rotationX = new SinLFO(-PI/32, PI/32, 9000);
+  SinLFO rotationY = new SinLFO(-PI/16, PI/16, 7000);
+  SinLFO rotationZ = new SinLFO(-PI/16, PI/16, 11000);
+  SawLFO phaseLFO = new SawLFO(0, 2 * PI, 5000 - 4500 * 0.5);
+  final BasicParameter phaseParam = new BasicParameter("Spd", 0.5);
+  final BasicParameter crazyParam = new BasicParameter("Crzy", 0.2);
 
 
   private final Sphere[] spheres;
   private final float centerX, centerY, centerZ, modelHeight, modelWidth, modelDepth;
-  SinLFO heightMod = new SinLFO(0.6, 1.85, 17298);
+  SinLFO heightMod = new SinLFO(0.8, 1.9, 17298);
 
-  public Breathe(GLucose glucose) {
+  public Balance(GLucose glucose) {
     super(glucose);
 
-    // Unused for now
     projection = new Projection(model);
 
     addParameter(hueScale);
+    addParameter(phaseParam);
+    addParameter(crazyParam);
 
     spheres = new Sphere[2];
     centerX = (model.xMax + model.xMin) / 2;
@@ -111,22 +117,33 @@ class Breathe extends SCPattern {
     modelDepth = model.zMax - model.zMin;
 
     spheres[0] = new Sphere();
-    spheres[0].x = 3*modelWidth/8;
-    spheres[0].y = centerY + 10;
+    spheres[0].x = 1*modelWidth/2 + model.xMin;
+    spheres[0].y = centerY + 20;
     spheres[0].z = centerZ;
 
     spheres[1] = new Sphere();
-    spheres[1].x = 7*modelWidth/8;
+    spheres[1].x = model.xMin;
     spheres[1].y = centerY - 20;
     spheres[1].z = centerZ;
 
+    addModulator(rotationX).trigger();
+    addModulator(rotationY).trigger();
+    addModulator(rotationZ).trigger();
+
 
     addModulator(sphere1Z).trigger();
     addModulator(sphere2Z).trigger();
+    addModulator(phaseLFO).trigger();
 
     addModulator(heightMod).trigger();
   }
 
+  public void onParameterChanged(LXParameter parameter) {
+    if (parameter == phaseParam) {
+      phaseLFO.setDuration(5000 - 4500 * parameter.getValuef());
+    }
+  }
+
   int beat = 0;
   float prevRamp = 0;
   void run(int deltaMs) {
@@ -137,10 +154,13 @@ class Breathe extends SCPattern {
       beat = (beat + 1) % 4;
     }
     prevRamp = ramp;
-    float phase = (beat+ramp) * PI % (2 * PI);
+    float phase = phaseLFO.getValuef();
 
+    float crazy_factor = crazyParam.getValuef() / 0.2;
     projection.reset(model)
-      .rotate(rotation.getValuef(), 0, 1, 0);
+      .rotate(rotationZ.getValuef() * crazy_factor,  0, 1, 0)
+        .rotate(rotationX.getValuef() * crazy_factor, 0, 0, 1)
+          .rotate(rotationY.getValuef() * crazy_factor, 0, 1, 0);
 
     for (Coord p : projection) {
       float x_percentage = (p.x - model.xMin)/modelWidth;
@@ -149,36 +169,37 @@ class Breathe extends SCPattern {
       float sin_x =  sin(PI / 2 + phase + 2 * PI * x_percentage);       
 
       // Color fade near the top of the sin wave
-      float v1 = sin_x > y_in_range  ? (100 + 100*(y_in_range - sin_x)) : 0;     
+      float v1 = max(0, 100 * (1 - 4*abs(sin_x - y_in_range)));     
 
-      float hue_color = (lx.getBaseHuef() + hueScale.getValuef() * (abs(p.x-model.xMax/2.)*.6 + abs(p.y-model.yMax/2)*.9 + abs(p.z - model.zMax/2.))) % 360;
-      color c = color(hue_color, 60, v1);
+      float hue_color = (lx.getBaseHuef() + hueScale.getValuef() * (abs(p.x-model.xMax/2.) + abs(p.y-model.yMax/2)*.2 + abs(p.z - model.zMax/2.)*.5)) % 360;
+      color c = color(hue_color, 80, v1);
 
       // Now draw the spheres
       for (Sphere s : spheres) {
-        float phase_x = (s.x - phase * modelWidth / ( 2 * PI)) % modelWidth;        
+        float phase_x = (s.x - phase / (2 * PI) * modelWidth) % modelWidth;    
         float x_dist = LXUtils.wrapdistf(p.x, phase_x, modelWidth);
 
         float sphere_z = (s == spheres[0]) ? (s.z + sphere1Z.getValuef()) : (s.z - sphere2Z.getValuef()); 
 
+
         float d = sqrt(pow(x_dist, 2) + pow(p.y - s.y, 2) + pow(p.z - sphere_z, 2));
-        float r = 25;
+
+        float distance_from_beat =  (beat % 2 == 1) ? 1 - ramp : ramp;
+
+        min(ramp, 1-ramp);
+
+        float r = 40 - pow(distance_from_beat, 0.75) * 20;
 
         float distance_value = max(0, 1 - max(0, d - r) / 10);
         float beat_value = 1.0;
-        if (s == spheres[0]) {
-          //          beat_value = .2 + ((beat % 4 >= 2) ? ((4 - (ramp + beat)) / 2) *.8 : 0);
-        } 
-        else {
-          //          beat_value = .2 + ((beat % 4 < 2) ? ((2 - (ramp + beat)) / 2) *.8 : 0);
-        } 
 
         float value = min(beat_value, distance_value);
 
-        c = blendColor(c, color((hue_color + 180) % 360, 100, min(1, value) * 100), ADD);
+        float sphere_color = (lx.getBaseHuef() - (1 - hueScale.getValuef()) * d/r * 45) % 360;
+
+        c = blendColor(c, color((sphere_color + 270) % 360, 60, min(1, value) * 100), ADD);
       }
       colors[p.index] = c;
     }
   }
 }
-
index 0bfef321c8d9a7d059022867c2422a62c9302129..2e9ead0005c425eaa0ff11b62b98b0028cd9554a 100644 (file)
@@ -149,24 +149,36 @@ class HelixPattern extends SCPattern {
       return color((lx.getBaseHuef() + (360*(phase / TWO_PI)))%360, 80, b);
     }
   }
+  
+  private class BasePairInfo {
+    Line line;
+    float colorPhase1;
+    float colorPhase2;
+    
+    BasePairInfo(Line line, float colorPhase1, float colorPhase2) {
+      this.line = line;
+      this.colorPhase1 = colorPhase1;
+      this.colorPhase2 = colorPhase2;
+    }
+  }
 
   private final Helix h1;
   private final Helix h2;
-  private final Line[] basePairs;
+  private final BasePairInfo[] basePairs;
 
   private final BasicParameter helix1On = new BasicParameter("H1ON", 1);
   private final BasicParameter helix2On = new BasicParameter("H2ON", 1);
   private final BasicParameter basePairsOn = new BasicParameter("BPON", 1);
 
   private static final float helixCoilPeriod = 100;
-  private static final float helixCoilRadius = 45;
-  private static final float helixCoilGirth = 20;
-  private static final float helixCoilRotationPeriod = 10000;
+  private static final float helixCoilRadius = 50;
+  private static final float helixCoilGirth = 30;
+  private static final float helixCoilRotationPeriod = 5000;
 
   private static final float spokePeriod = 40;
-  private static final float spokeGirth = 10;
+  private static final float spokeGirth = 20;
   private static final float spokePhase = 10;
-  private static final float spokeRadius = 35; // helixCoilRadius - helixCoilGirth*.5f;
+  private static final float spokeRadius = helixCoilRadius - helixCoilGirth*.5f;
   
   private static final float tMin = -200;
   private static final float tMax = 200;
@@ -178,7 +190,7 @@ class HelixPattern extends SCPattern {
     addParameter(helix2On);
     addParameter(basePairsOn);
 
-    PVector origin = new PVector(100, 50, 45);
+    PVector origin = new PVector(100, 50, 55);
     PVector axis = new PVector(1,0,0);
 
     h1 = new Helix(
@@ -196,16 +208,18 @@ class HelixPattern extends SCPattern {
       PI,
       helixCoilRotationPeriod);
       
-    basePairs = new Line[(int)floor((tMax - tMin)/spokePeriod)];
+    basePairs = new BasePairInfo[(int)floor((tMax - tMin)/spokePeriod)];
   }
 
   private void calculateSpokes() {
+    float colorPhase = PI/6;
     for (float t = tMin + spokePhase; t < tMax; t += spokePeriod) {
       int spokeIndex = (int)floor((t - tMin)/spokePeriod);
       PVector h1point = h1.pointOnToroidalAxis(t);
       PVector spokeCenter = h1.getAxis().getPointAt(t);
       PVector spokeVector = PVector.sub(h1point, spokeCenter);
-      basePairs[spokeIndex] = new Line(spokeCenter, spokeVector);
+      Line spokeLine = new Line(spokeCenter, spokeVector);
+      basePairs[spokeIndex] = new BasePairInfo(spokeLine, colorPhase * spokeIndex, colorPhase * (spokeIndex + 1));
     }
   }
   
@@ -220,10 +234,13 @@ class HelixPattern extends SCPattern {
     if (spokeIndex < 0 || spokeIndex >= basePairs.length) {
       return color(0,0,0);
     }
-    Line spokeLine = basePairs[spokeIndex];
+    BasePairInfo basePair = basePairs[spokeIndex];
+    Line spokeLine = basePair.line;
     PVector pointOnSpoke = spokeLine.projectPoint(pt);
-    float b = ((PVector.dist(pt, pointOnSpoke) < spokeGirth) && (PVector.dist(pointOnSpoke, spokeLine.getPoint()) < spokeRadius)) ? 100.f : 0.f;
-    return color(100, 80.f, b);
+    float d = PVector.dist(pt, pointOnSpoke);
+    float b = (PVector.dist(pointOnSpoke, spokeLine.getPoint()) < spokeRadius) ? constrain(100*(1 - ((d-.5*spokeGirth)/(spokeGirth*.5))), 0, 100) : 0.f;
+    float phase = spokeLine.getTValue(pointOnSpoke) < 0 ? basePair.colorPhase1 : basePair.colorPhase2;
+    return color((lx.getBaseHuef() + (360*(phase / TWO_PI)))%360, 80.f, b);
   }
 
   void run(int deltaMs) {
index 4681f2d639caf36a051640447bfb8a32ff28d14e..bc70626a384391726f08d3fff4c6d8d13401063d 100644 (file)
@@ -57,8 +57,9 @@ LXPattern[] patterns(GLucose glucose) {
 
     // Jack
     new Swim(glucose),
-    new Breathe(glucose),
+    new Balance(glucose),
 
+    // Tim
     new TimPlanes(glucose),
     new TimPinwheels(glucose),
     new TimRaindrops(glucose),
index 1a61a8a8807337e7e7f0cddf4182cbb905572b37..efe0e4c1aaa58076ca116c2e5d35c6def4ba8727 100644 (file)
@@ -109,14 +109,14 @@ public Model buildModel() {
 public PandaMapping[] buildPandaList() {
   return new PandaMapping[] {
     new PandaMapping(
-      "10.200.1.28", new ChannelMapping[] {
+      "10.200.1.29", new ChannelMapping[] {
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 7, 8 }),
+        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 9, 10 }),
         new ChannelMapping(ChannelMapping.MODE_BASS),
         new ChannelMapping(ChannelMapping.MODE_FLOOR),
         new ChannelMapping(ChannelMapping.MODE_SPEAKER, 0),
         new ChannelMapping(ChannelMapping.MODE_SPEAKER, 1),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1 }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
-        new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
         new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
         new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
         new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
@@ -126,7 +126,7 @@ public PandaMapping[] buildPandaList() {
     }),
 
     new PandaMapping(
-      "10.200.1.29", new ChannelMapping[] {
+      "10.200.1.28", new ChannelMapping[] {
         new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
         new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
         new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
index 62d4c94b46dc1ffe3438d96e7940132ceb819e6f..cd85e9b05e9738d051492aef097ec123dae857a3 100644 (file)
@@ -14,7 +14,7 @@ import oscP5.*;
  * This class implements the output function to the Panda Boards. It
  * will be moved into GLucose once stabilized.
  */
-public class PandaDriver {
+public static class PandaDriver {
 
   // IP address
   public final String ip;
@@ -50,18 +50,73 @@ public class PandaDriver {
     }
   }
 
+  private final static int FORWARD = -1;
+  private final static int BACKWARD = -2;
+
   /**
    * These constant arrays indicate the order in which the strips of a cube
    * are wired. There are four different options, depending on which bottom
    * corner of the cube the data wire comes in.
    */
-  private final int[][] CUBE_STRIP_ORDERINGS = new int[][] {
+  private final static int[][] CUBE_STRIP_ORDERINGS = new int[][] {
     {  2,  1,  0,  3, 13, 12, 15, 14,  4,  7,  6,  5, 11, 10,  9,  8 }, // FRONT_LEFT
     {  6,  5,  4,  7,  1,  0,  3,  2,  8, 11, 10,  9, 15, 14, 13, 12 }, // FRONT_RIGHT
     { 14, 13, 12, 15,  9,  8, 11, 10,  0,  3,  2,  1,  7,  6,  5,  4 }, // REAR_LEFT
     { 10,  9,  8, 11,  5,  4,  7,  6, 12, 15, 14, 13,  3,  2,  1,  0 }, // REAR_RIGHT
   };
-
+  
+  private final static int[][] BASS_STRIP_ORDERING = {
+    {0, FORWARD },
+    {1, FORWARD },
+    {2, FORWARD },
+    {3, FORWARD },
+    {4, FORWARD },
+    {5, FORWARD },
+    {6, FORWARD },
+    {7, FORWARD },
+    {8, FORWARD },
+    {9, FORWARD },
+    {10, FORWARD },
+    {11, FORWARD },
+    {12, FORWARD },
+    {13, FORWARD },
+    {14, FORWARD },
+    {15, FORWARD },
+    {16, FORWARD },
+    {17, FORWARD },
+    {18, FORWARD },
+    {19, FORWARD },
+    {20, FORWARD },
+    {21, FORWARD },
+    {22, FORWARD },            
+  };
+  
+  private final static int[][] FLOOR_STRIP_ORDERING = {
+    {0, FORWARD},
+    {1, FORWARD},
+    {2, FORWARD},
+    {3, FORWARD},
+  };
+  
+  private final static int[][] SPEAKER_STRIP_ORDERING = {
+    {0, FORWARD },
+    {1, FORWARD },
+    {2, FORWARD },
+    {3, FORWARD },
+    {4, FORWARD },
+    {5, FORWARD },
+    {6, FORWARD },
+    {7, FORWARD },
+    {8, FORWARD },
+    {9, FORWARD },
+    {10, FORWARD },
+    {11, FORWARD },
+    {12, FORWARD },
+    {13, FORWARD },
+    {14, FORWARD },
+    {15, FORWARD },
+  };
+  
   public PandaDriver(String ip, Model model, PandaMapping pm) {
     this(ip);
 
@@ -99,25 +154,29 @@ public class PandaDriver {
               for (int stripIndex : CUBE_STRIP_ORDERINGS[stripOrderIndex]) {
                 // We go backwards here... in the model strips go clockwise, but
                 // the physical wires are run counter-clockwise
-                Strip s = cube.strips.get(stripIndex);
-                for (int j = s.points.size() - 1; j >= 0; --j) {
-                  points[pi++] = s.points.get(j).index;
-                }
+                pi = mapStrip(cube.strips.get(stripIndex), BACKWARD, points, pi);
               }
             }
           }
           break;
           
         case ChannelMapping.MODE_BASS:
-          // TODO(mapping): figure out how we end up connecting the bass cabinet
+          for (int[] config : BASS_STRIP_ORDERING) {
+            pi = mapStrip(model.bassBox.strips.get(config[0]), config[1], points, pi);
+          }
           break;
           
-        case ChannelMapping.MODE_FLOOR:        
-          // TODO(mapping): figure out how these strips are wired
+        case ChannelMapping.MODE_FLOOR:
+          for (int[] config : FLOOR_STRIP_ORDERING) {
+            pi = mapStrip(model.boothFloor.strips.get(config[0]), config[1], points, pi);
+          }
           break;
           
         case ChannelMapping.MODE_SPEAKER:
-          // TODO(mapping): figure out how these strips are wired
+          for (int[] config : SPEAKER_STRIP_ORDERING) {
+            Speaker speaker = model.speakers.get(channel.objectIndices[0]);
+            pi = mapStrip(speaker.strips.get(config[0]), config[1], points, pi);
+          }
           break;
           
         case ChannelMapping.MODE_NULL:
@@ -130,6 +189,21 @@ public class PandaDriver {
 
     }
   }
+  
+  private int mapStrip(Strip s, int direction, int[] points, int pi) {
+    if (direction == FORWARD) {
+      for (Point p : s.points) {
+        points[pi++] = p.index;
+      }
+    } else if (direction == BACKWARD) {
+      for (int i = s.points.size()-1; i >= 0; --i) {
+        points[pi++] = s.points.get(i).index;
+      }
+    } else {
+      throw new RuntimeException("Unidentified strip mapping direction: " + direction);
+    }
+    return pi;
+  }
 
   public void toggle() {
     enabled = !enabled;
index 457c9746ffe51e246ffce68255cf97508e9cc116..cda18e5c67486c4c0f96d62fb127e114413d602d 100644 (file)
Binary files a/code/GLucose.jar and b/code/GLucose.jar differ
index 57713186b387fe4d69bc1b118f2ea2739dc59383..004d86fff690ecd717aa0f41f9e03696583187f4 100644 (file)
Binary files a/code/HeronLX.jar and b/code/HeronLX.jar differ