diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2011-02-20 23:00:18 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2011-02-20 23:00:18 -0500 |
commit | ee5dc03fbf6b75328295f5a6115f5d6a5c33455e (patch) | |
tree | db39963c35214ad0d7e33474e19e0ae221831c0a | |
parent | a742e43c387d089b344c0e293cf1b4292ee57c58 (diff) | |
parent | 6cb8952976d771d5f3be20a1eb1cd9b957651a54 (diff) |
Merge branch 'conner5' of git://github.com/dxiao/SmootLight into conner5
-rw-r--r-- | behaviors/RunFinite.py | 28 | ||||
-rw-r--r-- | behaviors/SplitBehavior.py | 45 | ||||
-rw-r--r-- | config/C5Sign-dxiao.xml | 396 | ||||
-rw-r--r-- | config/C5Sign-pygame.xml | 2 | ||||
-rw-r--r-- | config/C5Sign.xml | 63 | ||||
-rw-r--r-- | inputs/InitialLocationInput.py | 24 | ||||
-rw-r--r-- | operationscore/Input.py | 3 |
7 files changed, 162 insertions, 399 deletions
diff --git a/behaviors/RunFinite.py b/behaviors/RunFinite.py new file mode 100644 index 0000000..498998a --- /dev/null +++ b/behaviors/RunFinite.py @@ -0,0 +1,28 @@ +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): + + print "runfinite ", str(inp), ",", str(state) + if state != []: + iterations = state + else: + iterations = self['Iterations'] + + if iterations > 0: + out = inp + else: + out = [] + + if inp: + iterations -= 1 + + print " -->", str(iterations), ",", str(out) + 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 <BehaviorList> as a list of Id's + + Example: + <Behavior> + <Class>behaviors.SplitBehavior</Class> + <Args> + <Id>splitbehavior</Id> + <BehaviorList> + <Id>behavior1Id</Id> + <Id>behavior2Id</Id> + </BehaviorList> + </Args> + </Behavior> + """ + + 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-dxiao.xml b/config/C5Sign-dxiao.xml deleted file mode 100644 index 7dc4b81..0000000 --- a/config/C5Sign-dxiao.xml +++ /dev/null @@ -1,396 +0,0 @@ -<!---All configuration items contain a "Class" tag specifying the python class they represent, and an "Args" tag specifying the args to be passed in.--> -<LightInstallation> - <InstallationConfiguration> - <Defaults> - <PixelMapper>simplemap</PixelMapper> - </Defaults> - </InstallationConfiguration> - <PixelConfiguration> - <InheritsFrom>layouts/C5SignLayout.xml</InheritsFrom> - </PixelConfiguration> - <PixelMapperConfiguration> - <!-- ****************************** --> - <PixelMapper> - <Class>pixelmappers.C5SignMapper</Class> - <Args> - <Id>c5signmapper</Id> - <CutoffDist>20</CutoffDist> - </Args> - </PixelMapper> - <!-- ****************************** --> - <PixelMapper> - <Class>pixelmappers.SimpleMapper</Class> - <Args> - <Id>simplemap</Id> - <CutoffDist>20</CutoffDist> - </Args> - </PixelMapper> - <PixelMapper> - <Class>pixelmappers.GaussianMapper</Class> - <Args> - <Id>gaussmap</Id> - <CutoffDist>30</CutoffDist> - <MinWeight>0.1</MinWeight> - <Width>7</Width> - <Height>1</Height> - </Args> - </PixelMapper> - </PixelMapperConfiguration> - <RendererConfiguration> - <Renderer> - <InheritsFrom>renderers/C5Renderer.xml</InheritsFrom> - </Renderer> - <!--Renderer> - <InheritsFrom>renderers/Pygame.xml</InheritsFrom> - </Renderer--> - </RendererConfiguration> - <InputConfiguration> - <!--InputElement> - <Class>inputs.PygameInput</Class> - <Args> - <Id>pygameclick</Id> - <RefreshInterval>10</RefreshInterval> - <Clicks>True</Clicks> - </Args> - </InputElement--> - <InputElement> - <Class>inputs.OSCInput</Class> - <Args> - <Id>osc</Id> - <Port>1234</Port> - <RefreshInterval>10</RefreshInterval> - </Args> - </InputElement> - <!--InputElement> - <Class>inputs.PygameInput</Class> - <Args> - <Id>pygamekey</Id> - <RefreshInterval>10</RefreshInterval> - <Keyboard>True</Keyboard> - </Args> - </InputElement--> - <InputElement> - <Class>inputs.UDPInput</Class> - <Args> - <Id>udp</Id> - <Port>3344</Port> - <RefreshInterval>50</RefreshInterval> - </Args> - </InputElement> - <InputElement> - <Class>inputs.ContinuousCenterInput</Class> - <Args> - <Id>center</Id> - <RefreshInterval>1800</RefreshInterval> - </Args> - </InputElement> - <!-- ****************************** --> - <InputElement> - <Class>inputs.ContinuousLocationInput</Class> - <Args> - <Id>centerleft</Id> - <xloc>left</xloc> - <yloc>center</yloc> - <RefreshInterval>1800</RefreshInterval> - </Args> - </InputElement> - <!-- ****************************** --> - <!--<InputElement> - <Class>inputs.TCPInput</Class> - <Args> - <Id>tcp</Id> - <Port>20120</Port> - <RefreshInterval>10</RefreshInterval> - </Args> - </InputElement>--> - <!--InputElement Id="followmouse" RefreshInterval="10"> - <InheritsFrom>inputs/MouseFollower.xml</InheritsFrom> - </InputElement--> - </InputConfiguration> - <BehaviorConfiguration> - <Behavior> - <Args> - <Id>touchosc</Id> - </Args> - <Class>behaviors.TouchOSC</Class> - </Behavior> - <Behavior Id="colorchange"> - <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom> - <Args> - <!--ColorList> - <Val>(255,0,0)</Val> - <Val>(0,0,255)</Val> - </ColorList--> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.BehaviorChain</Class> - <Args> - <Id>OSCTouchChase</Id> - <Inputs> - <Id>osc</Id> - </Inputs> - <ChainedBehaviors> - <Id>touchosc</Id> - <Id>decay</Id> - </ChainedBehaviors> - <Mapper>gaussmap</Mapper> - <RenderToScreen>False</RenderToScreen> - </Args> - </Behavior> - <Behavior Id="decay"> - <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom> - </Behavior> - <Behavior Id="singleframe"> - <InheritsFrom>behaviors/SingleFrame.xml</InheritsFrom> - </Behavior> - <!-- ****************************** --> - <Behavior Id="slowdecay"> - <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom> - <Args> - <Coefficient>.001</Coefficient> - </Args> - </Behavior> - <!-- ****************************** --> - <Behavior> - <Class>behaviors.XYMove</Class> - <Args> - <Id>xymove</Id> - <XStep>1</XStep> - <YStep>1</YStep> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.RestrictLocation</Class> - <Args> - <Id>xbounce</Id> - <Action>{val}*-1</Action> - <ParamName>XStep</ParamName> - <LocationRestriction>{x}<2 or {x}>48</LocationRestriction> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.RestrictLocation</Class> - <Args> - <Id>ybounce</Id> - <Action>{val}*-1</Action> - <ParamName>YStep</ParamName> - <LocationRestriction>{y}<2 or {y}>24</LocationRestriction> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.BehaviorChain</Class> - <Args> - <Id>movebounce</Id> - <ChainedBehaviors> - <Id>xymove</Id> - <Id>ybounce</Id> - <Id>xbounce</Id> - </ChainedBehaviors> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.ModifyParam</Class> - <Args> - <Id>ysin</Id> - <ParamName>YStep</ParamName> - <ParamType>Sensor</ParamType> - <ParamOp>4*math.sin({x}/float(40))</ParamOp> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.DebugBehavior</Class> - <Args> - <Id>debug</Id> - <z-index>0</z-index> - <Inputs> - <Id>pygamekey</Id> - <Id>udp</Id> - </Inputs> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.AllPixels</Class> - <Args> - <Id>square</Id> - <Width>20</Width> - </Args> - </Behavior> - <Behavior Id="recursivedecay"> - <InheritsFrom>behaviors/LoopAndDie.xml</InheritsFrom> - <Args> - <InitialResponseCount>160</InitialResponseCount> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.BehaviorChain</Class> - <Args> - <Id>runcolordecay</Id> - <Inputs> - <Id>pygameclick</Id> - </Inputs> - <ChainedBehaviors> - <Id>colorchange</Id> - <Id>mover</Id> - <!--<Id>square</Id>--> - <Id>decay</Id> - </ChainedBehaviors> - <RecursiveHooks>{'mover':'movebounce'}</RecursiveHooks> - <RenderToScreen>False</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> - <Behavior> - <Class>behaviors.EchoBehavior</Class> - <Args> - <Id>echo</Id> - <z-index>0</z-index> - <RenderToScreen>False</RenderToScreen> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.ColorShift</Class> - <Args> - <Id>colorshift</Id> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.BehaviorChain</Class> - <Args> - <Id>mousechaser</Id> - <Inputs> - </Inputs> - <ChainedBehaviors> - <Id>echo</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>centerleft</Id> - </Inputs> - <ChainedBehaviors> - <Id>colorchange</Id> - <Id>mover</Id> - <Id>decay</Id> - </ChainedBehaviors> - <RecursiveHooks>{'mover':'circle_expand'}</RecursiveHooks> - <RenderToScreen>False</RenderToScreen> - </Args> - </Behavior> - <!-- ****************************** --> - <Behavior> - <Class>behaviors.ModifyParam</Class> - <Args> - <Id>incrVertBarLoc</Id> - <ParamName>xLoc</ParamName> - <ParamOp>{val}+1</ParamOp> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.VerticalBar</Class> - <Args> - <Id>vertBar</Id> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.BehaviorChain</Class> - <Args> - <Id>bar_move</Id> - <ChainedBehaviors> - <Id>vertBar</Id> - <Id>incrVertBarLoc</Id> - <Id>recursivedecay</Id> - </ChainedBehaviors> - </Args> - </Behavior> - <Behavior> - <Class>behaviors.BehaviorChain</Class> - <Args> - <Id>scanningbars</Id> - <Inputs> - <Id>centerleft</Id> - </Inputs> - <ChainedBehaviors> - <Id>colorchange</Id> - <Id>mover</Id> - <Id>slowdecay</Id> - </ChainedBehaviors> - <RecursiveHooks>{'mover':'bar_move'}</RecursiveHooks> - <RenderToScreen>True</RenderToScreen> - </Args> - </Behavior> - <!-- ****************************** --> - <Behavior Id="running"> - <InheritsFrom>behaviors/RunningBehavior.xml</InheritsFrom> - </Behavior> - </BehaviorConfiguration> -</LightInstallation> diff --git a/config/C5Sign-pygame.xml b/config/C5Sign-pygame.xml index d08e14c..2040642 100644 --- a/config/C5Sign-pygame.xml +++ b/config/C5Sign-pygame.xml @@ -14,5 +14,5 @@ </Args> </InputElement> </InputConfiguration> - <InheritsFrom>config/C5Sign-Leah.xml</InheritsFrom> + <InheritsFrom>config/C5Sign.xml</InheritsFrom> </LightInstallation> diff --git a/config/C5Sign.xml b/config/C5Sign.xml index 6d7de20..93b3028 100644 --- a/config/C5Sign.xml +++ b/config/C5Sign.xml @@ -52,6 +52,14 @@ </Args> </InputElement> <InputElement> + <Class>inputs.InitialLocationInput</Class> + <Args> + <Id>centeronce</Id> + <xPos>0.5</xPos> + <yPos>0.5</yPos> + </Args> + </InputElement> + <InputElement> <Class>inputs.OSCInput</Class> <Args> <Id>osc</Id> @@ -130,6 +138,14 @@ <RenderToScreen>False</RenderToScreen> </Args> </Behavior> + <Behavior Id="redcolor"> + <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom> + <Args> + <ColorList> + <Color>(255,0,0)</Color> + </ColorList> + </Args> + </Behavior> <Behavior Id="colorchange"> <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom> </Behavior> @@ -183,6 +199,13 @@ <Behavior> <Class>behaviors.LocationMask</Class> <Args> + <Id>stripsonly</Id> + <Location>ts.all ls.all rs.all bs.all</Location> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.LocationMask</Class> + <Args> <Id>wordsonly</Id> <Location>wt.all cl.all c5.all</Location> </Args> @@ -207,8 +230,8 @@ <Id>centerleft</Id> <Id>center</Id> </Inputs> - <TimeMap>{'scanningbars':10,'runcolordecay':10,'expandingcircles':10}</TimeMap> - <InputMap>{'scanningbars':'centerleft', 'runcolordecay':'center',\ + <TimeMap>{'framedbars':10,'runcolordecay':10,'expandingcircles':10}</TimeMap> + <InputMap>{'framedbars':'centerleft', 'runcolordecay':'center',\ 'expandingcircles':'center'}</InputMap> <RenderToScreen>True</RenderToScreen> </Args> @@ -310,6 +333,42 @@ </Args> </Behavior> <Behavior> + <Class>behaviors.RunFinite</Class> + <Args> + <Id>runonce</Id> + <Iterations>1</Iterations> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.BehaviorChain</Class> + <Args> + <Id>coloredframe</Id> + <!--Inputs> + <Id>centeronce</Id> + </Inputs--> + <ChainedBehaviors> + <Id>runonce</Id> + <Id>redcolor</Id> + <Id>square</Id> + <Id>mover</Id> + <Id>singleframe</Id> + <Id>stripsonly</Id> + </ChainedBehaviors> + <RecursiveHooks>{'mover':'colorshift'}</RecursiveHooks> + <RenderToScreen>False</RenderToScreen> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.SplitBehavior</Class> + <Args> + <Id>framedbars</Id> + <BehaviorList> + <Id>coloredframe</Id> + <Id>scanningbars</Id> + </BehaviorList> + </Args> + </Behavior> + <Behavior> <Class>behaviors.BehaviorChain</Class> <Args> <Id>expandingcircles</Id> diff --git a/inputs/InitialLocationInput.py b/inputs/InitialLocationInput.py new file mode 100644 index 0000000..8d39a40 --- /dev/null +++ b/inputs/InitialLocationInput.py @@ -0,0 +1,24 @@ +import util.TimeOps as clock +import util.ComponentRegistry as compReg +import util.Strings as Strings +from operationscore.Input import * +class InitialLocationInput(Input): + """Takes two arguments: xPos, yPos, where xPos and yPos is a value from + 0 to 1, where 0 represents top/left and 1 represents bottom/right of the + lightscreen. Will return that position on the screen only once.""" + + def inputInit(self): + compReg.getLock().acquire() + xmin, ymin, xmax, ymax = compReg.getComponent('Screen').getSize() + compReg.getLock().release() + + xlen = xmax-xmin + ylen = ymax-ymin + + self.xloc = xmin + xlen * self['xPos'] + self.yloc = ymin + ylen * self['yPos'] + + def sensingLoop(self): + self.respond({Strings.LOCATION: (self.xloc, self.yloc)}) + self.done = True + diff --git a/operationscore/Input.py b/operationscore/Input.py index 7720847..8800556 100644 --- a/operationscore/Input.py +++ b/operationscore/Input.py @@ -14,6 +14,7 @@ class Input(ThreadedSmootCoreObject): if not 'RefreshInterval' in self.argDict: self.argDict['RefreshInterval'] = 500 self.parentScope = self.argDict['parentScope'] + self.done = False self.inputInit() def respond(self, eventDict): @@ -44,6 +45,8 @@ class Input(ThreadedSmootCoreObject): self.acquireLock() self.sensingLoop() self.releaseLock() + if self.done: + break def sensingLoop(self): pass |