diff options
author | rcoh <rcoh@mit.edu> | 2011-01-29 21:05:59 -0500 |
---|---|---|
committer | rcoh <rcoh@mit.edu> | 2011-01-29 21:05:59 -0500 |
commit | 9f69f7a2e174da12e6b2554c4270b5cadc52ff23 (patch) | |
tree | 503f63959459fd91cd1c170a390e916b85499a01 /behaviors | |
parent | b42cab93f90760eaf3f8aac01c2ab41c1a5b1176 (diff) | |
parent | da934a838305bab72bd12dcd2b83e689f7c1cc3f (diff) |
Merge branch 'fridaydemo' of https://github.com/smootlight2/SmootLight into smootlight2-fridaydemo
Diffstat (limited to 'behaviors')
-rw-r--r-- | behaviors/EchoBehavior.py | 5 | ||||
-rw-r--r-- | behaviors/Flasher.py | 41 | ||||
-rw-r--r-- | behaviors/RandomSetBrightColorBehavior.py | 14 |
3 files changed, 59 insertions, 1 deletions
diff --git a/behaviors/EchoBehavior.py b/behaviors/EchoBehavior.py index 6ef4fcb..c4af7c0 100644 --- a/behaviors/EchoBehavior.py +++ b/behaviors/EchoBehavior.py @@ -9,6 +9,9 @@ class EchoBehavior(Behavior): for sensory in sensorInputs: outDict = {} outDict[Strings.LOCATION] = sensory[Strings.LOCATION] - outDict['Color'] = (255,0,0) + if self['Color'] != None: + outDict['Color'] = self['Color'] + else: + outDict['Color'] = (255,0,0) ret.append(outDict) return (ret, []) diff --git a/behaviors/Flasher.py b/behaviors/Flasher.py new file mode 100644 index 0000000..4a2dad4 --- /dev/null +++ b/behaviors/Flasher.py @@ -0,0 +1,41 @@ +# Implements a pulsing/flashing behavior. +# Jim Salem: jsalem@gmail.com +# +# Args: +# Factor - The speed of flashing. Must be b/w 0 and 1. Default is .95 +# + +from operationscore.Behavior import * +import util.ColorOps as colorops +import pdb +class Flasher(Behavior): + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + for response in sensorInputs: + # Get the multiplier + if self['Factor'] != None: + factor = self['Factor'] + else: + factor = 0.95 + # Initialize the first time + if not 'FireflyStartColor' in response: + response['FireflyValue'] = 1.0 + response['FireflyDir'] = 1 + response['FireflyStartColor'] = response['Color']; + else: + # Update the current value + if response['FireflyDir'] == 1: + response['FireflyValue'] = response['FireflyValue'] * factor + if response['FireflyValue'] <= 0.01: + response['FireflyValue'] = 0.01 + response['FireflyDir'] = 0 + else: + response['FireflyValue'] = response['FireflyValue'] / factor + if response['FireflyValue'] >= 1.0: + response['FireflyValue'] = 1.0 + response['FireflyDir'] = 1 + + # Compute the color + response['Color'] = colorops.multiplyColor(response['FireflyStartColor'], response['FireflyValue']) + ret.append(response) + return (ret, []) #no direct ouput diff --git a/behaviors/RandomSetBrightColorBehavior.py b/behaviors/RandomSetBrightColorBehavior.py new file mode 100644 index 0000000..f278858 --- /dev/null +++ b/behaviors/RandomSetBrightColorBehavior.py @@ -0,0 +1,14 @@ +from operationscore.Behavior import * +import util.ColorOps as color +import pdb +import colorsys +import random +class RandomSetBrightColorBehavior(Behavior): + """Sets a random color that is bright.""" + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + for sensory in sensorInputs: + newDict = dict(sensory) + newDict['Color'] = color.randomBrightColor() + ret.append(newDict) + return (ret, []) |