diff options
author | 2011-01-29 18:55:40 -0800 | |
---|---|---|
committer | 2011-01-29 18:55:40 -0800 | |
commit | 8f0e3818e819c73fee6986852c856efb7717c0e4 (patch) | |
tree | 4c6ee00fcebc155d83a78ce40cc38cbcd37efd3e /behaviors/Flasher.py | |
parent | e34b4dbf8ba67c5374e43bea8b469172025a9163 (diff) | |
parent | 277a5143165d2553ce5e97f151cc6b3cea426468 (diff) |
Merge branch 'master' of github.com:rcoh/SmootLight into osc
Conflicts:
Profile.py
Diffstat (limited to 'behaviors/Flasher.py')
-rw-r--r-- | behaviors/Flasher.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/behaviors/Flasher.py b/behaviors/Flasher.py new file mode 100644 index 0000000..1d79d41 --- /dev/null +++ b/behaviors/Flasher.py @@ -0,0 +1,41 @@ + +from operationscore.Behavior import * +import util.ColorOps as colorops +import pdb +class Flasher(Behavior): + """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 + """ + 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 |