aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-02-13 16:03:39 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-02-13 16:03:39 -0500
commit6e0e6869a5ee1e4963071a18f24aa4dfdd442689 (patch)
tree59dfe233e69f331afe3be9137fe5638f359e1f56
parentf6dd5ab92949843d2fb163e2d84f19e824a291dc (diff)
Added a circle behavior to make circles. Added ContinuousCenterInput to do what it says. Modified
SimpleMapper a bit.
-rw-r--r--behaviors/Circle.py29
-rw-r--r--behaviors/ModifyParam.py2
-rw-r--r--config/C5Sign.xml84
-rw-r--r--inputs/ContinuousCenterInput.py12
-rw-r--r--pixelcore/Screen.py2
-rw-r--r--pixelmappers/SimpleMapper.py17
6 files changed, 132 insertions, 14 deletions
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 @@
<RefreshInterval>50</RefreshInterval>
</Args>
</InputElement>
+ <InputElement>
+ <Class>inputs.ContinuousCenterInput</Class>
+ <Args>
+ <Id>center</Id>
+ <RefreshInterval>1800</RefreshInterval>
+ </Args>
+ </InputElement>
<!--<InputElement>
<Class>inputs.TCPInput</Class>
<Args>
@@ -76,7 +83,7 @@
<RefreshInterval>10</RefreshInterval>
</Args>
</InputElement>-->
- <InputElement Id="followmouse" RefreshInterval="1000">
+ <InputElement Id="followmouse" RefreshInterval="10">
<InheritsFrom>inputs/MouseFollower.xml</InheritsFrom>
</InputElement>
</InputConfiguration>
@@ -90,10 +97,10 @@
<Behavior Id="colorchange">
<InheritsFrom>behaviors/RandomColor.xml</InheritsFrom>
<Args>
- <ColorList>
+ <!--ColorList>
<Val>(255,0,0)</Val>
<Val>(0,0,255)</Val>
- </ColorList>
+ </ColorList-->
</Args>
</Behavior>
<Behavior>
@@ -108,7 +115,7 @@
<Id>decay</Id>
</ChainedBehaviors>
<Mapper>gaussmap</Mapper>
- <RenderToScreen>True</RenderToScreen>
+ <RenderToScreen>False</RenderToScreen>
</Args>
</Behavior>
<Behavior Id="decay">
@@ -155,7 +162,6 @@
<Id>movebounce</Id>
<ChainedBehaviors>
<Id>xymove</Id>
- <!--Id>colorshift</Id-->
<Id>ybounce</Id>
<Id>xbounce</Id>
</ChainedBehaviors>
@@ -207,7 +213,7 @@
<Id>decay</Id>
</ChainedBehaviors>
<RecursiveHooks>{'mover':'movebounce'}</RecursiveHooks>
- <RenderToScreen>True</RenderToScreen>
+ <RenderToScreen>False</RenderToScreen>
<Mapper>gaussmap</Mapper>
</Args>
</Behavior>
@@ -246,16 +252,78 @@
<Args>
<Id>mousechaser</Id>
<Inputs>
- <Id>followmouse</Id>
</Inputs>
<ChainedBehaviors>
<Id>echo</Id>
- <Id>square</Id>
+ <Id>innercircle</Id>
+ <Id>outercircle</Id>
<Id>singleframe</Id>
</ChainedBehaviors>
<RenderToScreen>False</RenderToScreen>
</Args>
</Behavior>
+ <Behavior>
+ <Class>behaviors.Circle</Class>
+ <Args>
+ <Id>innercircle</Id>
+ <Radius>0</Radius>
+ <Outside>True</Outside>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.Circle</Class>
+ <Args>
+ <Id>outercircle</Id>
+ <Radius>3</Radius>
+ <Combine>True</Combine>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.ModifyParam</Class>
+ <Args>
+ <Id>incrinner</Id>
+ <ParamOp>{val}+.3</ParamOp>
+ <ParamName>innercircleRadius</ParamName>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.ModifyParam</Class>
+ <Args>
+ <Id>incrouter</Id>
+ <ParamOp>{val}+.3</ParamOp>
+ <ParamName>outercircleRadius</ParamName>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>circle_expand</Id>
+ <ChainedBehaviors>
+ <Id>innercircle</Id>
+ <Id>outercircle</Id>
+ <Id>incrinner</Id>
+ <Id>incrouter</Id>
+ <Id>recursivedecay</Id>
+ </ChainedBehaviors>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>expandingcirlces</Id>
+ <Inputs>
+ <Id>pygameclick</Id>
+ <Id>center</Id>
+ </Inputs>
+ <ChainedBehaviors>
+ <Id>colorchange</Id>
+ <Id>mover</Id>
+ <Id>decay</Id>
+ </ChainedBehaviors>
+ <RecursiveHooks>{'mover':'circle_expand'}</RecursiveHooks>
+ <RenderToScreen>True</RenderToScreen>
+ </Args>
+ </Behavior>
<Behavior Id="running">
<InheritsFrom>behaviors/RunningBehavior.xml</InheritsFrom>
</Behavior>
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}<k
ret = []
- eventLocation = eventLocation.replace('{x}', 'pixel.location[0]')
- eventLocation = eventLocation.replace('{y}', 'pixel.location[1]')
- conditions = eventLocation.split(',')
+ if not isinstance(eventLocation, list):
+ eventLocation = eventLocation.replace('{x}', 'pixel.location[0]')
+ eventLocation = eventLocation.replace('{y}', 'pixel.location[1]')
+ conditions = eventLocation.split(',')
+ else:
+ conditions = eventLocation #TODO: check for lists of strings
conditionLambdas = [eval('lambda pixel:'+condition) for condition in conditions]
+
for pixel in screen:
try:
pixelValid = True
@@ -38,6 +44,7 @@ class SimpleMapper(PixelMapper):
if pixelValid:
ret.append((pixel, 1))
except Exception as exp:
+ import pdb; pdb.set_trace()
raise Exception('Bad event condition')
return ret