Merge pull request #9 from visigoth/master
authorMark Slee <mcslee@gmail.com>
Wed, 21 Aug 2013 07:07:06 +0000 (00:07 -0700)
committerMark Slee <mcslee@gmail.com>
Wed, 21 Aug 2013 07:07:06 +0000 (00:07 -0700)
Finishing touches on Helix

ShaheenGandhi.pde

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) {