From 907780f6b298bfa259ace94d07ca137099067e67 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Wed, 12 Jan 2011 11:58:00 -0500 Subject: Added ResponseMover to facilitate spawn and run responses. Modified simplemapper to fix a bug with null responses. --- ResponseMover.py | 15 --------------- behaviors/PixelDecay.xml | 9 --------- behaviors/RandomWalk.py | 13 +++++++++++++ behaviors/ResponseMover.py | 15 +++++++++++++++ config/Outdoor.xml | 36 ++++++++++++++++++++++++++++++++++++ ga | 0 pixelcore/Screen.py | 3 +++ pixelmappers/SimpleMapper.py | 5 ++++- util/Config.py | 1 + 9 files changed, 72 insertions(+), 25 deletions(-) delete mode 100644 ResponseMover.py create mode 100644 behaviors/ResponseMover.py mode change 100644 => 100755 ga diff --git a/ResponseMover.py b/ResponseMover.py deleted file mode 100644 index 718400d..0000000 --- a/ResponseMover.py +++ /dev/null @@ -1,15 +0,0 @@ -from operationscore.Behavior import * -import util.ComponentRegistry as compReg -#ResponseMover is a scaffold for behaviors that spawn 'walkers' which act autonomously on input. -#Add a recursive hook to control the movement. -class ResponseMover(Behavior): - def processResponse(self, sensorInputs, recursiveInputs): - newResponses = sensorInputs - ret = [] - ret += newResponses - for recurInput in recursiveInputs: - outDict = dict(recurInput) - ret.append(outDict) - ret += newResponses - return (ret, ret) - 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 @@ - behaviors.AddPixelEvent 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/behaviors/ResponseMover.py b/behaviors/ResponseMover.py new file mode 100644 index 0000000..e1faccb --- /dev/null +++ b/behaviors/ResponseMover.py @@ -0,0 +1,15 @@ +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. +#Add a recursive hook to control the movement. +class ResponseMover(Behavior): + def processResponse(self, sensorInputs, recursiveInputs): + newResponses = sensorInputs + ret = [] + for recurInput in recursiveInputs: + outDict = dict(recurInput) + ret.append(outDict) + ret += newResponses + return (ret, ret) + 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 @@ behaviors/RandomColor.xml + + + (0,255,0) + (255,0,0) + + behaviors/PixelDecay.xml @@ -129,6 +135,36 @@ gaussmap + + behaviors.BehaviorChain + + randomwalk + + pygame + + + colorchange + mover + decay + + {'mover':'randmovement'} + True + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors.RandomWalk + + randmovement + 2 + + behaviors/Accelerate.xml diff --git a/ga b/ga old mode 100644 new mode 100755 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}