aboutsummaryrefslogtreecommitdiff
path: root/behaviors
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
parent83931a3c8e65b4018e98b4986458d1df7172ab91 (diff)
parent277a5143165d2553ce5e97f151cc6b3cea426468 (diff)
Merge branch 'master' of github.com:rcoh/SmootLight
Diffstat (limited to 'behaviors')
-rw-r--r--behaviors/Accelerate.xml2
-rw-r--r--behaviors/AddPixelEvent.py2
-rw-r--r--behaviors/ControllerOSC.py62
-rw-r--r--behaviors/Deccelerate.xml9
-rw-r--r--behaviors/DimColor.xml2
-rw-r--r--behaviors/EchoBehavior.py5
-rw-r--r--behaviors/Expand.py3
-rw-r--r--behaviors/ExpandingColorZones.py21
-rw-r--r--behaviors/Flasher.py41
-rw-r--r--behaviors/MITDoors.py8
-rw-r--r--behaviors/MobileShakeBehavior.py29
-rw-r--r--behaviors/MoveBehavior.py7
-rw-r--r--behaviors/RandomSetBrightColorBehavior.py14
-rw-r--r--behaviors/ResponseMover.py8
-rw-r--r--behaviors/RiseFall.py6
-rw-r--r--behaviors/Sink.py42
-rwxr-xr-xbehaviors/SmootWind.py43
-rw-r--r--behaviors/SynchTest.py12
-rw-r--r--behaviors/TouchOSC.py5
-rw-r--r--behaviors/XYMove.py1
20 files changed, 293 insertions, 29 deletions
diff --git a/behaviors/Accelerate.xml b/behaviors/Accelerate.xml
index f9de077..c78195b 100644
--- a/behaviors/Accelerate.xml
+++ b/behaviors/Accelerate.xml
@@ -3,6 +3,6 @@
<Args>
<ParamType>Sensor</ParamType>
<ParamName>StepSize</ParamName>
- <ParamOp>{val}*1.1</ParamOp>
+ <ParamOp>{val}*1.01</ParamOp>
</Args>
</Behavior>
diff --git a/behaviors/AddPixelEvent.py b/behaviors/AddPixelEvent.py
index 821f432..da3f7c2 100644
--- a/behaviors/AddPixelEvent.py
+++ b/behaviors/AddPixelEvent.py
@@ -21,8 +21,6 @@ class AddPixelEvent(Behavior):
ret = []
for sensory in sensors:
outDict = {}
- if not 'Location' in sensory:
- pdb.set_trace()
outDict[Strings.LOCATION] = sensory[Strings.LOCATION]
settingsDict = dict(self.argDict)
settingsDict['Color'] = sensory['Color']
diff --git a/behaviors/ControllerOSC.py b/behaviors/ControllerOSC.py
new file mode 100644
index 0000000..05d2e7d
--- /dev/null
+++ b/behaviors/ControllerOSC.py
@@ -0,0 +1,62 @@
+from operationscore.Behavior import *
+from logger import main_log
+#import util.ColorOps as color
+import colorsys
+from numpy import array
+import pdb
+import util.ComponentRegistry as compReg
+
+speedfactor = 15
+vel_decay = .9
+
+def constrainLocation(v,c):
+ if v[0] > c[0]:
+ v[0] = c[0]
+ elif v[0]<0:
+ v[0] = 0
+
+ if v[1] > c[1]:
+ v[1] = c[1]
+ elif v[1]<0:
+ v[1] = 0
+
+ return v
+
+class ControllerOSC(Behavior):
+ def behaviorInit(self):
+ self.xy = array((0,0))
+ self.v_xy = array((0,0))
+ self.v_decay = vel_decay
+
+ self.start_hsv = [0,1,1]
+ self.dest_hsv = [0,1,1]
+ self.ssize = compReg.getComponent('Screen').getSize()[-2:] #896 x 310
+
+ def processResponse(self, sensorInputs, recursiveInputs):
+ ret = []
+ if sensorInputs:
+ data = sensorInputs[-1]#for data in sensorInputs:
+ if data['Path'] == '/sixaxis/xy':
+ #try:
+ x = data['Value'][0]
+ y = data['Value'][1]
+ if y < 0:
+ self.start_hsv[1] = 1.0+y #s
+ else:
+ self.start_hsv[2] = 1.0-y
+ self.start_hsv[0] = (x+1)/2.
+ elif data['Path'] == '/sixaxis/lrud':
+ val=data['Value']
+ vy = val[3]-val[2]
+ vx = val[1]-val[0]
+ #pdb.set_trace()
+ #self.v_xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1])
+ self.v_xy = array((vx, vy)) * speedfactor
+ else:
+ main_log.error('Sensor Inputs: ' + str(sensorInputs))
+ self.xy = self.xy + self.v_xy
+ constrainLocation(self.xy,self.ssize)
+ self.v_xy *= self.v_decay
+ ret.append({'Color':[i*255. for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':(int(self.xy[0]), int(self.xy[1]))})
+
+ return (ret, [])
diff --git a/behaviors/Deccelerate.xml b/behaviors/Deccelerate.xml
new file mode 100644
index 0000000..e64e61d
--- /dev/null
+++ b/behaviors/Deccelerate.xml
@@ -0,0 +1,9 @@
+
+<Behavior>
+ <Class>behaviors.ModifyParam</Class>
+ <Args>
+ <ParamType>Sensor</ParamType>
+ <ParamName>StepSize</ParamName>
+ <ParamOp>{val}*.98</ParamOp>
+ </Args>
+</Behavior>
diff --git a/behaviors/DimColor.xml b/behaviors/DimColor.xml
index 58b0673..ef98fee 100644
--- a/behaviors/DimColor.xml
+++ b/behaviors/DimColor.xml
@@ -3,6 +3,6 @@
<Args>
<ParamType>Sensor</ParamType>
<ParamName>Color</ParamName>
- <ParamOp>[chan*.95 for chan in {val}]</ParamOp>
+ <ParamOp>[chan*.98 for chan in {val}]</ParamOp>
</Args>
</Behavior>
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/Expand.py b/behaviors/Expand.py
index 323e71f..f017c16 100644
--- a/behaviors/Expand.py
+++ b/behaviors/Expand.py
@@ -15,7 +15,8 @@ class Expand(Behavior):
data = dict(data)
data['Left'] -= data['ExpandRate']
data['Right'] += data['ExpandRate']
- data['Location'] = "{x}>" + str(data['Left']) + ", {x}<" + str(data['Right'])
+ data['Location'] = "{x}>" + str(data['Left']) + ", {x}<" +\
+ str(data['Right'])+", {y}<50"
ret.append(data)
return (ret, [])
diff --git a/behaviors/ExpandingColorZones.py b/behaviors/ExpandingColorZones.py
new file mode 100644
index 0000000..75be761
--- /dev/null
+++ b/behaviors/ExpandingColorZones.py
@@ -0,0 +1,21 @@
+from operationscore.Behavior import *
+from logger import main_log
+class ExpandingColorZones(Behavior):
+ def behaviorInit(self):
+ self.mapping = {'s001':[(132,0),(255,0,0)], 's002':[(400,0), (0,255,0)],
+ 's003':[(668,0),
+ (0,0,255)]}
+ self.mappingkey = 'data'
+ def processResponse(self, sensorInputs, recursiveInputs):
+ ret = []
+ for data in sensorInputs:
+ print data
+ data = dict(data)
+ if self.mappingkey in data:
+ try:
+ data['Location'], data['Color'] =\
+ self.mapping[data[self.mappingkey]]
+ ret.append(data)
+ except:
+ main_log.warn('Bad mapping key. Expanding Color Zones.')
+ return (ret,[])
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
diff --git a/behaviors/MITDoors.py b/behaviors/MITDoors.py
index d602a55..cee47f0 100644
--- a/behaviors/MITDoors.py
+++ b/behaviors/MITDoors.py
@@ -1,4 +1,6 @@
from operationscore.Behavior import *
+import math
+import util.ComponentRegistry as compReg
class MITDoors(Behavior):
"""MITDoors is a case-specific behavior to map keypresses to specific locations. Written for
Kuan 1/26/11 by RCOH"""
@@ -6,6 +8,11 @@ class MITDoors(Behavior):
def behaviorInit(self):
self.keymapping = {'q':[2,19], 'w':[22,36], 'e':[37,49], 'r':[52,69], 't':[76,91], 'y':[94,105],
'u':[106,117], 'i':[123,154], 'o':[158,161], 'p':[164,167], '[':[172,184]}
+ screenWidth = compReg.getComponent('Screen').getSize()[2] #(minx, miny,maxx, maxy)
+ maxKey = max([max(self.keymapping[v]) for v in self.keymapping])
+ mult = screenWidth / float(maxKey)
+ for k in self.keymapping:
+ self.keymapping[k] = [int(val*mult) for val in self.keymapping[k]]
def processResponse(self, sensorInputs, recursiveInputs):
ret = []
for data in sensorInputs:
@@ -16,5 +23,6 @@ class MITDoors(Behavior):
data['Left'], data['Right'] = bounds
data['Bottom'] = self['Bottom']
data['Location'] = (sum(bounds) / 2., self['Bottom'])
+ data['Oscillate'] = False
ret.append(data)
return (ret, [])
diff --git a/behaviors/MobileShakeBehavior.py b/behaviors/MobileShakeBehavior.py
index e25e929..b05cb5f 100644
--- a/behaviors/MobileShakeBehavior.py
+++ b/behaviors/MobileShakeBehavior.py
@@ -1,17 +1,26 @@
from operationscore.Behavior import *
+import util.ComponentRegistry as compReg
import util.Strings as Strings
class MobileShakeBehavior(Behavior):
+ def behaviorInit(self):
+ self.mapper = None
+
def processResponse(self, sensorInputs, recursiveInputs):
+ if self.mapper == None:
+ try:
+ self.mapper = compReg.getComponent('mobilegaussmap')
+ except KeyError:
+ pass
+
#print sensorInputs
- ret = []
for sInput in sensorInputs:
- outDict = dict(sInput)
- if 'type' in sInput and sInput['type'] == 2:
- outDict['Location'] = '{x}>' + str(0) + ',{y}>' + str(0)
- outDict['Color'] = [sInput['r'], sInput['g'], sInput['b']]
- else: # dumb invisible pixel
- outDict['Location'] = (-1, -1)
- outDict['Color'] = [0, 0, 0]
- ret.append(outDict)
- return (ret, recursiveInputs)
+ if 'Shake' in sInput and sInput['Shake'] == 1:
+ #print 'increase!'
+ self.mapper.argDict['Width'] += 30
+ #self.mapper.argDict['CutoffDist'] += 20
+ sInput['Shake'] = 0
+ print 'Width:' + str(compReg.getComponent('mobilegaussmap').argDict['Width'])
+ #print 'CutoffDist: '+ str(compReg.getComponent('mobilegaussmap').argDict['CutoffDist'])
+
+ return (sensorInputs, recursiveInputs)
diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py
index e504ca9..6e7fc6a 100644
--- a/behaviors/MoveBehavior.py
+++ b/behaviors/MoveBehavior.py
@@ -19,12 +19,13 @@ class MoveBehavior(Behavior):
currDict = dict(currRecLoc)
for sensorInput in sensorInputs:
if 'type' in sensorInput and sensorInput['type'] == 1:
+ currDict['Shake'] = 0
currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \
currDict['Location'][1] + sensorInput['y'] * self['YStep'])
currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']]
- #elif sensorInput['type'] == 2:
- # currDict['Shake'] = 1
- # currDict['Force'] = sensorInput['force']
+ elif sensorInput['type'] == 2:
+ currDict['Shake'] = 1
+ #currDict['Force'] = sensorInput['force']
ret.append(currDict)
#print ret
return (ret, ret)
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/behaviors/ResponseMover.py b/behaviors/ResponseMover.py
index 59e353a..3d559df 100644
--- a/behaviors/ResponseMover.py
+++ b/behaviors/ResponseMover.py
@@ -7,11 +7,5 @@ class ResponseMover(Behavior):
modulates the location."""
def processResponse(self, sensorInputs, recursiveInputs):
- newResponses = sensorInputs
- ret = []
- for recurInput in recursiveInputs:
- outDict = dict(recurInput)
- ret.append(outDict)
- ret += newResponses
- return (ret, ret)
+ return (recursiveInputs, recursiveInputs+sensorInputs)
diff --git a/behaviors/RiseFall.py b/behaviors/RiseFall.py
index 109cd10..eea2283 100644
--- a/behaviors/RiseFall.py
+++ b/behaviors/RiseFall.py
@@ -29,7 +29,13 @@ class RiseFall(Behavior):
data['Right'] = data['Location'][0]+data['Width']/2.
currentTime = timeOps.time()
deltaTime = currentTime-data['StartTime']
+ #if data['Oscillate'] == True:
data['Height'] = data['MaxHeight']*math.sin(deltaTime/data['Period']*(math.pi*2))
+ #else:
+ # data['Height'] = data['MaxHeight']
+ #if (currentTime-data['StartTime']) > data['Period']:
+ # del data['StartTime']
+
data['Location'] = "{x}>"+str(data['Left']) + ", " +\
"{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\
{y}>"+str(data['Bottom']-data['Height'])
diff --git a/behaviors/Sink.py b/behaviors/Sink.py
new file mode 100644
index 0000000..52d0be2
--- /dev/null
+++ b/behaviors/Sink.py
@@ -0,0 +1,42 @@
+
+from operationscore.Behavior import *
+import math
+import util.TimeOps as timeOps
+#Required Args:
+#Period (ms), MaxHeight, Width
+class Sink(Behavior):
+ """RiseFall is a behavior that creates a rising and falling column of light. Specify:
+ <MaxHeight> -- the maximum height that it rises to.
+ <Width> -- the width of the column OR <Left> and <Right>
+ <Period> -- the period of oscillation in ms
+
+ Designed to be used as part of a recursive hook.
+ """
+
+ def processResponse(self, sensorInputs, recurInputs):
+ ret = []
+ for data in sensorInputs:
+ #first time with behavior:
+ data = dict(data)
+ if not 'StartTime' in data:
+ data['StartTime'] = timeOps.time()
+ data['Period'] = self['Period']
+ data['MaxHeight'] = self['MaxHeight'] #Consider just using +=
+ if not 'Bottom' in data:
+ data['Bottom'] = data['Location'][1]
+ if 'Width' in self: #TODO: improve
+ data['Width'] = self['Width']
+ data['Left'] = data['Location'][0]-data['Width']/2.
+ data['Right'] = data['Location'][0]+data['Width']/2.
+ currentTime = timeOps.time()
+ deltaTime = currentTime-data['StartTime']
+ data['Height'] = data['MaxHeight']*math.cos(deltaTime/data['Period']*(math.pi*2))
+
+ data['Location'] = "{x}>"+str(data['Left']) + ", " +\
+ "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\
+ {y}>"+str(data['Bottom']-data['Height'])
+
+ ret.append(data)
+ return (ret, [])
+
+
diff --git a/behaviors/SmootWind.py b/behaviors/SmootWind.py
new file mode 100755
index 0000000..804183c
--- /dev/null
+++ b/behaviors/SmootWind.py
@@ -0,0 +1,43 @@
+from operationscore.Behavior import *
+import util.ComponentRegistry as compReg
+import random
+
+class SmootWind(Behavior):
+ def behaviorInit(self):
+ self.mapper = None
+ self.xFor = None
+
+ def processResponse(self, sensorInputs, recursiveInputs):
+ if self.mapper == None:
+ try:
+ self.mapper = compReg.getComponent('windgaussmap')
+ except KeyError:
+ pass
+ if self.xFor == None:
+ try:
+ self.xFor = compReg.getComponent('xfor')
+ except KeyError:
+ pass
+
+ for sensory in sensorInputs:
+ print sensory
+ # input[0] is windspeed, [1] is dir
+ if 0 in sensory and 1 in sensory:
+ windSpeed = sensory[0]
+ windDir = sensory[1]
+ #print self.mapper.argDict
+ self.mapper.argDict['Width'] = self.mapper.argDict['Width']+float(windSpeed)*2+20
+ self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+float(windSpeed)*3+10*random.random();
+ #print 'Width: ' + str(self.mapper.argDict['Width'])
+ #print 'xFor: ' + str(self.xFor.argDict['ParamOp'])
+
+ elif 'Key' in sensory:
+ if sensory['Key'] == 273:
+ self.mapper.argDict['Width'] = self.mapper.argDict['Width']+10;
+ self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+5;
+
+ elif sensory['Key'] == 274:
+ self.mapper.argDict['Width'] = self.mapper.argDict['Width']-10;
+ self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']-5;
+
+ return (sensorInputs, recursiveInputs)
diff --git a/behaviors/SynchTest.py b/behaviors/SynchTest.py
new file mode 100644
index 0000000..e7b8acc
--- /dev/null
+++ b/behaviors/SynchTest.py
@@ -0,0 +1,12 @@
+from operationscore.Behavior import *
+from pixelevents.SynchTestEvent import *
+import pdb
+class SynchTest(Behavior):
+ def behaviorInit(self):
+ self.rendered = False
+ def processResponse(self, sensorInputs, recurs):
+ if not self.rendered:
+ self.rendered = True
+ print 'here1'
+ return ([{'Location':'True', 'PixelEvent':SynchTestEvent({'Color':(255,0,0)})}], [])
+ return ([], [])
diff --git a/behaviors/TouchOSC.py b/behaviors/TouchOSC.py
index 1c41b5e..099d5e5 100644
--- a/behaviors/TouchOSC.py
+++ b/behaviors/TouchOSC.py
@@ -12,10 +12,11 @@ class TouchOSC(Behavior):
self.xy = (-1,-1)
def processResponse(self, sensorInputs, recursiveInputs):
ret = []
- for data in sensorInputs:
+ if sensorInputs:
+ data = sensorInputs[-1]#for data in sensorInputs:
if data['Path'] == '/1/fader1':
try:
- self.h = data['Value'][0]*360.0
+ self.h = data['Value'][0]
except:
pdb.set_trace()
elif data['Path'] == '/1/fader2':
diff --git a/behaviors/XYMove.py b/behaviors/XYMove.py
index 0ba3baf..11cee96 100644
--- a/behaviors/XYMove.py
+++ b/behaviors/XYMove.py
@@ -13,7 +13,6 @@ 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, [])