aboutsummaryrefslogtreecommitdiff
path: root/behaviors/RiseFall.py
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-02-01 23:14:12 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-02-01 23:14:12 -0500
commit5a97e7548b0ec44f0d61a724903748197e69df7c (patch)
tree7bb6b8ea7e488949eeb16ae18b0ad2230f1f7c9b /behaviors/RiseFall.py
parent082e4b0c53123dd377da148541f7d98516716862 (diff)
parent482a94fd48627153b923931d6ff21ebf57fad6f7 (diff)
Merge branch 'osc' of github.com:rcoh/SmootLight into osc
Diffstat (limited to 'behaviors/RiseFall.py')
-rw-r--r--behaviors/RiseFall.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/behaviors/RiseFall.py b/behaviors/RiseFall.py
new file mode 100644
index 0000000..eea2283
--- /dev/null
+++ b/behaviors/RiseFall.py
@@ -0,0 +1,46 @@
+from operationscore.Behavior import *
+import math
+import util.TimeOps as timeOps
+#Required Args:
+#Period (ms), MaxHeight, Width
+class RiseFall(Behavior):
+ """RiseFall is a behavior that creates a rising and falling column of light. Specify:
+ <MaxHeight> -- the maximum height that it rises to.
+ <Width> -- the width of the column OR <Left> and <Right>
+ <Period> -- the period of oscillation in ms
+
+ Designed to be used as part of a recursive hook.
+ """
+
+ def processResponse(self, sensorInputs, recurInputs):
+ ret = []
+ for data in sensorInputs:
+ #first time with behavior:
+ data = dict(data)
+ if not 'StartTime' in data:
+ data['StartTime'] = timeOps.time()
+ data['Period'] = self['Period']
+ data['MaxHeight'] = self['MaxHeight'] #Consider just using +=
+ if not 'Bottom' in data:
+ data['Bottom'] = data['Location'][1]
+ if 'Width' in self: #TODO: improve
+ data['Width'] = self['Width']
+ data['Left'] = data['Location'][0]-data['Width']/2.
+ data['Right'] = data['Location'][0]+data['Width']/2.
+ currentTime = timeOps.time()
+ deltaTime = currentTime-data['StartTime']
+ #if data['Oscillate'] == True:
+ data['Height'] = data['MaxHeight']*math.sin(deltaTime/data['Period']*(math.pi*2))
+ #else:
+ # data['Height'] = data['MaxHeight']
+ #if (currentTime-data['StartTime']) > data['Period']:
+ # del data['StartTime']
+
+ data['Location'] = "{x}>"+str(data['Left']) + ", " +\
+ "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\
+ {y}>"+str(data['Bottom']-data['Height'])
+
+ ret.append(data)
+ return (ret, [])
+
+