aboutsummaryrefslogtreecommitdiff
path: root/behaviors/ColorChangerBehavior.py
blob: e2f8bd344e9c72d81ab0fe2a2082af1c4944cf4f (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
from operationscore.Behavior import *
import util.ColorOps as color
import pdb
class ColorChangerBehavior(Behavior):
    """ColorChangerBehavior is a behavior for adding colors to responses.  If given no arguments, it
    will generate a random color.  If it is given a list of colors [as below] it will pick randomly
    from them.

    <ColorList>
        <Color>(255,0,0)</Color>
        <Color>(30,79,200)</Color>
    </ColorList>

    ColorList also supports specification of a single color."""

    def processResponse(self, sensorInputs, recursiveInputs):
        ret = []
        for sensory in sensorInputs:
            newDict = dict(sensory) 
            if self['ColorList'] != None:
                if isinstance(self['ColorList'], list):
                    newDict['Color'] = color.chooseRandomColor(self['ColorList'])  #Pick randomly
                else:
                    newDict['Color'] = self['ColorList'] #Unless there is only one
            else:
                newDict['Color'] = color.randomColor() 
            ret.append(newDict)
        return (ret, [])