From e3ac24dfaefdd367d8817252b693ec6834d8f1c8 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Mon, 10 Aug 2015 18:10:44 -0400
Subject: [PATCH] potential field getting set up

---
 js/simulation/electronics/eSimField.js | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/js/simulation/electronics/eSimField.js b/js/simulation/electronics/eSimField.js
index 80f7c760..972d52d3 100644
--- a/js/simulation/electronics/eSimField.js
+++ b/js/simulation/electronics/eSimField.js
@@ -52,7 +52,8 @@ define(['underscore', 'threeModel'], function(_, threeModel){
     };
 
     ESimField.prototype._colorForVal = function(val){
-        return new THREE.Color(val, 0, 0);
+        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);
@@ -60,13 +61,18 @@ define(['underscore', 'threeModel'], function(_, threeModel){
     };
 
     ESimField.prototype.show = function(height){
-        if (height){
-            for (var x=0;x<this._threeObjects.length;x++){
-                for (var y=0;y<this._threeObjects[x].length;y++){
-                    this._threeObjects[x][y].material.color = this._colorForVal(this._data[x][y][height]);
-                }
+        console.log(height);
+        if (height < 0 || this._data[0][0][height] === undefined) {
+            console.warn("height " + height + " is out of range");
+            return;
+        }
+
+        for (var x=0;x<this._threeObjects.length;x++){
+            for (var y=0;y<this._threeObjects[x].length;y++){
+                this._threeObjects[x][y].material.color.set(this._colorForVal(this._data[x][y][height]));
             }
         }
+
         this._setObject3DPosition(this._offset, this._resolution, height);
         this._object3D.visible = true;
         threeModel.render();
-- 
GitLab