aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-01-29 21:05:59 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-01-29 21:05:59 -0500
commit9f69f7a2e174da12e6b2554c4270b5cadc52ff23 (patch)
tree503f63959459fd91cd1c170a390e916b85499a01
parentb42cab93f90760eaf3f8aac01c2ab41c1a5b1176 (diff)
parentda934a838305bab72bd12dcd2b83e689f7c1cc3f (diff)
Merge branch 'fridaydemo' of https://github.com/smootlight2/SmootLight into smootlight2-fridaydemo
-rw-r--r--behaviors/EchoBehavior.py5
-rw-r--r--behaviors/Flasher.py41
-rw-r--r--behaviors/RandomSetBrightColorBehavior.py14
-rw-r--r--config/FireflyDemo.xml261
-rw-r--r--util/ColorOps.py15
5 files changed, 335 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, [])
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 @@
+<!-- Demo of the flasher behavior. -->
+<!-- Bubbles or fireflies move around and fade on and off -->
+<!-- Jim Salem 1/28/11 jsalem@gmail.com -->
+<!-- Movement is pretty wonky. -->
+
+<!---All configuration items contain a "Class" tag specifying the python class they represent, and an "Args" tag specifying the args to be passed in.-->
+<LightInstallation>
+ <InstallationConfiguration>
+ <Defaults>
+ <PixelMapper>simplemap</PixelMapper>
+ </Defaults>
+ </InstallationConfiguration>
+ <PixelConfiguration>
+ <InheritsFrom>layouts/60StripLayout.xml</InheritsFrom>
+ </PixelConfiguration>
+ <PixelMapperConfiguration>
+ <PixelMapper>
+ <Class>pixelmappers.SimpleMapper</Class>
+ <Args>
+ <Id>simplemap</Id>
+ <CutoffDist>20</CutoffDist>
+ </Args>
+ </PixelMapper>
+ <PixelMapper>
+ <Class>pixelmappers.GaussianMapper</Class>
+ <Args>
+ <Id>gaussmap</Id>
+ <CutoffDist>30</CutoffDist>
+ <MinWeight>0.1</MinWeight>
+ <Width>10</Width>
+ <Height>1</Height>
+ </Args>
+ </PixelMapper>
+ </PixelMapperConfiguration>
+ <RendererConfiguration>
+<!--
+ <Renderer>
+ <InheritsFrom>renderers/60StripSeq.xml</InheritsFrom>
+ </Renderer>
+-->
+ <Renderer>
+ <InheritsFrom>renderers/Pygame.xml</InheritsFrom>
+ </Renderer>
+ </RendererConfiguration>
+ <InputConfiguration>
+ <InputElement>
+ <Class>inputs.PygameInput</Class>
+ <Args>
+ <Id>pygameclick</Id>
+ <RefreshInterval>10</RefreshInterval>
+ <Clicks>True</Clicks>
+ </Args>
+ </InputElement>
+ <InputElement>
+ <Class>inputs.PygameInput</Class>
+ <Args>
+ <Id>pygamekey</Id>
+ <RefreshInterval>10</RefreshInterval>
+ <Keyboard>True</Keyboard>
+ </Args>
+ </InputElement>
+ <InputElement>
+ <Class>inputs.UDPInput</Class>
+ <Args>
+ <Id>udp</Id>
+ <Port>3344</Port>
+ <RefreshInterval>50</RefreshInterval>
+ </Args>
+ </InputElement>
+ <!--<InputElement>
+ <Class>inputs.TCPInput</Class>
+ <Args>
+ <Id>tcp</Id>
+ <Port>20120</Port>
+ <RefreshInterval>10</RefreshInterval>
+ </Args>
+ </InputElement>-->
+ <InputElement Id="followmouse">
+ <InheritsFrom>inputs/MouseFollower.xml</InheritsFrom>
+ </InputElement>
+ </InputConfiguration>
+
+ <BehaviorConfiguration>
+ <Behavior>
+ <Class>behaviors.RandomSetBrightColorBehavior</Class>
+ <Args>
+ <Id>setbrightcolor</Id>
+ </Args>
+ </Behavior>
+
+ <Behavior Id="colorchange">
+ <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom>
+ <Args>
+ <ColorList>
+ <Val>(255,0,0)</Val>
+ <Val>(0,0,255)</Val>
+ </ColorList>
+ </Args>
+ </Behavior>
+ <Behavior Id="fastdecay">
+ <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom>
+ <Args>
+ <Coefficient>.5</Coefficient>
+ </Args>
+ </Behavior>
+ <Behavior Id="decay">
+ <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom>
+ </Behavior>
+ <Behavior Id="singleframe">
+ <InheritsFrom>behaviors/SingleFrame.xml</InheritsFrom>
+ </Behavior>
+ <Behavior Id="slowdecay">
+ <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom>
+ <Args>
+ <Coefficient>.01</Coefficient>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.XYMove</Class>
+ <Args>
+ <Id>xymove</Id>
+ <XStep>5</XStep>
+ <YStep>2</YStep>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.RestrictLocation</Class>
+ <Args>
+ <Id>xbounce</Id>
+ <Action>{val}*-1</Action>
+ <ParamName>XStep</ParamName>
+ <LocationRestriction>{x}&lt;0 or {x}&gt;800</LocationRestriction>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.RestrictLocation</Class>
+ <Args>
+ <Id>ybounce</Id>
+ <Action>{val}*-1</Action>
+ <ParamName>YStep</ParamName>
+ <LocationRestriction>{y}&lt;0 or {y}&gt;200</LocationRestriction>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>movebounce</Id>
+ <ChainedBehaviors>
+ <Id>xymove</Id>
+ <Id>ybounce</Id>
+ <Id>xbounce</Id>
+ </ChainedBehaviors>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.Flasher</Class>
+ <Args>
+ <Id>flasher</Id>
+ </Args>
+ </Behavior>
+
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>flashermovebounce</Id>
+ <ChainedBehaviors>
+ <Id>randmovement</Id>
+ <Id>ybounce</Id>
+ <Id>xbounce</Id>
+ <!-- <Id>fadecolor</Id> -->
+ <Id>flasher</Id>
+ </ChainedBehaviors>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.Square</Class>
+ <Args>
+ <Id>square</Id>
+ <Width>15</Width>
+ </Args>
+ </Behavior>
+ <Behavior Id="recursivedecay">
+ <InheritsFrom>behaviors/LoopAndDie.xml</InheritsFrom>
+ <Args>
+ <InitialResponseCount>80</InitialResponseCount>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.RandomWalk</Class>
+ <Args>
+ <Id>randmovement</Id>
+ <StepSize>20</StepSize>
+ </Args>
+ </Behavior>
+
+ <Behavior>
+ <Class>behaviors.ModifyParam</Class>
+ <Args>
+ <Id>fadecolor</Id>
+ <ParamType>Sensor</ParamType>
+ <ParamName>Color</ParamName>
+ <ParamOp>[chan*.98 for chan in {val}]</ParamOp>
+ </Args>
+ </Behavior>
+
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>runcolordecay</Id>
+ <Inputs>
+ <Id>pygameclick</Id>
+ </Inputs>
+ <ChainedBehaviors>
+ <Id>setbrightcolor</Id>
+ <Id>mover</Id>
+ <Id>decay</Id>
+ </ChainedBehaviors>
+ <RecursiveHooks>{'mover':'flashermovebounce'}</RecursiveHooks>
+ <RenderToScreen>True</RenderToScreen>
+ <Mapper>gaussmap</Mapper>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.ResponseMover</Class>
+ <Args>
+ <Id>mover</Id>
+ </Args>
+ </Behavior>
+ <Behavior Id="accelerate">
+ <InheritsFrom>behaviors/Accelerate.xml</InheritsFrom>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.EchoBehavior</Class>
+ <Args>
+ <Id>echo</Id>
+ <z-index>0</z-index>
+ <Color>(90,90,90)</Color>
+ <RenderToScreen>False</RenderToScreen>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>mousechaser</Id>
+ <Inputs>
+ <Id>followmouse</Id>
+ </Inputs>
+ <ChainedBehaviors>
+ <Id>echo</Id>
+ <Id>square</Id>
+ <Id>singleframe</Id>
+ </ChainedBehaviors>
+ <RenderToScreen>True</RenderToScreen>
+ </Args>
+ </Behavior>
+
+ <Behavior Id="running">
+ <InheritsFrom>behaviors/RunningBehavior.xml</InheritsFrom>
+ </Behavior>
+ </BehaviorConfiguration>
+</LightInstallation>
diff --git a/util/ColorOps.py b/util/ColorOps.py
index e384605..4b1162a 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)]
@@ -25,3 +26,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)