aboutsummaryrefslogtreecommitdiff
path: root/behaviors/RiseFall.py
blob: eea2283c7a3d4d8f983d0dfde6cc7c06643c203b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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, [])