aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-02-05 22:34:34 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-02-05 22:34:34 -0500
commit06c639db6b98affab4abf07e57a90e2fcb5402ef (patch)
tree3dad66f7c131272cafad5304327cec0d3cf5bd62 /util
parent9b134eb47a93c2317519c07dc5a3c3522c9fa2f4 (diff)
Early stages of param-binding in xml. Functional. RCOH
Diffstat (limited to 'util')
-rw-r--r--util/ColorOps.py4
-rw-r--r--util/Config.py10
-rw-r--r--util/Geo.py7
3 files changed, 21 insertions, 0 deletions
diff --git a/util/ColorOps.py b/util/ColorOps.py
index 4b1162a..796a902 100644
--- a/util/ColorOps.py
+++ b/util/ColorOps.py
@@ -40,3 +40,7 @@ def randomBrightColor():
hue, sat, val = colorsys.hsv_to_rgb(hue, sat, val)
ret = [hue, sat, val]
return floatToIntColor(ret)
+
+class Color(object):
+ def __init__(self, r,g,b):
+ self.rep = [r,g,b]
diff --git a/util/Config.py b/util/Config.py
index 6fdb0d4..4153313 100644
--- a/util/Config.py
+++ b/util/Config.py
@@ -1,4 +1,5 @@
from xml.etree.ElementTree import *
+import re
import sys
import xml
import pdb
@@ -113,6 +114,15 @@ def pullArgsFromItem(parentNode):
def attemptEval(val):
try:
+ if '${' in val and '}$' in val: #TODO: this could be a little cleaner
+ dictVal = re.sub("'\$\{(.+)\}\$'", "b['\\1']", val) #replace all expressions like {blah} with a['blah']
+ dictVal = re.sub("\$\{(.+)\}\$", "a['\\1']", dictVal) #replace all expressions like {blah} with a['blah']
+ if "'${" and "}$'" in val: #nested lambda madness
+ lambdaVal = eval('lambda a: lambda b: ' + dictVal)
+ else:
+ lambdaVal = eval('lambda a:'+dictVal) #TODO: nested lambdas
+ return lambdaVal #convert referential objects to lambda expressions which resolve
+ #dynamically
val = eval(val)
except (NameError, SyntaxError):
val = str(val)
diff --git a/util/Geo.py b/util/Geo.py
index 0dde80b..43817ad 100644
--- a/util/Geo.py
+++ b/util/Geo.py
@@ -32,3 +32,10 @@ def windtrail(x,y,height,center,width):
b=center
c=width
return a*((math.exp(-((x-b))/(c)))**2)*(math.exp(-((y))/(0.2*c)))**2
+
+class Location(object):
+ def __init__(self,x=0,y=0):
+ self.x = x
+ self.y = y
+ def __add__(self, b):
+ return Location(self.x+b.x, self.y+b.y)