diff options
Diffstat (limited to 'behaviors')
-rw-r--r-- | behaviors/ModifyParam.py | 7 | ||||
-rw-r--r-- | behaviors/MrmrSetColor.py | 21 | ||||
-rw-r--r-- | behaviors/TouchOSC.py | 33 | ||||
-rw-r--r-- | behaviors/XYMove.py | 1 |
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, []) |