From 6e0e6869a5ee1e4963071a18f24aa4dfdd442689 Mon Sep 17 00:00:00 2001 From: rcoh Date: Sun, 13 Feb 2011 16:03:39 -0500 Subject: Added a circle behavior to make circles. Added ContinuousCenterInput to do what it says. Modified SimpleMapper a bit. --- behaviors/Circle.py | 29 ++++++++++++++ behaviors/ModifyParam.py | 2 + config/C5Sign.xml | 84 +++++++++++++++++++++++++++++++++++++---- inputs/ContinuousCenterInput.py | 12 ++++++ pixelcore/Screen.py | 2 +- pixelmappers/SimpleMapper.py | 17 ++++++--- 6 files changed, 132 insertions(+), 14 deletions(-) create mode 100644 behaviors/Circle.py create mode 100644 inputs/ContinuousCenterInput.py diff --git a/behaviors/Circle.py b/behaviors/Circle.py new file mode 100644 index 0000000..24d71f1 --- /dev/null +++ b/behaviors/Circle.py @@ -0,0 +1,29 @@ +from operationscore.Behavior import * +class Circle(Behavior): + def processResponse(self, sensors, recurs): + ret = [] + for data in sensors: + #import pdb; pdb.set_trace() + if 'CenterLoc' in data: + xLoc = data['CenterLoc'][0] + yLoc = data['CenterLoc'][1] + else: + data['CenterLoc'] = tuple(data['Location']) + xLoc = data['Location'][0] + yLoc = data['Location'][1] + if not self['Id']+'Radius' in data: + data[self['Id']+'Radius'] = self['Radius'] + rad = data[self['Id']+'Radius'] + cond = '>=' if self['Outside'] else '<=' + circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2))'+cond+str(rad) + if self['Combine']: + data['Location'] += ',' + circleStr + else: + data['Location'] = circleStr + ret.append(data) + return (ret, []) + def setLastOutput(self, output): + coutput = Behavior.deepCopyPacket(output) + for data in coutput: + data['Location'] = data['CenterLoc'] + return coutput diff --git a/behaviors/ModifyParam.py b/behaviors/ModifyParam.py index 0ef3a60..ebcb98f 100644 --- a/behaviors/ModifyParam.py +++ b/behaviors/ModifyParam.py @@ -30,6 +30,8 @@ class ModifyParam(Behavior): #TODO: move elsewhere paramOp = paramOp.replace('{y}', "behaviorInput['Location'][1]") paramOp = paramOp.replace('{x}', "behaviorInput['Location'][0]") + if eval(paramOp) == None: + import pdb; pdb.set_trace() behaviorInput[paramName] = eval(paramOp) if paramType == 'Sensor': #return accordingly return (searchSet, recursiveInputs) diff --git a/config/C5Sign.xml b/config/C5Sign.xml index 8c2871e..23a823a 100644 --- a/config/C5Sign.xml +++ b/config/C5Sign.xml @@ -68,6 +68,13 @@ 50 + + inputs.ContinuousCenterInput + + center + 1800 + + - + inputs/MouseFollower.xml @@ -90,10 +97,10 @@ behaviors/RandomColor.xml - + @@ -108,7 +115,7 @@ decay gaussmap - True + False @@ -155,7 +162,6 @@ movebounce xymove - ybounce xbounce @@ -207,7 +213,7 @@ decay {'mover':'movebounce'} - True + False gaussmap @@ -246,16 +252,78 @@ mousechaser - followmouse echo - square + innercircle + outercircle singleframe False + + behaviors.Circle + + innercircle + 0 + True + + + + behaviors.Circle + + outercircle + 3 + True + + + + behaviors.ModifyParam + + incrinner + {val}+.3 + innercircleRadius + + + + behaviors.ModifyParam + + incrouter + {val}+.3 + outercircleRadius + + + + behaviors.BehaviorChain + + circle_expand + + innercircle + outercircle + incrinner + incrouter + recursivedecay + + + + + behaviors.BehaviorChain + + expandingcirlces + + pygameclick + center + + + colorchange + mover + decay + + {'mover':'circle_expand'} + True + + behaviors/RunningBehavior.xml diff --git a/inputs/ContinuousCenterInput.py b/inputs/ContinuousCenterInput.py new file mode 100644 index 0000000..a7635b2 --- /dev/null +++ b/inputs/ContinuousCenterInput.py @@ -0,0 +1,12 @@ +import util.TimeOps as clock +import util.ComponentRegistry as compReg +import util.Strings as Strings +from operationscore.Input import * +class ContinuousCenterInput(Input): + def inputInit(self): + minX,minY,maxX,maxY = compReg.getComponent('Screen').getSize() + self.center = ((minX+maxX) / 2, (minY+maxY) / 2) + print self.center + def sensingLoop(self): + self.respond({Strings.LOCATION: self.center}) + diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py index ada8d4a..1bed4f1 100644 --- a/pixelcore/Screen.py +++ b/pixelcore/Screen.py @@ -79,7 +79,7 @@ class Screen: maxY = max(y, maxY) self.size = (0,0, maxX, maxY) self.sizeValid = True - return (0, 0, maxX, maxY) + return (minX, minY, maxX, maxY) #private def processResponse(self, responseInfo, currentTime=None): #we need to make a new dict for diff --git a/pixelmappers/SimpleMapper.py b/pixelmappers/SimpleMapper.py index 1568de3..6603c98 100644 --- a/pixelmappers/SimpleMapper.py +++ b/pixelmappers/SimpleMapper.py @@ -1,11 +1,13 @@ from operationscore.PixelMapper import * import util.Geo as Geo +import math import sys class SimpleMapper(PixelMapper): """SimpleMapper is a PixelMapper which maps events to the nearest Pixel. It also supports strings of the form: - {x}>5, {y}<10, {x}*{y}<{x}, etc. (Conditons, separated by commas. and and or may also be - used).""" + {x}>5, {y}<10, {x}*{y}<{x}, etc. (Conditions, separated by commas. Standard python syntax such + as and and or may also be + used). You may use 'math.' functions such as math.sqrt, etc. It also accepts lists of strings""" def mappingFunction(self, eventLocation, screen): if type(eventLocation) == type(tuple()): bestDist = sys.maxint @@ -24,10 +26,14 @@ class SimpleMapper(PixelMapper): else: #{x}>5,{y}