From da934a838305bab72bd12dcd2b83e689f7c1cc3f Mon Sep 17 00:00:00 2001 From: Jim Salem Date: Fri, 28 Jan 2011 18:28:25 -0500 Subject: New Flasher behavior which fades colors in and out. Several new color functions. Created a "firefly" demo (moving colored bubbles that fade in and out) --- behaviors/EchoBehavior.py | 5 +- behaviors/Flasher.py | 41 +++++ behaviors/RandomSetBrightColorBehavior.py | 14 ++ config/FireflyDemo.xml | 261 ++++++++++++++++++++++++++++++ util/ColorOps.py | 15 ++ 5 files changed, 335 insertions(+), 1 deletion(-) create mode 100644 behaviors/Flasher.py create mode 100644 behaviors/RandomSetBrightColorBehavior.py create mode 100644 config/FireflyDemo.xml 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, []) diff --git a/config/FireflyDemo.xml b/config/FireflyDemo.xml new file mode 100644 index 0000000..8008168 --- /dev/null +++ b/config/FireflyDemo.xml @@ -0,0 +1,261 @@ + + + + + + + + + + simplemap + + + + layouts/60StripLayout.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 30 + 0.1 + 10 + 1 + + + + + + + renderers/Pygame.xml + + + + + inputs.PygameInput + + pygameclick + 10 + True + + + + inputs.PygameInput + + pygamekey + 10 + True + + + + inputs.UDPInput + + udp + 3344 + 50 + + + + + inputs/MouseFollower.xml + + + + + + behaviors.RandomSetBrightColorBehavior + + setbrightcolor + + + + + behaviors/RandomColor.xml + + + (255,0,0) + (0,0,255) + + + + + behaviors/PixelDecay.xml + + .5 + + + + behaviors/PixelDecay.xml + + + behaviors/SingleFrame.xml + + + behaviors/PixelDecay.xml + + .01 + + + + behaviors.XYMove + + xymove + 5 + 2 + + + + behaviors.RestrictLocation + + xbounce + {val}*-1 + XStep + {x}<0 or {x}>800 + + + + behaviors.RestrictLocation + + ybounce + {val}*-1 + YStep + {y}<0 or {y}>200 + + + + behaviors.BehaviorChain + + movebounce + + xymove + ybounce + xbounce + + + + + behaviors.Flasher + + flasher + + + + + behaviors.BehaviorChain + + flashermovebounce + + randmovement + ybounce + xbounce + + flasher + + + + + behaviors.Square + + square + 15 + + + + behaviors/LoopAndDie.xml + + 80 + + + + behaviors.RandomWalk + + randmovement + 20 + + + + + behaviors.ModifyParam + + fadecolor + Sensor + Color + [chan*.98 for chan in {val}] + + + + + behaviors.BehaviorChain + + runcolordecay + + pygameclick + + + setbrightcolor + mover + decay + + {'mover':'flashermovebounce'} + True + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors/Accelerate.xml + + + behaviors.EchoBehavior + + echo + 0 + (90,90,90) + False + + + + behaviors.BehaviorChain + + mousechaser + + followmouse + + + echo + square + singleframe + + True + + + + + behaviors/RunningBehavior.xml + + + diff --git a/util/ColorOps.py b/util/ColorOps.py index 037957a..d971ad0 100644 --- a/util/ColorOps.py +++ b/util/ColorOps.py @@ -1,4 +1,5 @@ import random +import colorsys from util.TimeOps import Stopwatch def randomColor(): return [random.randint(0,255) for i in range(3)] @@ -23,3 +24,17 @@ def combineColors(colors): def multiplyColor(color, percent): return safeColor([channel*(percent) for channel in color]) + +def floatToIntColor(rgb): + rgb[0] = int(rgb[0]*256 + .5) + rgb[1] = int(rgb[1]*256 + .5) + rgb[2] = int(rgb[2]*256 + .5) + return safeColor(rgb) + +def randomBrightColor(): + hue = random.random() + sat = random.random()/2.0 + .5 + val = 1.0 + hue, sat, val = colorsys.hsv_to_rgb(hue, sat, val) + ret = [hue, sat, val] + return floatToIntColor(ret) -- cgit v1.2.3 From ccb6ea18285a26b8cc8d99ae7d6540f8ca792398 Mon Sep 17 00:00:00 2001 From: rcoh Date: Sat, 29 Jan 2011 19:28:11 -0500 Subject: couple changes. Merge of friday demo. --- Profile.py | 2 +- util/ColorOps.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Profile.py b/Profile.py index 2f180c9..daabb6b 100644 --- a/Profile.py +++ b/Profile.py @@ -1,4 +1,4 @@ import cProfile from LightInstallation import main -command = """main(['', 'config/6thFloor.xml'])""" +command = """main(['', 'config/Kuan.xml'])""" cProfile.runctx(command, globals(), locals(), filename="smootlight.profile") diff --git a/util/ColorOps.py b/util/ColorOps.py index 037957a..e384605 100644 --- a/util/ColorOps.py +++ b/util/ColorOps.py @@ -11,6 +11,8 @@ def safeColor(c): c[0] = c[0] if c[0] < 255 else 255 c[1] = c[1] if c[1] < 255 else 255 c[2] = c[2] if c[2] < 255 else 255 + + return c def combineColors(colors): -- cgit v1.2.3 From b42cab93f90760eaf3f8aac01c2ab41c1a5b1176 Mon Sep 17 00:00:00 2001 From: rcoh Date: Sat, 29 Jan 2011 19:36:39 -0500 Subject: Fixed a bug that was causing us to drop clicks. --- inputs/PygameInput.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inputs/PygameInput.py b/inputs/PygameInput.py index 414adf3..480630c 100644 --- a/inputs/PygameInput.py +++ b/inputs/PygameInput.py @@ -33,3 +33,5 @@ class PygameInput(Input): if event.type is MOUSEBUTTONDOWN: if self['Clicks']: self.respond({Strings.LOCATION: pygame.mouse.get_pos()}) + else: + pygame.event.post(event) -- cgit v1.2.3 From 277a5143165d2553ce5e97f151cc6b3cea426468 Mon Sep 17 00:00:00 2001 From: rcoh Date: Sat, 29 Jan 2011 21:15:28 -0500 Subject: A couple bits of cleanup to the firefly code --- behaviors/Flasher.py | 12 +++--- config/FireflyDemo.xml | 106 ++----------------------------------------------- 2 files changed, 10 insertions(+), 108 deletions(-) diff --git a/behaviors/Flasher.py b/behaviors/Flasher.py index 4a2dad4..1d79d41 100644 --- a/behaviors/Flasher.py +++ b/behaviors/Flasher.py @@ -1,14 +1,14 @@ -# 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): + """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: diff --git a/config/FireflyDemo.xml b/config/FireflyDemo.xml index 8008168..856569e 100644 --- a/config/FireflyDemo.xml +++ b/config/FireflyDemo.xml @@ -33,11 +33,9 @@ - renderers/Pygame.xml @@ -67,62 +65,18 @@ 50 - - - inputs/MouseFollower.xml - - behaviors.RandomSetBrightColorBehavior - - setbrightcolor - - - - - behaviors/RandomColor.xml + behaviors.RandomSetBrightColorBehavior - - (255,0,0) - (0,0,255) - - - - - behaviors/PixelDecay.xml - - .5 + setbrightcolor behaviors/PixelDecay.xml - - behaviors/SingleFrame.xml - - - behaviors/PixelDecay.xml - - .01 - - - - behaviors.XYMove - - xymove - 5 - 2 - - behaviors.RestrictLocation @@ -141,24 +95,12 @@ {y}<0 or {y}>200 - - behaviors.BehaviorChain - - movebounce - - xymove - ybounce - xbounce - - - behaviors.Flasher flasher - behaviors.BehaviorChain @@ -167,8 +109,7 @@ randmovement ybounce xbounce - - flasher + flasher @@ -179,12 +120,6 @@ 15 - - behaviors/LoopAndDie.xml - - 80 - - behaviors.RandomWalk @@ -192,17 +127,6 @@ 20 - - - behaviors.ModifyParam - - fadecolor - Sensor - Color - [chan*.98 for chan in {val}] - - - behaviors.BehaviorChain @@ -226,36 +150,14 @@ mover - - behaviors/Accelerate.xml - behaviors.EchoBehavior echo 0 - (90,90,90) + (90,90,90) False - - behaviors.BehaviorChain - - mousechaser - - followmouse - - - echo - square - singleframe - - True - - - - - behaviors/RunningBehavior.xml - -- cgit v1.2.3