From 5783d6336f014c05e0e46d7bc35533e70b280582 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Thu, 25 Nov 2010 21:44:00 -0500 Subject: Added BehaviorChain to support chains of behaviors. Added FollowMouse parameter to PygameInput to support following of mice. Added component registry to Util which allows any component to access any other component. Some changes to the structure of LightInstallation. --- behaviors/BehaviorChain.py | 10 ++++++++++ behaviors/ColorChangerBehavior.py | 12 ++++++++++++ behaviors/DecayBehavior.py | 15 +++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 behaviors/BehaviorChain.py create mode 100644 behaviors/ColorChangerBehavior.py create mode 100644 behaviors/DecayBehavior.py (limited to 'behaviors') diff --git a/behaviors/BehaviorChain.py b/behaviors/BehaviorChain.py new file mode 100644 index 0000000..15f7d74 --- /dev/null +++ b/behaviors/BehaviorChain.py @@ -0,0 +1,10 @@ +from operationscore.Behavior import * +import Util +import pdb +class BehaviorChain(Behavior): + def processResponse(self, sensorInputs, recursiveInputs): + response = sensorInputs + for behaviorId in self['ChainedBehaviors']: + behavior = Util.getComponentById(behaviorId) + response = behavior.immediateProcessInput(response) + return response diff --git a/behaviors/ColorChangerBehavior.py b/behaviors/ColorChangerBehavior.py new file mode 100644 index 0000000..8ecc5f2 --- /dev/null +++ b/behaviors/ColorChangerBehavior.py @@ -0,0 +1,12 @@ +from operationscore.Behavior import * +import Util +import pdb +class ColorChangerBehavior(Behavior): + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + for sensory in sensorInputs: + newDict = dict(sensory) #don't run into shallow copy issues + #TODO: support for PixelEvents + newDict['Color'] = Util.randomColor() + ret.append(newDict) + return ret diff --git a/behaviors/DecayBehavior.py b/behaviors/DecayBehavior.py new file mode 100644 index 0000000..f9efa3b --- /dev/null +++ b/behaviors/DecayBehavior.py @@ -0,0 +1,15 @@ +from operationscore.Behavior import * +from pixelevents.DecayEvent import * +import Util +import pdb +class DecayBehavior(Behavior): + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + #TODO: move into params + for sensory in sensorInputs: + outDict = {} + outDict[Util.location] = sensory[Util.location] + outDict['PixelEvent'] = \ + DecayEvent.generate('Proportional',100, sensory['Color']) + ret.append(outDict) + return ret -- cgit v1.2.3