From 339907710f8334ce16d6a02f9e0cac368c1727f2 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Mon, 10 Aug 2015 20:40:19 -0400
Subject: [PATCH] hsb colors

---
 js/menus/templates/EStaticMenuView.html  |  4 ++--
 js/simulation/electronics/LatticeEsim.js |  5 +++--
 js/simulation/electronics/eSimField.js   | 20 +++++++++-----------
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/js/menus/templates/EStaticMenuView.html b/js/menus/templates/EStaticMenuView.html
index 7d9239c7..47e47b68 100644
--- a/js/menus/templates/EStaticMenuView.html
+++ b/js/menus/templates/EStaticMenuView.html
@@ -13,8 +13,8 @@
         <label class="radio">
             <input type="radio" <% if (id == visibleConductorGroup){ %>checked<% } %> name="visibleConductorGroup" value="<%= id %>" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
             Group <%= ++index %>
-            <input data-property="voltage" data-index="<%= index %>" value="<%= groupData.voltage %>" placeholder="Voltage" class="form-control floatInput eSimGroup voltageInput" type="text">
-            <input data-property="current" data-index="<%= index %>" value="<%= groupData.current %>" placeholder="Current" class="form-control floatInput eSimGroup currentInput" type="text">
+            <input data-property="voltage" data-id="<%= id %>" value="<%= groupData.voltage %>" placeholder="Voltage" class="form-control floatInput eSimGroup voltageInput" type="text">
+            <input data-property="current" data-id="<%= id %>" value="<%= groupData.current %>" placeholder="Current" class="form-control floatInput eSimGroup currentInput" type="text">
         </label>
     <% }); %>
     Units:
diff --git a/js/simulation/electronics/LatticeEsim.js b/js/simulation/electronics/LatticeEsim.js
index 0ea05346..31585bca 100644
--- a/js/simulation/electronics/LatticeEsim.js
+++ b/js/simulation/electronics/LatticeEsim.js
@@ -95,7 +95,8 @@ define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimCell', 'eSimS
                 for (var i=0;i<resolution;i++){
                     for (var j=0;j<resolution;j++){
                         for (var k=0;k<resolution;k++){
-                            if (cell) eFieldMat[resolution*x+i+1][resolution*y+j+1][resolution*z+k+1] = 1;
+                            if (cell) eFieldMat[resolution*x+i+1][resolution*y+j+1][resolution*z+k+1] =
+                                conductorGroups[cell.getConductorGroupNum()].voltage;
                         }
                     }
                 }
@@ -103,7 +104,7 @@ define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimCell', 'eSimS
 
             var offset = this.get("cellsMin").clone().sub(new THREE.Vector3(1/(2*resolution)+this.xScale(0)/2, 1/(2*resolution)+this.yScale(0)/2, 1/(2*resolution)+this.zScale(0)/2));
             require(['eSimField'], function(ESimField){
-                eSim.set("electricField", new ESimField(eFieldMat, offset, resolution, eSim.get("simZHeight")));
+                eSim.set("electricField", new ESimField(eFieldMat, offset, resolution, eSim.get("simZHeight"), _.keys(conductorGroups)));
                 eSim.set("visibleStaticSim", "electricField");
             });
 
diff --git a/js/simulation/electronics/eSimField.js b/js/simulation/electronics/eSimField.js
index fda59872..0d2ac8b0 100644
--- a/js/simulation/electronics/eSimField.js
+++ b/js/simulation/electronics/eSimField.js
@@ -7,20 +7,20 @@
 
 define(['underscore', 'threeModel'], function(_, three){
 
-    function ESimField(data, offset, resolution, height){
+    function ESimField(data, offset, resolution, height, dataRange){
 
         this._object3D = new THREE.Object3D();
-        this._setData(data, offset, resolution, height);
+        this._setData(data, offset, resolution, height, dataRange);
 
         three.sceneAdd(this._object3D);
         this.hide();
     }
 
-    ESimField.prototype._setData = function(data, offset, resolution, height){
+    ESimField.prototype._setData = function(data, offset, resolution, height, dataRange){
         this._destroyData();
         this._data = data;
-        this._max = _.max(data);
-        this._min = _.min(data);
+        this._max = _.max(dataRange);
+        this._min = 0;
         this._resolution = resolution;
 
         this._offset = offset;
@@ -52,12 +52,10 @@ define(['underscore', 'threeModel'], function(_, three){
     };
 
     ESimField.prototype._colorForVal = function(val){
-        if (val == 1) console.log("here");
-        return new THREE.Color(1-val, val, val);
-        var scaledVal = (val - this._min)/(this._max - this._min) * (1-0)+ 0;
-        console.log(scaledVal);
-        console.log(this._min);
-        console.log(this._max);
+        var scaledVal = (1-(val - this._min)/(this._max - this._min)) * 0.7;
+        var color = new THREE.Color();
+        color.setHSL(scaledVal, 1, 0.5);
+        return color;
     };
 
     ESimField.prototype.show = function(height){
-- 
GitLab