From 42a3112b7cd7518ab69ba8d69c636a6278cfb288 Mon Sep 17 00:00:00 2001 From: dxiao Date: Sun, 20 Feb 2011 19:30:43 -0500 Subject: Added SplitBehavior and RunFinite behaviors --- behaviors/RunFinite.py | 25 +++++++++++++++++++++++++ behaviors/SplitBehavior.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ config/C5Sign.xml | 28 +++++++++++++++++++++++----- 3 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 behaviors/RunFinite.py create mode 100644 behaviors/SplitBehavior.py diff --git a/behaviors/RunFinite.py b/behaviors/RunFinite.py new file mode 100644 index 0000000..de2ce27 --- /dev/null +++ b/behaviors/RunFinite.py @@ -0,0 +1,25 @@ +from operationscore.Behavior import * +import util.ComponentRegistry as compReg + +class RunFinite(Behavior): + """RunFinite will just wire input to output, but only a finite number of + times as specified by the Iterations argument tag""" + + def behaviorInit(self): + pass + + def processResponse(self, inp, state): + + if state: + iterations = state + else: + iterations = self['Iterations'] + + if iterations > 0: + out = inp + else: + out = [] + + iterations -= 1 + + return (out, iterations) diff --git a/behaviors/SplitBehavior.py b/behaviors/SplitBehavior.py new file mode 100644 index 0000000..1892ad3 --- /dev/null +++ b/behaviors/SplitBehavior.py @@ -0,0 +1,45 @@ +from operationscore.Behavior import * +import util.ComponentRegistry as compReg + +class SplitBehavior(Behavior): + """SplitBehavior takes a list of behaviors, runs the input on all behaviors + listed, and then returns the concantenation of all the behavior outputs. + Behavior list is given under tag as a list of Id's + + Example: + + behaviors.SplitBehavior + + splitbehavior + + behavior1Id + behavior2Id + + + + """ + + def behaviorInit(self): + pass + + def processResponse(self, inp, state): + + out = [] + newstate = {} + for behaviorId in self['BehaviorList']: + + behavior = compReg.getComponent(behaviorId) + if behaviorId in state: + behaviorState = state[behaviorId] + else: + behaviorState = [] + + #print behaviorId, " ", str(inp), ",", str(behaviorState) + output = behavior.immediateProcessInput(inp, behaviorState) + (behaviorOutput, behaviorState) = output + #print " -->", str(behaviorState), ",", str(behaviorOutput) + + newstate[behaviorId] = behaviorState + out.extend(behaviorOutput) + + return (out, newstate) diff --git a/config/C5Sign.xml b/config/C5Sign.xml index f99ef2b..93b3028 100644 --- a/config/C5Sign.xml +++ b/config/C5Sign.xml @@ -230,8 +230,8 @@ centerleft center - {'scanningbars':10,'runcolordecay':10,'expandingcircles':10} - {'scanningbars':'centerleft', 'runcolordecay':'center',\ + {'framedbars':10,'runcolordecay':10,'expandingcircles':10} + {'framedbars':'centerleft', 'runcolordecay':'center',\ 'expandingcircles':'center'} True @@ -332,14 +332,22 @@ + + behaviors.RunFinite + + runonce + 1 + + behaviors.BehaviorChain coloredframe - + + runonce redcolor square mover @@ -347,7 +355,17 @@ stripsonly {'mover':'colorshift'} - True + False + + + + behaviors.SplitBehavior + + framedbars + + coloredframe + scanningbars + -- cgit v1.2.3