From eaaef5460a95d2de1dddc847f6c3bbcb2aef8047 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 25 Jan 2011 00:33:46 -0500 Subject: Adding an OSC input. --- behaviors/DebugBehavior.py | 2 +- behaviors/MrmrSetColor.py | 21 +++++++++++++++++++++ behaviors/Square.py | 15 ++++++++------- 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 behaviors/MrmrSetColor.py (limited to 'behaviors') diff --git a/behaviors/DebugBehavior.py b/behaviors/DebugBehavior.py index 34f4106..17383db 100644 --- a/behaviors/DebugBehavior.py +++ b/behaviors/DebugBehavior.py @@ -4,5 +4,5 @@ import pdb class DebugBehavior(Behavior): def processResponse(self, sensorInputs, recursiveInputs): if sensorInputs != []: - main_log.debug('Sensor Inputs: ' + str(sensorInputs)) + main_log.error('Sensor Inputs: ' + str(sensorInputs)) return ([], []) 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/Square.py b/behaviors/Square.py index aef3622..ecd000c 100644 --- a/behaviors/Square.py +++ b/behaviors/Square.py @@ -2,11 +2,12 @@ from operationscore.Behavior import * class Square(Behavior): def processResponse(self, sensorInputs, recursiveInputs): for sensory in sensorInputs:#TODO: consider replicating the dict - xLoc = sensory['Location'][0] - yLoc = sensory['Location'][1] - width = self['Width'] - #sensory['Location'] = 'True' - sensory['Location'] =\ - '{x}<'+str(xLoc+width)+',{x}>'+str(xLoc-width)+\ - ',{y}<'+str(yLoc+width)+',{y}>'+str(yLoc-width) + if 'Location' in sensory: + xLoc = sensory['Location'][0] + yLoc = sensory['Location'][1] + width = self['Width'] + #sensory['Location'] = 'True' + sensory['Location'] =\ + '{x}<'+str(xLoc+width)+',{x}>'+str(xLoc-width)+\ + ',{y}<'+str(yLoc+width)+',{y}>'+str(yLoc-width) return (sensorInputs, recursiveInputs) -- cgit v1.2.3