Package SmootLight :: Package behaviors :: Module RiseFall
[hide private]
[frames] | no frames]

Source Code for Module SmootLight.behaviors.RiseFall

 1  from operationscore.Behavior import * 
 2  import math 
 3  import util.TimeOps as timeOps 
 4  #Required Args: 
 5  #Period (ms), MaxHeight, Width 
6 -class RiseFall(Behavior):
7 """RiseFall is a behavior that creates a rising and falling column of light. Specify: 8 <MaxHeight> -- the maximum height that it rises to. 9 <Width> -- the width of the column OR <Left> and <Right> 10 <Period> -- the period of oscillation in ms 11 12 Designed to be used as part of a recursive hook. 13 """ 14
15 - def processResponse(self, sensorInputs, recurInputs):
16 ret = [] 17 for data in sensorInputs: 18 #first time with behavior: 19 data = dict(data) 20 if not 'StartTime' in data: 21 data['StartTime'] = timeOps.time() 22 data['Period'] = self['Period'] 23 data['MaxHeight'] = self['MaxHeight'] #Consider just using += 24 if not 'Bottom' in data: 25 data['Bottom'] = data['Location'][1] 26 if 'Width' in self: #TODO: improve 27 data['Width'] = self['Width'] 28 data['Left'] = data['Location'][0]-data['Width']/2. 29 data['Right'] = data['Location'][0]+data['Width']/2. 30 currentTime = timeOps.time() 31 deltaTime = currentTime-data['StartTime'] 32 #if data['Oscillate'] == True: 33 data['Height'] = data['MaxHeight']*math.sin(deltaTime/data['Period']*(math.pi*2)) 34 #else: 35 # data['Height'] = data['MaxHeight'] 36 #if (currentTime-data['StartTime']) > data['Period']: 37 # del data['StartTime'] 38 39 data['Location'] = "{x}>"+str(data['Left']) + ", " +\ 40 "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ 41 {y}>"+str(data['Bottom']-data['Height']) 42 43 ret.append(data) 44 return (ret, [])
45