aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Russell Cohen <rcoh@mit.edu>2011-01-12 11:58:00 -0500
committerGravatar Russell Cohen <rcoh@mit.edu>2011-01-12 11:58:00 -0500
commit907780f6b298bfa259ace94d07ca137099067e67 (patch)
treea12e1f555c27982b39a49c89383544773ba08039
parentc7fc6c2725231eb1427f0edf00d3219409b3d55b (diff)
Added ResponseMover to facilitate spawn and run responses. Modified
simplemapper to fix a bug with null responses.
-rw-r--r--behaviors/PixelDecay.xml9
-rw-r--r--behaviors/RandomWalk.py13
-rw-r--r--behaviors/ResponseMover.py (renamed from ResponseMover.py)2
-rw-r--r--config/Outdoor.xml36
-rwxr-xr-x[-rw-r--r--]ga0
-rw-r--r--pixelcore/Screen.py3
-rw-r--r--pixelmappers/SimpleMapper.py5
-rw-r--r--util/Config.py1
8 files changed, 58 insertions, 11 deletions
diff --git a/behaviors/PixelDecay.xml b/behaviors/PixelDecay.xml
index bfe84ca..c19a1a8 100644
--- a/behaviors/PixelDecay.xml
+++ b/behaviors/PixelDecay.xml
@@ -1,12 +1,3 @@
-<!--<Behavior>
- <Class>behaviors.DecayBehavior</Class>
- <Args>
- <DecayType>Exponential</DecayType>
- <Coefficient>.01</Coefficient>
- <z-index>0</z-index>
- <RenderToScreen>False</RenderToScreen>
- </Args>
-</Behavior>-->
<Behavior>
<Class>behaviors.AddPixelEvent</Class>
<Args>
diff --git a/behaviors/RandomWalk.py b/behaviors/RandomWalk.py
index 8254430..5a32792 100644
--- a/behaviors/RandomWalk.py
+++ b/behaviors/RandomWalk.py
@@ -1,5 +1,18 @@
from operationscore.Behavior import *
import util.ComponentRegistry as compReg
+import util.Geo as Geo
+import util.Strings as Strings
+import random
class RandomWalk(Behavior):
def processResponse(self, sensors, recursives):
+ ret = []
+ for sensory in sensors:
+ s = self['StepSize']
+ step = [random.randint(-s,s), random.randint(-s,s)]
+ outdict = dict(sensory)
+ outdict[Strings.LOCATION] = Geo.addLocations(step, outdict[Strings.LOCATION])
+ ret.append(outdict)
+ return (ret,recursives)
+
+
diff --git a/ResponseMover.py b/behaviors/ResponseMover.py
index 718400d..e1faccb 100644
--- a/ResponseMover.py
+++ b/behaviors/ResponseMover.py
@@ -1,3 +1,4 @@
+import pdb
from operationscore.Behavior import *
import util.ComponentRegistry as compReg
#ResponseMover is a scaffold for behaviors that spawn 'walkers' which act autonomously on input.
@@ -6,7 +7,6 @@ class ResponseMover(Behavior):
def processResponse(self, sensorInputs, recursiveInputs):
newResponses = sensorInputs
ret = []
- ret += newResponses
for recurInput in recursiveInputs:
outDict = dict(recurInput)
ret.append(outDict)
diff --git a/config/Outdoor.xml b/config/Outdoor.xml
index 5ad2c58..e3a74f4 100644
--- a/config/Outdoor.xml
+++ b/config/Outdoor.xml
@@ -72,6 +72,12 @@
</Behavior>
<Behavior Id="colorchange">
<InheritsFrom>behaviors/RandomColor.xml</InheritsFrom>
+ <Args>
+ <ColorList>
+ <Color>(0,255,0)</Color>
+ <Color>(255,0,0)</Color>
+ </ColorList>
+ </Args>
</Behavior>
<Behavior Id="decay">
<InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom>
@@ -129,6 +135,36 @@
<Mapper>gaussmap</Mapper>
</Args>
</Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>randomwalk</Id>
+ <Inputs>
+ <Id>pygame</Id>
+ </Inputs>
+ <ChainedBehaviors>
+ <Id>colorchange</Id>
+ <Id>mover</Id>
+ <Id>decay</Id>
+ </ChainedBehaviors>
+ <RecursiveHooks>{'mover':'randmovement'}</RecursiveHooks>
+ <RenderToScreen>True</RenderToScreen>
+ <Mapper>gaussmap</Mapper>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.ResponseMover</Class>
+ <Args>
+ <Id>mover</Id>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.RandomWalk</Class>
+ <Args>
+ <Id>randmovement</Id>
+ <StepSize>2</StepSize>
+ </Args>
+ </Behavior>
<Behavior Id="accelerate">
<InheritsFrom>behaviors/Accelerate.xml</InheritsFrom>
</Behavior>
diff --git a/ga b/ga
index 7bed4ad..7bed4ad 100644..100755
--- a/ga
+++ b/ga
diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py
index 3e8ad5e..77bebb6 100644
--- a/pixelcore/Screen.py
+++ b/pixelcore/Screen.py
@@ -8,6 +8,7 @@ import util.Strings as Strings
import util.TimeOps as timeops
import itertools
import sys
+import pdb
from logger import main_log
#Class representing a collection of Pixels grouped into PixelStrips. Needs a
#PixelMapper, currently set via setMapper by may be migrated into the argDict.
@@ -91,5 +92,7 @@ class Screen:
PixelEvent.addPixelEventIfMissing(responseInfo)
currentTime = timeops.time()
for (pixel, weight) in pixelWeightList:
+ if pixel == None:
+ pdb.set_trace()
pixel.processInput(responseInfo['PixelEvent'].scale(weight), 0, currentTime) #TODO: z-index
diff --git a/pixelmappers/SimpleMapper.py b/pixelmappers/SimpleMapper.py
index 31a48cc..396eca3 100644
--- a/pixelmappers/SimpleMapper.py
+++ b/pixelmappers/SimpleMapper.py
@@ -13,7 +13,10 @@ class SimpleMapper(PixelMapper):
if pixelDist < bestDist:
bestPixel = pixel
bestDist = pixelDist
- return [(bestPixel,1)]
+ if bestPixel != None:
+ return [(bestPixel,1)]
+ else:
+ return []
else:
#{x}>5,{y}<k
#TODO: we should probably encapsulate this somewhere
diff --git a/util/Config.py b/util/Config.py
index 4c1eb1e..1e20cde 100644
--- a/util/Config.py
+++ b/util/Config.py
@@ -24,6 +24,7 @@ def loadConfigFile(fileName): #TODO: error handling etc.
return config
except Exception as inst:
main_log.error('Error loading config file ' + fileName)#, inst) TODO: log exception too
+ main_log.error(str(inst))
return None
#Takes an Element or an ElementTree. If it is a tree, it returns its root. Otherwise, just returns
#it