aboutsummaryrefslogtreecommitdiff
path: root/behaviors
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 /behaviors
parent32fdbbb7512576cb8a54556640b18be160d655d1 (diff)
parentf103e47da5d563d1b8448bc021676ed7db0f529d (diff)
Merge branch 'master' of github.com:rcoh/SmootLight into mobileapp
Diffstat (limited to 'behaviors')
-rw-r--r--behaviors/ModifyParam.py7
-rw-r--r--behaviors/MrmrSetColor.py21
-rw-r--r--behaviors/TouchOSC.py33
-rw-r--r--behaviors/XYMove.py1
4 files changed, 61 insertions, 1 deletions
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, [])