1 from operationscore.Behavior import *
2 import math
3 import util.TimeOps as timeOps
4
5
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
16 ret = []
17 for data in sensorInputs:
18
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']
24 if not 'Bottom' in data:
25 data['Bottom'] = data['Location'][1]
26 if 'Width' in self:
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
33 data['Height'] = data['MaxHeight']*math.sin(deltaTime/data['Period']*(math.pi*2))
34
35
36
37
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