aboutsummaryrefslogtreecommitdiff
path: root/behaviors/Flasher.py
diff options
context:
space:
mode:
authorGravatar Daniel <dmt@daniel-desktop.(none)>2011-01-29 18:54:50 -0800
committerGravatar Daniel <dmt@daniel-desktop.(none)>2011-01-29 18:54:50 -0800
commitff07b18748c64243c1c6bc62f489bfd03205d13a (patch)
treedb95373a3511be0dd1e700a78e9f1ea7320769a4 /behaviors/Flasher.py
parent83931a3c8e65b4018e98b4986458d1df7172ab91 (diff)
parent277a5143165d2553ce5e97f151cc6b3cea426468 (diff)
Merge branch 'master' of github.com:rcoh/SmootLight
Diffstat (limited to 'behaviors/Flasher.py')
-rw-r--r--behaviors/Flasher.py41
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