aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar eugue <eug.sun@gmail.com>2011-01-27 17:31:13 -0500
committerGravatar eugue <eug.sun@gmail.com>2011-01-27 17:31:13 -0500
commita08a7f19f2e7b4421f894fcbc00c7c12af031e89 (patch)
tree66ddb6fdfbec9fec29dc4b72e066c8d1c761c1db
parent32fdbbb7512576cb8a54556640b18be160d655d1 (diff)
parentf103e47da5d563d1b8448bc021676ed7db0f529d (diff)
Merge branch 'master' of github.com:rcoh/SmootLight into mobileapp
-rwxr-xr-x[-rw-r--r--]LightInstallation.py2
-rw-r--r--behaviors/ModifyParam.py7
-rw-r--r--behaviors/MrmrSetColor.py21
-rw-r--r--behaviors/TouchOSC.py33
-rw-r--r--behaviors/XYMove.py1
-rw-r--r--config/6thFloor.xml16
-rw-r--r--config/6thFloorOSC.xml286
-rw-r--r--config/osc.xml10
-rw-r--r--inputs/OSCInput.py22
-rwxr-xr-xoscserver.py36
-rw-r--r--pixelcore/PixelStrip.py4
-rwxr-xr-xtestosc.py36
12 files changed, 466 insertions, 8 deletions
diff --git a/LightInstallation.py b/LightInstallation.py
index ad1e38d..24ad8b1 100644..100755
--- a/LightInstallation.py
+++ b/LightInstallation.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+
from xml.etree.ElementTree import ElementTree
from pixelcore.Screen import *
from pixelcore.PixelStrip import *
diff --git a/behaviors/ModifyParam.py b/behaviors/ModifyParam.py
index 4f45be0..0ef3a60 100644
--- a/behaviors/ModifyParam.py
+++ b/behaviors/ModifyParam.py
@@ -1,4 +1,5 @@
from operationscore.Behavior import *
+import math
import pdb
#Class to perform a given operation on some element of an argDict. Designed to be used a recursive hook, but can serve sensor-based functions as well. Specify ParamType (Sensor or Recurse), ParamName, and ParamOp, (a valid python statement with the old value represented as {val})
class ModifyParam(Behavior):
@@ -7,7 +8,8 @@ class ModifyParam(Behavior):
<ParamType> -- Sensor or Recurse
<ParamName> -- The name of the parameter you wish to modify
<ParamOp> -- The modification you wish to do. Use {val} to specify the current value of the
- parameter in question. Special hooks for {x} and {y} exist in some versions"""
+ parameter in question. Special hooks for {x} and {y} also exist to access the x and y
+ locations."""
def processResponse(self, sensorInputs, recursiveInputs):
paramType = self['ParamType']
@@ -25,6 +27,9 @@ class ModifyParam(Behavior):
if paramName in behaviorInput: #TODO: copy -> modify instead of just
#copying
paramOp = paramOp.replace('{val}', 'behaviorInput[paramName]') #convert the {val} marker to something we can execute
+ #TODO: move elsewhere
+ paramOp = paramOp.replace('{y}', "behaviorInput['Location'][1]")
+ paramOp = paramOp.replace('{x}', "behaviorInput['Location'][0]")
behaviorInput[paramName] = eval(paramOp)
if paramType == 'Sensor': #return accordingly
return (searchSet, recursiveInputs)
diff --git a/behaviors/MrmrSetColor.py b/behaviors/MrmrSetColor.py
new file mode 100644
index 0000000..97b9fb7
--- /dev/null
+++ b/behaviors/MrmrSetColor.py
@@ -0,0 +1,21 @@
+from operationscore.Behavior import *
+from logger import main_log
+#import util.ColorOps as color
+import colorsys
+import pdb
+class MrmrSetColor(Behavior):
+ def behaviorInit(self):
+ self.h=0
+ self.s=0
+ self.v=0
+ def processResponse(self, sensorInputs, recursiveInputs):
+ ret = []
+ for data in sensorInputs:
+ if data['Path'].find('horizontal') != -1:
+ self.h = data['Value'] / 2.78
+ elif data['Path'].find('vertical') != -1:
+ self.s = data['Value'] / 1000.0
+ else:
+ main_log.error('Sensor Inputs: ' + str(sensorInputs))
+ ret.append({'Color':[i*255 for i in colorsys.hsv_to_rgb(self.h,self.s,self.v)]})
+ return (ret, [])
diff --git a/behaviors/TouchOSC.py b/behaviors/TouchOSC.py
new file mode 100644
index 0000000..1c41b5e
--- /dev/null
+++ b/behaviors/TouchOSC.py
@@ -0,0 +1,33 @@
+from operationscore.Behavior import *
+from logger import main_log
+#import util.ColorOps as color
+import colorsys
+import pdb
+import util.ComponentRegistry as compReg
+class TouchOSC(Behavior):
+ def behaviorInit(self):
+ self.h=0
+ self.s=0
+ self.v=0
+ self.xy = (-1,-1)
+ def processResponse(self, sensorInputs, recursiveInputs):
+ ret = []
+ for data in sensorInputs:
+ if data['Path'] == '/1/fader1':
+ try:
+ self.h = data['Value'][0]*360.0
+ except:
+ pdb.set_trace()
+ elif data['Path'] == '/1/fader2':
+ self.s = data['Value'][0]
+ elif data['Path'] == '/1/fader3':
+ self.v = data['Value'][0]
+ elif data['Path'] == '/1/xy':
+ val=data['Value']
+ ssize = compReg.getComponent('Screen').getSize()[-2:] #896 x 310
+ self.xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1])
+ else:
+ main_log.error('Sensor Inputs: ' + str(sensorInputs))
+ ret.append({'Color':[i*255 for i in colorsys.hsv_to_rgb(self.h,self.s,self.v)],'Location':self.xy})
+
+ return (ret, [])
diff --git a/behaviors/XYMove.py b/behaviors/XYMove.py
index 11cee96..0ba3baf 100644
--- a/behaviors/XYMove.py
+++ b/behaviors/XYMove.py
@@ -13,6 +13,7 @@ class XYMove(Behavior):
for loc in sensor:
oploc = dict(loc)
self.insertStepIfMissing(oploc)
+ print oploc['YStep']
oploc['Location'] = Geo.addLocations((oploc['XStep'], oploc['YStep']), oploc['Location'])
ret.append(oploc)
return (ret, [])
diff --git a/config/6thFloor.xml b/config/6thFloor.xml
index b58ff57..81f0c9f 100644
--- a/config/6thFloor.xml
+++ b/config/6thFloor.xml
@@ -28,9 +28,9 @@
</PixelMapper>
</PixelMapperConfiguration>
<RendererConfiguration>
- <!--Renderer>
+ <Renderer>
<InheritsFrom>renderers/60StripSeq.xml</InheritsFrom>
- </Renderer-->
+ </Renderer>
<Renderer>
<InheritsFrom>renderers/Pygame.xml</InheritsFrom>
</Renderer>
@@ -147,12 +147,22 @@
<Id>movebounce</Id>
<ChainedBehaviors>
<Id>xymove</Id>
- <Id>ybounce</Id>
+ <!--Id>ybounce</Id-->
<Id>xbounce</Id>
+ <Id>ysin</Id>
</ChainedBehaviors>
</Args>
</Behavior>
<Behavior>
+ <Class>behaviors.ModifyParam</Class>
+ <Args>
+ <Id>ysin</Id>
+ <ParamName>YStep</ParamName>
+ <ParamType>Sensor</ParamType>
+ <ParamOp>4*math.sin({x}/float(40))</ParamOp>
+ </Args>
+ </Behavior>
+ <Behavior>
<Class>behaviors.BehaviorChain</Class>
<Args>
<Id>expanddie</Id>
diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml
new file mode 100644
index 0000000..792fd0c
--- /dev/null
+++ b/config/6thFloorOSC.xml
@@ -0,0 +1,286 @@
+<!---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>
+ <!--<InheritsFrom>layouts/BasicSixStrip.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.OSCInput</Class>
+ <Args>
+ <Id>osc</Id>
+ <Port>12345</Port>
+ <RefreshInterval>10</RefreshInterval>
+ </Args>
+ </InputElement>
+ <InputElement>
+ <Class>inputs.PygameInput</Class>
+ <Args><!--Passed as a dictionary-->
+ <Id>pygame</Id>
+ <RefreshInterval>10</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>
+ <InputElement>
+ <Class>inputs.RandomLocs</Class>
+ <Args>
+ <Id>randomLoc</Id>
+ </Args>
+ </InputElement>
+ </InputConfiguration>
+ <BehaviorConfiguration>
+ <Behavior>
+ <Class>behaviors.EchoBehavior</Class>
+ <Args>
+ <Id>echo</Id>
+ <z-index>0</z-index>
+ <RenderToScreen>False</RenderToScreen>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Args>
+ <Id>touchosc</Id>
+ </Args>
+ <Class>behaviors.TouchOSC</Class>
+ </Behavior>
+ <Behavior Id="redshift">
+ <InheritsFrom>behaviors/RedShift.xml</InheritsFrom>
+ </Behavior>
+ <Behavior Id="colorchange">
+ <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom>
+ </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.BehaviorChain</Class>
+ <Args>
+ <Id>xymover</Id>
+ <Inputs>
+ <Id>pygame</Id>
+ </Inputs>
+ <ChainedBehaviors>
+ <Id>colorchange</Id>
+ <Id>mover</Id>
+ <Id>decay</Id>
+ </ChainedBehaviors>
+ <RecursiveHooks>{'mover':'movebounce'}</RecursiveHooks>
+ <RenderToScreen>True</RenderToScreen>
+ <Mapper>gaussmap</Mapper>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.DebugBehavior</Class>
+ <Args>
+ <Id>debug</Id>
+ <z-index>0</z-index>
+ <Inputs>
+ <Id>pygame</Id>
+ </Inputs>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.AllPixelsLeft</Class>
+ <Args>
+ <Id>pixelsleft</Id>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.Square</Class>
+ <Args>
+ <Id>square</Id>
+ <Width>20</Width>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.AllPixels</Class>
+ <Args>
+ <Id>allpixels</Id>
+ </Args>
+ </Behavior>
+ <Behavior Id="recursivedecay">
+ <InheritsFrom>behaviors/LoopAndDie.xml</InheritsFrom>
+ <Args>
+ <InitialResponseCount>50</InitialResponseCount>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>runcolordecay</Id>
+ <Inputs>
+ <Id>pygame</Id>
+ </Inputs>
+ <ChainedBehaviors>
+ <Id>colorchange</Id>
+ <Id>running</Id>
+ <Id>decay</Id>
+ </ChainedBehaviors>
+ <RecursiveHooks>{'running':'acceleratedie'}</RecursiveHooks>
+ <RenderToScreen>False</RenderToScreen>
+ <Mapper>gaussmap</Mapper>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>randomwalk</Id>
+ <Inputs>
+ <Id>pygame</Id>
+ </Inputs>
+ <ChainedBehaviors>
+ <Id>colorchange</Id>
+ <Id>mover</Id>
+ <Id>decay</Id>
+ </ChainedBehaviors>
+ <RecursiveHooks>{'mover':'redwalk'}</RecursiveHooks>
+ <RenderToScreen>False</RenderToScreen>
+ <Mapper>gaussmap</Mapper>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.ResponseMover</Class>
+ <Args>
+ <Id>mover</Id>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>redwalk</Id>
+ <ChainedBehaviors>
+ <Id>randmovement</Id>
+ <Id>redshift</Id>
+ </ChainedBehaviors>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.RandomWalk</Class>
+ <Args>
+ <Id>randmovement</Id>
+ <StepSize>2</StepSize>
+ </Args>
+ </Behavior>
+ <Behavior Id="accelerate">
+ <InheritsFrom>behaviors/Accelerate.xml</InheritsFrom>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>acceleratedie</Id>
+ <ChainedBehaviors>
+ <Id>accelerate</Id>
+ <Id>recursivedecay</Id>
+ </ChainedBehaviors>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>mousechaser</Id>
+ <Inputs>
+ <!--Id>followmouse</Id-->
+ <Id>tcp</Id>
+ <Id>osc</Id>
+ </Inputs>
+ <ChainedBehaviors>
+ <Id>touchosc</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/config/osc.xml b/config/osc.xml
new file mode 100644
index 0000000..6efea40
--- /dev/null
+++ b/config/osc.xml
@@ -0,0 +1,10 @@
+ <InputElement>
+ <Class>inputs.OSCInput</Class>
+ <Args>
+ <Id>osc</Id>
+ <Port>1234</Port>
+ </Args>
+ </InputElement>
+ <Behavior Id="mrmrcolor">
+ <Class>behaviors.MrmrSetColor</Class>
+ </Behavior>
diff --git a/inputs/OSCInput.py b/inputs/OSCInput.py
new file mode 100644
index 0000000..f867fb5
--- /dev/null
+++ b/inputs/OSCInput.py
@@ -0,0 +1,22 @@
+from operationscore.Input import *
+import liblo
+from logger import main_log
+
+
+class OSCInput(Input):
+ def inputInit(self):
+ HOST = '' # Symbolic name meaning all available interfaces
+ PORT = self['Port'] # Arbitrary non-privileged port
+ self.server = liblo.Server(PORT)
+ self.server.add_method(None,None, self.fallback)
+# except liblo.ServerError, err:
+ # main_log.error(str(err))
+
+ def fallback(self,path,args,types, src):
+ self.respond({'Path':path,'Type':types,'Value':args})
+ def sensingLoop(self):
+ self.server.recv(100)
+ pass#(data,address) = self.sock.recvfrom(1024)
+ #dataDict = {'data':data, 'address':address}
+ #self.respond(dataDict)
+
diff --git a/oscserver.py b/oscserver.py
new file mode 100755
index 0000000..6763f41
--- /dev/null
+++ b/oscserver.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import liblo, sys
+
+# create server, listening on port 1234
+try:
+ server = liblo.Server(1234)
+except liblo.ServerError, err:
+ print str(err)
+ sys.exit()
+
+def foo_bar_callback(path, args):
+ i, f = args
+ print "received message '%s' with arguments '%d' and '%f'" % (path, i, f)
+
+def foo_baz_callback(path, args, types, src, data):
+ print "received message '%s'" % path
+ print "blob contains %d bytes, user data was '%s'" % (len(args[0]), data)
+
+def fallback(path, args, types, src):
+ print "got unknown message '%s' from '%s'" % (path, src.get_url())
+ for a, t in zip(args, types):
+ print "argument of type '%s': %s" % (t, a)
+
+# register method taking an int and a float
+server.add_method("/foo/bar", 'if', foo_bar_callback)
+
+# register method taking a blob, and passing user data to the callback
+server.add_method("/foo/baz", 'b', foo_baz_callback, "blah")
+
+# register a fallback for unhandled messages
+server.add_method(None, None, fallback)
+
+# loop and dispatch messages every 100ms
+while True:
+ server.recv(100)
diff --git a/pixelcore/PixelStrip.py b/pixelcore/PixelStrip.py
index 595ce72..29d3b31 100644
--- a/pixelcore/PixelStrip.py
+++ b/pixelcore/PixelStrip.py
@@ -17,8 +17,4 @@ class PixelStrip:
def __iter__(self):
return self.pixels.__iter__()
-
-
-
-
diff --git a/testosc.py b/testosc.py
new file mode 100755
index 0000000..cea03f4
--- /dev/null
+++ b/testosc.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import liblo, sys
+
+# create server, listening on port 1234
+try:
+ server = liblo.Server(12345)
+except liblo.ServerError, err:
+ print str(err)
+ sys.exit()
+
+def foo_bar_callback(path, args):
+ i, f = args
+ print "received message '%s' with arguments '%d' and '%f'" % (path, i, f)
+
+def foo_baz_callback(path, args, types, src, data):
+ print "received message '%s'" % path
+ print "blob contains %d bytes, user data was '%s'" % (len(args[0]), data)
+
+def fallback(path, args, types, src):
+ print "got unknown message '%s' from '%s'" % (path, src.get_url())
+ for a, t in zip(args, types):
+ print "argument of type '%s': %s" % (t, a)
+
+# register method taking an int and a float
+server.add_method("/foo/bar", 'if', foo_bar_callback)
+
+# register method taking a blob, and passing user data to the callback
+server.add_method("/foo/baz", 'b', foo_baz_callback, "blah")
+
+# register a fallback for unhandled messages
+server.add_method(None, None, fallback)
+
+# loop and dispatch messages every 100ms
+while True:
+ server.recv(100)