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

Source Code for Module SmootLight.behaviors.Sink

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