From 00e836cfa4e2652d724972585d661143142af002 Mon Sep 17 00:00:00 2001 From: eugue Date: Mon, 24 Jan 2011 14:41:38 -0500 Subject: merge with biginstall --- config/6thFloor.xml | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++ config/MobileTest.xml | 147 +++++++++++++++++++++++++++++++++++ config/Outdoor.xml | 82 ++++++++++++++++++-- 3 files changed, 432 insertions(+), 5 deletions(-) create mode 100644 config/6thFloor.xml create mode 100644 config/MobileTest.xml (limited to 'config') diff --git a/config/6thFloor.xml b/config/6thFloor.xml new file mode 100644 index 0000000..9c5f77e --- /dev/null +++ b/config/6thFloor.xml @@ -0,0 +1,208 @@ + + + + + simplemap + + + + layouts/60StripLayout.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 30 + 0.1 + 10 + 1 + + + + + + renderers/60StripSeq.xml + + + renderers/Pygame.xml + + + + + inputs.PygameInput + + pygame + 10 + + + + + inputs/MouseFollower.xml + + + inputs.RandomLocs + + randomLoc + + + + + + behaviors.EchoBehavior + + echo + 0 + False + + + + behaviors/RedShift.xml + + + behaviors/RandomColor.xml + + + behaviors/PixelDecay.xml + + + behaviors/PixelDecay.xml + + .01 + + + + behaviors.DebugBehavior + + debug + 0 + + pygame + + + + + behaviors.AllPixelsLeft + + pixelsleft + + + + behaviors.Square + + square + 20 + + + + behaviors/LoopAndDie.xml + + 50 + + + + behaviors.BehaviorChain + + runcolordecay + + pygame + + + colorchange + running + decay + + {'running':'acceleratedie'} + True + gaussmap + + + + behaviors.BehaviorChain + + randomwalk + + pygame + + + colorchange + mover + decay + + {'mover':'redwalk'} + True + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors.BehaviorChain + + redwalk + + randmovement + redshift + + + + + behaviors.RandomWalk + + randmovement + 2 + + + + behaviors/Accelerate.xml + + + behaviors.BehaviorChain + + acceleratedie + + accelerate + recursivedecay + + + + + behaviors.BehaviorChain + + mousechaser + + followmouse + tcp + + + echo + redshift + square + slowdecay + + True + + + + behaviors/RunningBehavior.xml + + + diff --git a/config/MobileTest.xml b/config/MobileTest.xml new file mode 100644 index 0000000..2f736ea --- /dev/null +++ b/config/MobileTest.xml @@ -0,0 +1,147 @@ + + + + + simplemap + + + + layouts/BasicSixStrip.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 30 + 0.1 + 10 + 1 + + + + + + renderers/SixStripUDP.xml + + + renderers/Pygame.xml + + + + + inputs.PygameInput + + pygame + 100 + + + + inputs/MouseFollower.xml + + + inputs.RandomLocs + + randomLoc + + + + inputs.TCPInput + + TCP + 20120 + 100 + + + + + + behaviors.EchoBehavior + + echo + 0 + False + + + + behaviors/RandomColor.xml + + + behaviors/PixelDecay.xml + + + behaviors.DebugBehavior + + debug + 0 + + pygame + + + + + behaviors.AllPixelsLeft + + pixelsleft + + + + behaviors/LoopAndDie.xml + + 200 + + + + behaviors.BehaviorChain + + runcolordecay + + pygame + + + colorchange + running + decay + + {'running':'acceleratedie'} + True + gaussmap + + + + behaviors/Accelerate.xml + + + behaviors.BehaviorChain + + acceleratedie + + accelerate + recursivedecay + + + + + behaviors/RunningBehavior.xml + + + behaviors.MoveBehavior + + move + + TCP + + 1 + 1 + True + + + + diff --git a/config/Outdoor.xml b/config/Outdoor.xml index 9ee0c3a..e137ec4 100644 --- a/config/Outdoor.xml +++ b/config/Outdoor.xml @@ -40,9 +40,17 @@ inputs.PygameInput pygame - 100 + 10 + inputs/MouseFollower.xml @@ -62,12 +70,27 @@ False + + behaviors/RedShift.xml + behaviors/RandomColor.xml + + + (0,255,0) + (255,0,0) + + behaviors/PixelDecay.xml + + behaviors/PixelDecay.xml + + .01 + + behaviors.DebugBehavior @@ -84,10 +107,17 @@ pixelsleft + + behaviors.Square + + square + 5 + + behaviors/LoopAndDie.xml - 200 + 30 @@ -96,7 +126,7 @@ runcolordecay pygame - randomLoc + colorchange @@ -108,6 +138,46 @@ gaussmap + + behaviors.BehaviorChain + + randomwalk + + pygame + + + colorchange + mover + decay + + {'mover':'redwalk'} + True + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors.BehaviorChain + + redwalk + + randmovement + redshift + + + + + behaviors.RandomWalk + + randmovement + 2 + + behaviors/Accelerate.xml @@ -127,11 +197,13 @@ mousechaser followmouse + tcp echo - pixelsleft - decay + redshift + square + slowdecay True -- cgit v1.2.3 From ad8ad25072f55413ecfd696eff1e07c1cd08984e Mon Sep 17 00:00:00 2001 From: rcoh Date: Tue, 25 Jan 2011 14:07:05 -0500 Subject: Fancy param modification --- behaviors/ModifyParam.py | 4 ++++ behaviors/XYMove.py | 1 + config/6thFloor.xml | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) (limited to 'config') diff --git a/behaviors/ModifyParam.py b/behaviors/ModifyParam.py index f589e05..6e76d05 100644 --- a/behaviors/ModifyParam.py +++ b/behaviors/ModifyParam.py @@ -1,4 +1,5 @@ from operationscore.Behavior import * +import math import pdb #Class to perform a given operation on some element of an argDict. Designed to be used a recursive hook, but can serve sensor-based functions as well. Specify ParamType (Sensor or Recurse), ParamName, and ParamOp, (a valid python statement with the old value represented as {val}) class ModifyParam(Behavior): @@ -16,6 +17,9 @@ class ModifyParam(Behavior): if paramName in behaviorInput: #TODO: copy -> modify instead of just #copying paramOp = paramOp.replace('{val}', 'behaviorInput[paramName]') #convert the {val} marker to something we can execute + #TODO: move elsewhere + paramOp = paramOp.replace('{y}', "behaviorInput['Location'][1]") + paramOp = paramOp.replace('{x}', "behaviorInput['Location'][0]") behaviorInput[paramName] = eval(paramOp) if paramType == 'Sensor': #return accordingly return (searchSet, recursiveInputs) diff --git a/behaviors/XYMove.py b/behaviors/XYMove.py index 8acbba8..1b99ee1 100644 --- a/behaviors/XYMove.py +++ b/behaviors/XYMove.py @@ -6,6 +6,7 @@ class XYMove(Behavior): for loc in sensor: oploc = dict(loc) self.insertStepIfMissing(oploc) + print oploc['YStep'] oploc['Location'] = Geo.addLocations((oploc['XStep'], oploc['YStep']), oploc['Location']) ret.append(oploc) return (ret, []) diff --git a/config/6thFloor.xml b/config/6thFloor.xml index 3f734d9..9f3904a 100644 --- a/config/6thFloor.xml +++ b/config/6thFloor.xml @@ -121,11 +121,21 @@ movebounce xymove - ybounce + xbounce + ysin + + behaviors.ModifyParam + + ysin + YStep + Sensor + 4*math.sin({x}/float(40)) + + behaviors.BehaviorChain @@ -182,9 +192,9 @@ behaviors.BehaviorChain runcolordecay - + colorchange running -- cgit v1.2.3 From 82f99fc4583ca3cc9861a9fe30990a4a9ef162c4 Mon Sep 17 00:00:00 2001 From: eugue Date: Tue, 25 Jan 2011 15:22:24 -0500 Subject: working version of IconMover --- behaviors/MoveBehavior.py | 10 ++-- config/MobileTest.xml | 119 ++++++++++++++++++++++++++++++++++++------- inputs/TCPInput.py | 25 +++++---- operationscore/PixelEvent.py | 1 + 4 files changed, 118 insertions(+), 37 deletions(-) (limited to 'config') diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index 9ae98b9..590f0e4 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -5,21 +5,19 @@ import util.Strings as Strings class MoveBehavior(Behavior): def processResponse(self, sensorInputs, recursiveInputs): - print 'processing' - print sensorInputs if recursiveInputs: currRecLocs = recursiveInputs else: - currRecLocs = [{'Location' : (5, 5)), 'Color' : [255, 255, 255]}] + currRecLocs = [{'Location' : (5, 5), 'Color' : [255, 255, 255]}] if sensorInputs: # if input exists, change location ret = [] for currRecLoc in currRecLocs: currDict = dict(currRecLoc) for sensorInput in sensorInputs: - currDict['Location'][0] += sensorInput['x'] * self['XStep'] - currDict['Location'][1] += sensorInput['y'] * self['YStep'] - #currDict['Color'] = sensorInput['color'] + currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ + currDict['Location'][1] + sensorInput['y'] * self['YStep']) + currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] ret.append(currDict) #print ret return (ret, ret) diff --git a/config/MobileTest.xml b/config/MobileTest.xml index 2f736ea..a318069 100644 --- a/config/MobileTest.xml +++ b/config/MobileTest.xml @@ -6,7 +6,7 @@ - layouts/BasicSixStrip.xml + layouts/60StripLayout.xml @@ -29,7 +29,7 @@ - renderers/SixStripUDP.xml + renderers/60StripSeq.xml renderers/Pygame.xml @@ -40,7 +40,15 @@ inputs.PygameInput pygame - 100 + 10 + + + + inputs.TCPInput + + tcp + 20120 + 50 @@ -52,14 +60,6 @@ randomLoc - - inputs.TCPInput - - TCP - 20120 - 100 - - @@ -70,12 +70,21 @@ False + + behaviors/RedShift.xml + behaviors/RandomColor.xml behaviors/PixelDecay.xml + + behaviors/PixelDecay.xml + + .01 + + behaviors.DebugBehavior @@ -92,10 +101,17 @@ pixelsleft + + behaviors.Square + + square + 20 + + behaviors/LoopAndDie.xml - 200 + 50 @@ -115,6 +131,46 @@ gaussmap + + behaviors.BehaviorChain + + randomwalk + + pygame + + + colorchange + mover + decay + + {'mover':'redwalk'} + True + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors.BehaviorChain + + redwalk + + randmovement + redshift + + + + + behaviors.RandomWalk + + randmovement + 2 + + behaviors/Accelerate.xml @@ -128,6 +184,22 @@ + + behaviors.BehaviorChain + + mousechaser + + followmouse + + + echo + redshift + square + slowdecay + + True + + behaviors/RunningBehavior.xml @@ -135,12 +207,23 @@ behaviors.MoveBehavior move - - TCP - - 1 - 1 - True + 5 + 5 + + + + behaviors.BehaviorChain + + moveanddecay + + tcp + + + move + decay + + True + gaussmap diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py index e5475c1..513b853 100644 --- a/inputs/TCPInput.py +++ b/inputs/TCPInput.py @@ -21,28 +21,27 @@ class TCPInput(Input): def sensingLoop(self): data = self.conn.recv(self.BUFFER_SIZE) main_log.debug('Incoming data', data) - if not data or 'end' in data or data == '': # data end, close socket + if not data or 'end' in data: # data end, close socket main_log.debug('End in data') print 'end of stream' self.IS_RESPONDING = 0 self.conn.close() self.sock.close() - - if self.IS_RESPONDING == 1: # if 'responding', respond to the received data - dataDict = json.loads(data) - self.respond(dataDict) - #try: - # for datagroup in data.split('\n'): - # if datagroup != None and datagroup != '': - # dataDict = json.loads(datagroup) - # self.respond(dataDict) - # socketDict = {'data':dataDict, 'address':self.address} + if self.IS_RESPONDING == 1: # if 'responding', respond to the received data + #dataDict = json.loads(data) + try: + for datagroup in data.split('\n'): + if datagroup != None and datagroup != '': + dataDict = json.loads(datagroup) + #print dataDict + self.respond(dataDict) + #socketDict = {'data':dataDict, 'address':self.address} #socketDict = {Strings.LOCATION: (dataDict['x'], dataDict['y'])} # like PygameInput #print 'input' #self.respond(socketDict) - #except Exception as exp: - # print str(exp) + except Exception as exp: + print str(exp) else: # if not 'responding', don't respond to data and restart socket # * an incomplete hack for now. will be changed if same-type-multi-Input is implemented. diff --git a/operationscore/PixelEvent.py b/operationscore/PixelEvent.py index 80d3b9e..c41df17 100644 --- a/operationscore/PixelEvent.py +++ b/operationscore/PixelEvent.py @@ -26,5 +26,6 @@ class PixelEvent(SmootCoreObject): color = responseDict['Color'] else: raise Exception('Need Color. Probably') + pdb.set_trace() responseDict['PixelEvent'] = StepEvent.generate(300, color) -- cgit v1.2.3 From 328464219a02c014caf1608a27a898900cad8456 Mon Sep 17 00:00:00 2001 From: eugue Date: Thu, 27 Jan 2011 14:28:20 -0500 Subject: mobile shake behavior added. --- behaviors/MobileShakeBehavior.py | 17 +++++++++++++++++ behaviors/MoveBehavior.py | 16 ++++++++++------ config/MobileTest.xml | 28 +++++++++++++++++++++++++--- 3 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 behaviors/MobileShakeBehavior.py (limited to 'config') diff --git a/behaviors/MobileShakeBehavior.py b/behaviors/MobileShakeBehavior.py new file mode 100644 index 0000000..e25e929 --- /dev/null +++ b/behaviors/MobileShakeBehavior.py @@ -0,0 +1,17 @@ +from operationscore.Behavior import * +import util.Strings as Strings + +class MobileShakeBehavior(Behavior): + def processResponse(self, sensorInputs, recursiveInputs): + #print sensorInputs + ret = [] + for sInput in sensorInputs: + outDict = dict(sInput) + if 'type' in sInput and sInput['type'] == 2: + outDict['Location'] = '{x}>' + str(0) + ',{y}>' + str(0) + outDict['Color'] = [sInput['r'], sInput['g'], sInput['b']] + else: # dumb invisible pixel + outDict['Location'] = (-1, -1) + outDict['Color'] = [0, 0, 0] + ret.append(outDict) + return (ret, recursiveInputs) diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index 590f0e4..be41b52 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -1,7 +1,7 @@ from operationscore.Behavior import * -import util.ComponentRegistry as compReg -import util.Geo as Geo -import util.Strings as Strings +#import util.ComponentRegistry as compReg +#import util.Geo as Geo +#import util.Strings as Strings class MoveBehavior(Behavior): def processResponse(self, sensorInputs, recursiveInputs): @@ -15,9 +15,13 @@ class MoveBehavior(Behavior): for currRecLoc in currRecLocs: currDict = dict(currRecLoc) for sensorInput in sensorInputs: - currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ - currDict['Location'][1] + sensorInput['y'] * self['YStep']) - currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] + if 'type' in sensorInput and sensorInput['type'] == 1: + currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ + currDict['Location'][1] + sensorInput['y'] * self['YStep']) + currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] + #elif sensorInput['type'] == 2: + # currDict['Shake'] = 1 + # currDict['Force'] = sensorInput['force'] ret.append(currDict) #print ret return (ret, ret) diff --git a/config/MobileTest.xml b/config/MobileTest.xml index a318069..af94c25 100644 --- a/config/MobileTest.xml +++ b/config/MobileTest.xml @@ -207,10 +207,17 @@ behaviors.MoveBehavior move - 5 - 5 + 3 + 3 + + behaviors.MobileShakeBehavior + + mobileshake + 3 + + behaviors.BehaviorChain @@ -222,9 +229,24 @@ move decay - True + True gaussmap + + behaviors.BehaviorChain + + shakeanddecay + + tcp + + + mobileshake + slowdecay + + True + simplemap + + -- cgit v1.2.3 From 5fb3ea060025241105dc8e9a174513c112f9a133 Mon Sep 17 00:00:00 2001 From: rcoh Date: Thu, 27 Jan 2011 16:50:59 -0500 Subject: A metric $#%$-ton of changes. Added doc-strings to EVERYTHING. Phew. Fixed a massive bug that increases performance in by up to a factor of 60. A bunch of new behaviors for the class. --- LightInstallation.py | 44 ++++++---------- behaviors/AddPixelEvent.py | 5 ++ behaviors/AllPixels.py | 11 ++-- behaviors/AllPixelsLeft.py | 1 + behaviors/BehaviorChain.py | 23 +++++++-- behaviors/ColorChangerBehavior.py | 18 ++++++- behaviors/DebugBehavior.py | 3 ++ behaviors/DecayBehavior.py | 1 + behaviors/DimColor.xml | 2 +- behaviors/DoorBehavior.py | 4 -- behaviors/EchoBehavior.py | 2 + behaviors/Expand.py | 4 ++ behaviors/MITDoors.py | 20 ++++++++ behaviors/ModifyParam.py | 9 ++++ behaviors/MoveBehavior.py | 3 ++ behaviors/RandomWalk.py | 3 ++ behaviors/RecursiveDecay.py | 5 ++ behaviors/ResponseMover.py | 6 ++- behaviors/RestrictLocation.py | 10 ++++ behaviors/RiseFall.py | 40 +++++++++++++++ behaviors/RiseFall.xml | 7 +++ behaviors/RunningBehavior.py | 5 ++ behaviors/Square.py | 25 +++++---- behaviors/TimedDie.py | 15 ++++++ behaviors/Timeout.py | 16 ++++++ behaviors/XYMove.py | 7 +++ config/6thFloor.xml | 85 ++++++++++++++++--------------- inputs/PygameInput.py | 35 ++++++++----- inputs/RandomLocs.py | 3 ++ inputs/TCPInput.py | 9 ++-- inputs/UDPInput.py | 4 ++ layouts/LineLayout.py | 2 +- layouts/ZigzagLayout.py | 9 ++++ operationscore/Behavior.py | 18 ++++--- operationscore/Input.py | 14 +++-- operationscore/PixelEvent.py | 7 ++- operationscore/PixelMapper.py | 8 ++- operationscore/Renderer.py | 8 +-- operationscore/SmootCoreObject.py | 9 ++-- operationscore/ThreadedSmootCoreObject.py | 2 + pixelcore/Pixel.py | 32 +++++------- pixelcore/PixelEventManager.py | 2 - pixelcore/PixelStrip.py | 29 +++-------- pixelcore/Screen.py | 13 +++-- pixelevents/DecayEvent.py | 4 ++ pixelevents/SingleFrameEvent.py | 3 ++ pixelmappers/GaussianMapper.py | 10 +++- pixelmappers/SimpleMapper.py | 5 +- renderers/IndoorRenderer.py | 6 +-- renderers/PygameRenderer.py | 7 ++- tests/TestComponentRegistry.py | 3 ++ tests/TestConfigLoaders.py | 3 ++ util/ColorOps.py | 5 ++ util/Config.py | 26 ++++++---- util/Geo.py | 9 +++- util/NetworkOps.py | 1 - util/PacketComposition.py | 9 +++- util/Search.py | 6 +-- util/TimeOps.py | 1 + 59 files changed, 459 insertions(+), 217 deletions(-) delete mode 100644 behaviors/DoorBehavior.py create mode 100644 behaviors/MITDoors.py create mode 100644 behaviors/RiseFall.py create mode 100644 behaviors/RiseFall.xml create mode 100644 behaviors/TimedDie.py create mode 100644 behaviors/Timeout.py delete mode 100644 pixelcore/PixelEventManager.py (limited to 'config') diff --git a/LightInstallation.py b/LightInstallation.py index b582bd2..ad1e38d 100644 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -89,8 +89,8 @@ class LightInstallation(object): self.inputs = inputs for inputClass in inputs: inputClass.start() - self.inputBehaviorRegistry[inputClass['Id']] = [] - #empty list is list of bound behaviors + self.inputBehaviorRegistry[inputClass['Id']] = [] #Bound behaviors will be added to this + #list def initializeRenderers(self, rendererConfig): self.renderers = self.initializeComponent(rendererConfig) @@ -98,13 +98,9 @@ class LightInstallation(object): def registerComponents(self, components): for component in components: cid = compReg.registerComponent(component) - main_log.debug(cid + ' registered') - cid = component['Id'] - if cid == None: #TODO: determine if componenent is critical, and if so, die - main_log.error('Components must be registered with Ids. Component not registered') - else: - compReg.registerComponent(component) - main_log.debug(cid + ' registered') + main_log.info(cid + ' registered') + compReg.registerComponent(component) + main_log.info(cid + ' registered') def initializeComponent(self, config): components = [] @@ -114,7 +110,6 @@ class LightInstallation(object): [module,className] = configItem.find('Class').text.split('.') except: main_log.error('Module must have Class element') - main_log.warn('Module without class element. Module not initialized') continue try: exec('from ' + module+'.'+className + ' import *') @@ -125,16 +120,13 @@ class LightInstallation(object): main_log.error(str(inst)) continue args = configGetter.pullArgsFromItem(configItem) - args['parentScope'] = self #TODO: we shouldn't give away scope - #like this, find another way. + args['parentScope'] = self try: new_component = eval(className+'(args)') new_component.addDieListener(self) - components.append(new_component) #TODO: doesn't error - main_log.debug(className + 'initialized with args ' + str(args)) - #right + components.append(new_component) + main_log.info(className + 'initialized with args ' + str(args)) except Exception as inst: - pdb.set_trace() main_log.error('Failure while initializing ' + className + ' with ' + str(args)) main_log.error(str(inst)) @@ -146,10 +138,9 @@ class LightInstallation(object): def mainLoop(self): lastLoopTime = clock.time() refreshInterval = 30 - while not self.dieNow: + while not self.dieNow: #dieNow is set if one of its constituents sends a die request. loopStart = clock.time() - responses = self.evaluateBehaviors() #inputs are all queued when they - #happen, so we only need to run the behaviors + responses = self.evaluateBehaviors() self.timer.start() [self.screen.respond(response) for response in responses if response != []] @@ -160,19 +151,17 @@ class LightInstallation(object): main_log.debug('Loop complete in ' + str(loopElapsed) + 'ms. Sleeping for ' +\ str(sleepTime)) self.timer.stop() - #print self.timer.elapsed() if sleepTime > 0: time.sleep(sleepTime/1000) - #evaluates all the behaviors (including inter-dependencies) and returns a - #list of responses to go to the screen. def evaluateBehaviors(self): + """Evaluates all the behaviors (including inter-dependencies) and returns a list of responses to + go to the screen""" responses = {} responses['Screen'] = [] #responses to the screen for behavior in self.behaviors: responses[behavior['Id']] = behavior.timeStep() - if behavior['RenderToScreen'] == True: #TODO: this uses extra space, - #we can use less in the future if needbe. + if behavior['RenderToScreen'] == True: responses['Screen'] += responses[behavior['Id']] return responses['Screen'] @@ -181,9 +170,9 @@ class LightInstallation(object): for behavior in self.behaviors: self.addBehavior(behavior) - #Does work needed to add a behavior: currently -- maps behavior inputs into - #the input behavior registry. def addBehavior(self, behavior): + """Does work needed to add a behavior: currently -- maps behavior inputs into the input behavior + registry""" for inputId in behavior.argDict['Inputs']: if inputId in self.inputBehaviorRegistry: #it could be a behavior self.inputBehaviorRegistry[inputId].append(behavior['Id']) @@ -191,12 +180,11 @@ class LightInstallation(object): def processResponse(self,inputDict, responseDict): inputId = inputDict['Id'] boundBehaviorIds = self.inputBehaviorRegistry[inputId] - #TODO: fix this, it crashes because inputs get run before beahviors exist try: [compReg.getComponent(b).addInput(responseDict) for b in boundBehaviorIds] except: pass - #print 'Behaviors not initialized yet. WAIT!' + #Behavior run before loading. Not a big deal. def handleDie(self, caller): self.dieNow = True diff --git a/behaviors/AddPixelEvent.py b/behaviors/AddPixelEvent.py index 7f134e1..821f432 100644 --- a/behaviors/AddPixelEvent.py +++ b/behaviors/AddPixelEvent.py @@ -2,6 +2,9 @@ from operationscore.Behavior import * import util.Strings as Strings from logger import main_log class AddPixelEvent(Behavior): + """AddPixelEvent is a behavior to append an arbitrary PixelEvent to a behavior response. The + classname of the PixelEvent should be specified in the Class field of Args. All arguments normally + passed to the PixelEvent should also be specified in Args.""" def behaviorInit(self): [module, className] = self['Class'].split('.') try: @@ -18,6 +21,8 @@ class AddPixelEvent(Behavior): ret = [] for sensory in sensors: outDict = {} + if not 'Location' in sensory: + pdb.set_trace() outDict[Strings.LOCATION] = sensory[Strings.LOCATION] settingsDict = dict(self.argDict) settingsDict['Color'] = sensory['Color'] diff --git a/behaviors/AllPixels.py b/behaviors/AllPixels.py index e155e55..7f66ad6 100644 --- a/behaviors/AllPixels.py +++ b/behaviors/AllPixels.py @@ -1,6 +1,9 @@ from operationscore.Behavior import * class AllPixels(Behavior): - def processResponse(self, sensorInputs, recursiveInputs): - for sensory in sensorInputs:#TODO: consider replicating the dict - sensory['Location'] = 'True' - return (sensorInputs, recursiveInputs) + """Turns on all Pixels in the installation. Must use SimpleMapper, or other Mapper supporting + conditional pixel locations.""" + + def processResponse(self, sensorInputs, recursiveInputs): + for sensory in sensorInputs:#TODO: consider replicating the dict + sensory['Location'] = 'True' + return (sensorInputs, recursiveInputs) diff --git a/behaviors/AllPixelsLeft.py b/behaviors/AllPixelsLeft.py index b48bfc1..b223156 100644 --- a/behaviors/AllPixelsLeft.py +++ b/behaviors/AllPixelsLeft.py @@ -2,6 +2,7 @@ from operationscore.Behavior import * import util.ComponentRegistry as compReg import pdb class AllPixelsLeft(Behavior): + """Behavior which returns all points left of its input. No Args.""" def processResponse(self, sensorInputs, recursiveInputs): for sensory in sensorInputs: xLoc = sensory['Location'][0] diff --git a/behaviors/BehaviorChain.py b/behaviors/BehaviorChain.py index 39f4402..631ad98 100644 --- a/behaviors/BehaviorChain.py +++ b/behaviors/BehaviorChain.py @@ -3,6 +3,24 @@ import util.ComponentRegistry as compReg from logger import main_log import pdb class BehaviorChain(Behavior): + """BehaviorChain is a class which chains together multiple behavior. BehaviorChain is in itself a + behavior, and behaves and can be used accordingly. BehaviorChain also supports recursive hooks to + be set on its constituent behaviors. ChainedBehaviors should be specified in as follows: + + + behavior1Id + behavior2Id + + + Behaviors may also be appended programmatically via the appendBehavior method. + + Recursive hooks should be specified with Python dict syntax as follows: + + {'behavior1Id':'hookid'} + + Behavior Chain manages all recurrences that its constituents propogate. At this point, it does not + support recurrences in its hooks.""" + def behaviorInit(self): self.feedback = {} #dictionary to allow feedback of recursives self.hooks = self['RecursiveHooks'] @@ -27,11 +45,10 @@ class BehaviorChain(Behavior): hookBehavior.immediateProcessInput(recurrence, \ []) if hookRecurrence != []: - main_log.warn('Hook recurrences are not currently supported. Implement it\ -yourself or bug russell') + main_log.warn('Hook recurrences are not currently supported.') self.feedback[behaviorId] = recurrence return (response, []) - + def appendBehavior(behavior): bid = compReg.registerComponent(behavior) #register behavior (will make #a new id if there isn't one) diff --git a/behaviors/ColorChangerBehavior.py b/behaviors/ColorChangerBehavior.py index 2a8d974..e2f8bd3 100644 --- a/behaviors/ColorChangerBehavior.py +++ b/behaviors/ColorChangerBehavior.py @@ -2,12 +2,26 @@ from operationscore.Behavior import * import util.ColorOps as color import pdb class ColorChangerBehavior(Behavior): + """ColorChangerBehavior is a behavior for adding colors to responses. If given no arguments, it + will generate a random color. If it is given a list of colors [as below] it will pick randomly + from them. + + + (255,0,0) + (30,79,200) + + + ColorList also supports specification of a single color.""" + def processResponse(self, sensorInputs, recursiveInputs): ret = [] for sensory in sensorInputs: - newDict = dict(sensory) #don't run into shallow copy issues + newDict = dict(sensory) if self['ColorList'] != None: - newDict['Color'] = color.chooseRandomColor(self['ColorList']) #TODO: this doesn't work. + if isinstance(self['ColorList'], list): + newDict['Color'] = color.chooseRandomColor(self['ColorList']) #Pick randomly + else: + newDict['Color'] = self['ColorList'] #Unless there is only one else: newDict['Color'] = color.randomColor() ret.append(newDict) diff --git a/behaviors/DebugBehavior.py b/behaviors/DebugBehavior.py index 17383db..8f81954 100644 --- a/behaviors/DebugBehavior.py +++ b/behaviors/DebugBehavior.py @@ -2,6 +2,9 @@ from operationscore.Behavior import * from logger import main_log import pdb class DebugBehavior(Behavior): + """DebugBehavior simply writes all of its inputs to the logs, currently at the ERROR level for + easy visibility. Will be changed to DEBUG or INFO in the future""" + def processResponse(self, sensorInputs, recursiveInputs): if sensorInputs != []: main_log.error('Sensor Inputs: ' + str(sensorInputs)) diff --git a/behaviors/DecayBehavior.py b/behaviors/DecayBehavior.py index c1f6f92..f19ffc8 100644 --- a/behaviors/DecayBehavior.py +++ b/behaviors/DecayBehavior.py @@ -3,6 +3,7 @@ from pixelevents.DecayEvent import * import util.Strings as Strings import pdb class DecayBehavior(Behavior): + """DecayBehavior is obsolete. Use AddPixelEvent instead""" def processResponse(self, sensorInputs, recursiveInputs): ret = [] for sensory in sensorInputs: diff --git a/behaviors/DimColor.xml b/behaviors/DimColor.xml index b01908e..58b0673 100644 --- a/behaviors/DimColor.xml +++ b/behaviors/DimColor.xml @@ -3,6 +3,6 @@ Sensor Color - [chan*.99 for chan in {val}] + [chan*.95 for chan in {val}] diff --git a/behaviors/DoorBehavior.py b/behaviors/DoorBehavior.py deleted file mode 100644 index 5058f69..0000000 --- a/behaviors/DoorBehavior.py +++ /dev/null @@ -1,4 +0,0 @@ -from operationscore.behavior import * -class DoorBehavior.py(Behavior): - def behaviorInit(self): - pyt diff --git a/behaviors/EchoBehavior.py b/behaviors/EchoBehavior.py index 589c42b..6ef4fcb 100644 --- a/behaviors/EchoBehavior.py +++ b/behaviors/EchoBehavior.py @@ -2,6 +2,8 @@ from operationscore.Behavior import * import util.Strings as Strings import pdb class EchoBehavior(Behavior): + """EchoBehavior generates a RED response at all locations specified in sensorInputs. Useful for + debugging""" def processResponse(self, sensorInputs, recursiveInputs): ret = [] for sensory in sensorInputs: diff --git a/behaviors/Expand.py b/behaviors/Expand.py index 3415966..323e71f 100644 --- a/behaviors/Expand.py +++ b/behaviors/Expand.py @@ -1,5 +1,9 @@ from operationscore.Behavior import * class Expand(Behavior): + """Expand is a behavior that generates a response that grows horizontally starting a location + specifed in input. Required Args: + 123 which is the expandrate in units/response""" + def processResponse(self, sensorInputs, recurs): ret = [] for data in sensorInputs: diff --git a/behaviors/MITDoors.py b/behaviors/MITDoors.py new file mode 100644 index 0000000..d602a55 --- /dev/null +++ b/behaviors/MITDoors.py @@ -0,0 +1,20 @@ +from operationscore.Behavior import * +class MITDoors(Behavior): + """MITDoors is a case-specific behavior to map keypresses to specific locations. Written for + Kuan 1/26/11 by RCOH""" + + def behaviorInit(self): + self.keymapping = {'q':[2,19], 'w':[22,36], 'e':[37,49], 'r':[52,69], 't':[76,91], 'y':[94,105], + 'u':[106,117], 'i':[123,154], 'o':[158,161], 'p':[164,167], '[':[172,184]} + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + for data in sensorInputs: + key = chr(data['Key']) + if key in self.keymapping: + bounds = self.keymapping[key] + data = dict(data) + data['Left'], data['Right'] = bounds + data['Bottom'] = self['Bottom'] + data['Location'] = (sum(bounds) / 2., self['Bottom']) + ret.append(data) + return (ret, []) diff --git a/behaviors/ModifyParam.py b/behaviors/ModifyParam.py index f589e05..4f45be0 100644 --- a/behaviors/ModifyParam.py +++ b/behaviors/ModifyParam.py @@ -2,8 +2,17 @@ from operationscore.Behavior import * import pdb #Class to perform a given operation on some element of an argDict. Designed to be used a recursive hook, but can serve sensor-based functions as well. Specify ParamType (Sensor or Recurse), ParamName, and ParamOp, (a valid python statement with the old value represented as {val}) class ModifyParam(Behavior): + """ModifyParam is a powerful class to perform an action on a specified key in the Argument + Dictionary of a response. Specify: + -- Sensor or Recurse + -- The name of the parameter you wish to modify + -- The modification you wish to do. Use {val} to specify the current value of the + parameter in question. Special hooks for {x} and {y} exist in some versions""" + def processResponse(self, sensorInputs, recursiveInputs): paramType = self['ParamType'] + if paramType == None: + paramType = 'Sensor' paramName = self['ParamName'] paramOp = str(self['ParamOp']) if paramType == 'Sensor': diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index 590f0e4..d2f60a0 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -4,6 +4,9 @@ import util.Geo as Geo import util.Strings as Strings class MoveBehavior(Behavior): + """Moves current location by the x and y components of sensorInput. Uses recurrences to track + current input. @Author: Euguene""" + def processResponse(self, sensorInputs, recursiveInputs): if recursiveInputs: currRecLocs = recursiveInputs diff --git a/behaviors/RandomWalk.py b/behaviors/RandomWalk.py index fd6c2c8..c9049af 100644 --- a/behaviors/RandomWalk.py +++ b/behaviors/RandomWalk.py @@ -5,6 +5,9 @@ import util.Strings as Strings import random import pdb class RandomWalk(Behavior): + """Behavior to move the curent location by a random distance specified by + -- StepSize in units/response""" + def processResponse(self, sensors, recursives): ret = [] s = self['StepSize'] diff --git a/behaviors/RecursiveDecay.py b/behaviors/RecursiveDecay.py index 218813d..0ae21ea 100644 --- a/behaviors/RecursiveDecay.py +++ b/behaviors/RecursiveDecay.py @@ -1,6 +1,11 @@ from operationscore.Behavior import * import pdb class RecursiveDecay(Behavior): + """RecursiveDecay is an event to allow recursive hooks to stop recursing after a certain number + of iterations specified in + -- Int, number of total responses. + Designed to be used as part of a recursive hook. + """ def processResponse(self, sensorInputs, recursiveInputs): ret = [] for response in sensorInputs: diff --git a/behaviors/ResponseMover.py b/behaviors/ResponseMover.py index e1faccb..59e353a 100644 --- a/behaviors/ResponseMover.py +++ b/behaviors/ResponseMover.py @@ -1,9 +1,11 @@ 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): + """ResponseMover is a scaffold for behaviors that spawn 'walkers' which act autonomously on input. + To control the movment, use the behavior as part of a BehaviorChain and add a recursive hook which + modulates the location.""" + def processResponse(self, sensorInputs, recursiveInputs): newResponses = sensorInputs ret = [] diff --git a/behaviors/RestrictLocation.py b/behaviors/RestrictLocation.py index f6c26ff..5e12440 100644 --- a/behaviors/RestrictLocation.py +++ b/behaviors/RestrictLocation.py @@ -6,6 +6,16 @@ import util.Strings as Strings import random import pdb class RestrictLocation(Behavior): + """RestrictLocation is a Behavior which does an action -- A ModifyParam, actually, when a certain + location based condition is met. It takes arguments as follows: + + -- Operation to perform, using ModifyParam syntax. Use {val} to reference the variable + specified by ParamName. + -- the name of the parameter to modify. + -- either a tuple of (xmin,ymin,xmax,ymax) or a python-correct conditional. Use {x} and + {y} to reference x and y. Use < and > to get < and > in XML. EG: + {x}<0 or {x}>800""" + def behaviorInit(self): action = self['Action'] modifyParamArgs = {'ParamType': 'Sensor', diff --git a/behaviors/RiseFall.py b/behaviors/RiseFall.py new file mode 100644 index 0000000..109cd10 --- /dev/null +++ b/behaviors/RiseFall.py @@ -0,0 +1,40 @@ +from operationscore.Behavior import * +import math +import util.TimeOps as timeOps +#Required Args: +#Period (ms), MaxHeight, Width +class RiseFall(Behavior): + """RiseFall is a behavior that creates a rising and falling column of light. Specify: + -- the maximum height that it rises to. + -- the width of the column OR and + -- the period of oscillation in ms + + Designed to be used as part of a recursive hook. + """ + + def processResponse(self, sensorInputs, recurInputs): + ret = [] + for data in sensorInputs: + #first time with behavior: + data = dict(data) + if not 'StartTime' in data: + data['StartTime'] = timeOps.time() + data['Period'] = self['Period'] + data['MaxHeight'] = self['MaxHeight'] #Consider just using += + if not 'Bottom' in data: + data['Bottom'] = data['Location'][1] + if 'Width' in self: #TODO: improve + data['Width'] = self['Width'] + data['Left'] = data['Location'][0]-data['Width']/2. + data['Right'] = data['Location'][0]+data['Width']/2. + currentTime = timeOps.time() + deltaTime = currentTime-data['StartTime'] + data['Height'] = data['MaxHeight']*math.sin(deltaTime/data['Period']*(math.pi*2)) + data['Location'] = "{x}>"+str(data['Left']) + ", " +\ + "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ + {y}>"+str(data['Bottom']-data['Height']) + + ret.append(data) + return (ret, []) + + diff --git a/behaviors/RiseFall.xml b/behaviors/RiseFall.xml new file mode 100644 index 0000000..eaadd7b --- /dev/null +++ b/behaviors/RiseFall.xml @@ -0,0 +1,7 @@ + + behaviors.RiseFall + + 2000 + 50 + + diff --git a/behaviors/RunningBehavior.py b/behaviors/RunningBehavior.py index 5eb33f7..ab3dc80 100644 --- a/behaviors/RunningBehavior.py +++ b/behaviors/RunningBehavior.py @@ -3,6 +3,11 @@ import util.ComponentRegistry as compReg import util.Geo as Geo import pdb class RunningBehavior(Behavior): + """RunningBehavior is a straightforward behavior that makes a Location run back and forth across + a screen. Specify: + -- the length of movment in units when the response moves. + """ + def processResponse(self, sensorInputs, recursiveInputs): newResponses = sensorInputs ret = [] diff --git a/behaviors/Square.py b/behaviors/Square.py index aef3622..9d3223a 100644 --- a/behaviors/Square.py +++ b/behaviors/Square.py @@ -1,12 +1,17 @@ from operationscore.Behavior import * class Square(Behavior): - def processResponse(self, sensorInputs, recursiveInputs): - for sensory in sensorInputs:#TODO: consider replicating the dict - xLoc = sensory['Location'][0] - yLoc = sensory['Location'][1] - width = self['Width'] - #sensory['Location'] = 'True' - sensory['Location'] =\ - '{x}<'+str(xLoc+width)+',{x}>'+str(xLoc-width)+\ - ',{y}<'+str(yLoc+width)+',{y}>'+str(yLoc-width) - return (sensorInputs, recursiveInputs) + """Square is a simple behavior that makes a square with side lengths Width*2 around locations in + the sensor input. Specify: + -- the sidelength/2 + """ + + def processResponse(self, sensorInputs, recursiveInputs): + for sensory in sensorInputs:#TODO: consider replicating the dict + xLoc = sensory['Location'][0] + yLoc = sensory['Location'][1] + width = self['Width'] + #sensory['Location'] = 'True' + sensory['Location'] =\ + '{x}<'+str(xLoc+width)+',{x}>'+str(xLoc-width)+\ + ',{y}<'+str(yLoc+width)+',{y}>'+str(yLoc-width) + return (sensorInputs, recursiveInputs) diff --git a/behaviors/TimedDie.py b/behaviors/TimedDie.py new file mode 100644 index 0000000..e75e9dd --- /dev/null +++ b/behaviors/TimedDie.py @@ -0,0 +1,15 @@ +from operationscore.Behavior import * +class Timeout(Behavior): + """Timeout is a behavior designed to be used in recursive hooks to stop responses after a certain + amount of time. It is the Time-version of RecursiveDecay. Specify: + -- the time in ms that the response will run. + """ + + def processResponse(self, sensorInputs, recur): + ret = [] + for data in sensorInputs: + if not 'StartTime' in data: + data['StartTime'] = timeops.time() + if timeops.time()-data['StartTime'] < self['Timeout']: + ret.append(data) + return (ret, []) diff --git a/behaviors/Timeout.py b/behaviors/Timeout.py new file mode 100644 index 0000000..14d4873 --- /dev/null +++ b/behaviors/Timeout.py @@ -0,0 +1,16 @@ +from operationscore.Behavior import * +import util.TimeOps as timeops +class Timeout(Behavior): + """Timeout is a behavior designed to be used in recursive hooks to stop responses after a certain + amount of time. It is the Time-version of RecursiveDecay. Specify: + -- the time in ms that the response will run. + """ + + def processResponse(self,sensorInputs, recur): + ret = [] + for data in sensorInputs: + if not 'StartTime' in data: + data['StartTime'] = timeops.time() + if timeops.time()-data['StartTime'] < self['Timeout']: + ret.append(data) + return (ret,[]) diff --git a/behaviors/XYMove.py b/behaviors/XYMove.py index 8acbba8..11cee96 100644 --- a/behaviors/XYMove.py +++ b/behaviors/XYMove.py @@ -1,6 +1,13 @@ from operationscore.Behavior import * import util.Geo as Geo class XYMove(Behavior): + """XYMove is a behavior designed to be used as a recursive hook to ResponseMover to move pixels by + XStep and YStep. As XStep and YStep are maintained in the responses itself, they can be + modulated to facilitate, acceleration, modulation, bouncing, etc. Specify: + -- the starting XStep + -- the starting YStep + """ + def processResponse(self, sensor, recurs): ret = [] for loc in sensor: diff --git a/config/6thFloor.xml b/config/6thFloor.xml index c98486a..b58ff57 100644 --- a/config/6thFloor.xml +++ b/config/6thFloor.xml @@ -39,8 +39,17 @@ inputs.PygameInput - pygame + pygameclick 10 + True + + + + inputs.PygameInput + + pygamekey + 10 + True @@ -62,14 +71,11 @@ inputs/MouseFollower.xml - - inputs.RandomLocs - - randomLoc - - + + behaviors/RiseFall.xml + behaviors.EchoBehavior @@ -88,9 +94,6 @@ 1 - - behaviors/RedShift.xml - behaviors/RandomColor.xml @@ -159,21 +162,32 @@ + + behaviors.BehaviorChain + + risefalldie + + risefall + 2sec + dim + + + behaviors.BehaviorChain inpexpanddim - pygame + pygamekey + mitdoors colorchange mover decay - {'mover':'movebounce'} + {'mover':'risefalldie'} True - gaussmap @@ -182,11 +196,25 @@ debug 0 - pygame + pygamekey udp + + behaviors.Timeout + + 2sec + 2000 + + + + behaviors.MITDoors + + mitdoors + 50 + + behaviors.AllPixelsLeft @@ -211,7 +239,7 @@ runcolordecay - pygame + pygameclick colorchange @@ -223,39 +251,12 @@ gaussmap - - behaviors.BehaviorChain - - randomwalk - - pygame - - - colorchange - mover - decay - - {'mover':'redwalk'} - False - gaussmap - - behaviors.ResponseMover mover - - behaviors.BehaviorChain - - redwalk - - randmovement - redshift - - - behaviors.RandomWalk diff --git a/inputs/PygameInput.py b/inputs/PygameInput.py index 27b82b0..399a77e 100644 --- a/inputs/PygameInput.py +++ b/inputs/PygameInput.py @@ -6,18 +6,27 @@ from pygame.locals import * #This class processes input from an already running pygame instance and passes #it to the parent. This class requires an already running pygame instance. class PygameInput(Input): + """PygameInput is an input tied to the PygameDisplay. Specify: + True to receive an input every frame specifying the current mouse + position. + True to grab keystrokes + True to grab clicks. + + NB: If follow mouse is enabled, PygameInput will not return mouse and keypresses. You can, however, + instantiate other PygameInputs in the XML that will capture mouse and keypresses.""" def sensingLoop(self): - #try: - if self['FollowMouse']: - self.respond({Strings.LOCATION: pygame.mouse.get_pos()}) - return - for event in pygame.event.get(): - if event.type is KEYDOWN: - if event.key == 27: - self.die() - self.respond({Strings.LOCATION: (5,5),'Key': event.key}) - if event.type is MOUSEBUTTONDOWN: + if self['FollowMouse']: + self.respond({Strings.LOCATION: pygame.mouse.get_pos()}) + return + for event in pygame.event.get(): + if event.type is KEYDOWN: + if event.key == 27: + self.die() + if self['Keyboard']: + self.respond({'Key': event.key}) + return + else: + pygame.event.post(event) + if event.type is MOUSEBUTTONDOWN: + if self['Clicks']: self.respond({Strings.LOCATION: pygame.mouse.get_pos()}) - #except: - #raise Exception('Pygame not initialized. Pygame must be \ - #initialized.') diff --git a/inputs/RandomLocs.py b/inputs/RandomLocs.py index d1ce1c7..2719981 100644 --- a/inputs/RandomLocs.py +++ b/inputs/RandomLocs.py @@ -4,6 +4,9 @@ import util.Geo as Geo import util.Strings as Strings from operationscore.Input import * class RandomLocs(Input): + """RandomLocs is an Input that generates RandomLocations at a preset time interval. Just a + prototype, some assembly required.""" + def inputInit(self): self['LastEvent'] = clock.time() def sensingLoop(self): #TODO: move to params diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py index 2bc69ef..17ea7e6 100644 --- a/inputs/TCPInput.py +++ b/inputs/TCPInput.py @@ -6,6 +6,10 @@ import logging as main_log import string class TCPInput(Input): + """TCPInput is a input to receive input on a TCP port. In its current incarnation, it parses + json data into python dicts. Warning: contains a bug where init will hang until it receives a + connection. Specify: + -- Port number to listen on.""" def inputInit(self): self.HOST = '' # Symbolic name meaning all available interfaces self.PORT = self.argDict['Port'] # Arbitrary non-privileged port @@ -34,12 +38,7 @@ class TCPInput(Input): for datagroup in data.split('\n'): if datagroup != None and datagroup != '': dataDict = json.loads(datagroup) - #print dataDict self.respond(dataDict) - #socketDict = {'data':dataDict, 'address':self.address} - #socketDict = {Strings.LOCATION: (dataDict['x'], dataDict['y'])} # like PygameInput - #print 'input' - #self.respond(socketDict) except Exception as exp: print str(exp) else: diff --git a/inputs/UDPInput.py b/inputs/UDPInput.py index e95bd33..83e2f77 100644 --- a/inputs/UDPInput.py +++ b/inputs/UDPInput.py @@ -1,6 +1,10 @@ from operationscore.Input import * import socket class UDPInput(Input): + """UDPInput is a barebones UDP Input class. It takes any data it receives and adds it to the + 'data' element of the response dict. It also notes the 'address'. Specify: + -- the Port to listen on.""" + def inputInit(self): HOST = '' # Symbolic name meaning all available interfaces PORT = self.argDict['Port'] # Arbitrary non-privileged port diff --git a/layouts/LineLayout.py b/layouts/LineLayout.py index 34f5e36..1d40105 100644 --- a/layouts/LineLayout.py +++ b/layouts/LineLayout.py @@ -1,5 +1,5 @@ from operationscore.PixelAssembler import * -#Simple layout class that simply makes a line of LEDs class LineLayout(PixelAssembler): + """LineLayout is a layout class that makes a line of LEDs""" def layoutFunc(self, lastLocation): return (lastLocation[0]+self.argDict['spacing'], lastLocation[1]) diff --git a/layouts/ZigzagLayout.py b/layouts/ZigzagLayout.py index 221571c..3fc2ea1 100644 --- a/layouts/ZigzagLayout.py +++ b/layouts/ZigzagLayout.py @@ -10,6 +10,15 @@ import pdb # | # X-X-X-X etc. class ZigzagLayout(PixelAssembler): + """ZigZagLayout is a slightly more complex layout class that makes a zig-Zag Led Pattern + Inheriting classes must specify zigLength, the length in lights of a of a zig + and zig Axis, the direction of the long X axis (X or Y). + EG: zig length = 4, zig Axis = X would give: + X-X-X-X + | + X-X-X-X + | + X-X-X-X etc. def initLayout(self): if not 'zigLength' in self.argDict: raise Exception('zigLength must be defined in argDict') diff --git a/operationscore/Behavior.py b/operationscore/Behavior.py index b3f7342..6424842 100644 --- a/operationscore/Behavior.py +++ b/operationscore/Behavior.py @@ -1,11 +1,3 @@ -#Abstract class for a behavior. On every time step, the behavior is passed the -#inputs from all sensors it is bound to as well as any recursive inputs that it -#spawned during the last time step. Inheriting classes MUST define -#processResponse. processResponse should return a list of dictionaries which -#define the properties of the light response, (outputs, recursions). They must give a location and -#color. They may define a PixelEvent to more closely control the outgoing -#data, however, this is normally handled by routing the event to a behavior -#specifically designed to do this (like DecayBehavior). import pdb from operationscore.SmootCoreObject import * @@ -13,6 +5,16 @@ from logger import main_log #timeStep is called on every iteration of the LightInstallation #addInput is called on each individual input received, and the inputs queue class Behavior(SmootCoreObject): + """Abstract class for a behavior. On every time step, the behavior is passed the + inputs from all sensors it is bound to as well as any recursive inputs that it + spawned during the last time step. Inheriting classes MUST define + processResponse. processResponse should return a list of dictionaries which + define the properties of the light response, (outputs, recursions). They must give a location and + color. They may define a PixelEvent to more closely control the outgoing + data, however, this is normally handled by routing the event to a behavior + specifically designed to do this (like AddPixelEvent). + timeStep is called on every iteration of the LightInstallation + addInput is called on each individual input received, and the inputs queue""" def init(self): self.validateArgs('Behavior.params') if type(self['Inputs']) != type([]): diff --git a/operationscore/Input.py b/operationscore/Input.py index 69375d3..d3d5644 100644 --- a/operationscore/Input.py +++ b/operationscore/Input.py @@ -1,16 +1,14 @@ import threading,time from logger import main_log, exception_log from operationscore.ThreadedSmootCoreObject import ThreadedSmootCoreObject -#Abstract class for inputs. Inheriting classes should call "respond" to raise -#their event. Inheriting classes MUST define sensingLoop. Called at the -#interval specified in RefreshInterval while the input is active. For example, if you are writing -#webserver, this is where the loop should go. -#Inheriting classes MAY define inputInit. This is called before the loop -#begins. import pdb class Input(ThreadedSmootCoreObject): - #Event scope is a function pointer the function that will get called when - #an Parent is raised. + """Abstract class for inputs. Inheriting classes should call "respond" to raise + their event. Inheriting classes MUST define sensingLoop. Called at the + interval specified in RefreshInterval while the input is active. For example, if you are writing + webserver, this is where the loop should go. + Inheriting classes MAY define inputInit. This is called before the loop + begins.""" def init(self): self.eventQueue = [] if not 'RefreshInterval' in self.argDict: diff --git a/operationscore/PixelEvent.py b/operationscore/PixelEvent.py index c41df17..5ed6163 100644 --- a/operationscore/PixelEvent.py +++ b/operationscore/PixelEvent.py @@ -1,6 +1,6 @@ -#Class defining a light response. Inheriting classes should define lightState, -#which should return a color, or None if the response is complete. Consider -#requiring a generate event. +"""PixelEvent is a class defining a light response. Inheriting classes should define state, +which should return a color, or None if the response is complete. Consider +requiring a generate event.""" from operationscore.SmootCoreObject import * from pixelevents.StepEvent import * import util.ColorOps as color @@ -26,6 +26,5 @@ class PixelEvent(SmootCoreObject): color = responseDict['Color'] else: raise Exception('Need Color. Probably') - pdb.set_trace() responseDict['PixelEvent'] = StepEvent.generate(300, color) diff --git a/operationscore/PixelMapper.py b/operationscore/PixelMapper.py index 7e2b0af..3937973 100644 --- a/operationscore/PixelMapper.py +++ b/operationscore/PixelMapper.py @@ -2,6 +2,9 @@ from operationscore.SmootCoreObject import * from logger import main_log import pdb class PixelMapper(SmootCoreObject): + """PixelMapper is the parent class for PixelMappers. Inheriting classes should define + mappingFunction which takes an eventLocation and a screen and returns a list of (weight, pixels). PixelMapper + handles caching automatically.""" def init(self): self.mem = {} #Dictionary of all seen events self.totalCalls = 0 @@ -19,6 +22,7 @@ class PixelMapper(SmootCoreObject): return self.mem[eventLocation] #Takes a Screen and returns a list of tuples #(pixel, weight), with the sum of weights = 1 - #TODO: consider abstracting away from pixels def mappingFunction(self,eventLocation, screen): - pass + """Takes a Screen and event location and returns a list of tuples (pixel,weight) with + sum(weights)=1""" + raise Exception('Mapping function not defined!') diff --git a/operationscore/Renderer.py b/operationscore/Renderer.py index b422304..0861c44 100644 --- a/operationscore/Renderer.py +++ b/operationscore/Renderer.py @@ -1,10 +1,10 @@ -#Renderer abstract class. Doesn't do much now, but might do more later. -#Inheriting classes MUST define render which takes a light system and renders it. -#Inheriting classes may define initRenderer which is called after the dictionary -#is pulled from config. #TODO: multithreaded-rendering from operationscore.SmootCoreObject import * class Renderer(SmootCoreObject): + """Renderer abstract class. Doesn't do much now, but might do more later. + Inheriting classes MUST define render which takes a light system and renders it. + Inheriting classes may define initRenderer which is called after the dictionary + is pulled from config.""" def init(self): self.initRenderer() def render(lightSystem): diff --git a/operationscore/SmootCoreObject.py b/operationscore/SmootCoreObject.py index 8b36f4d..0d32773 100644 --- a/operationscore/SmootCoreObject.py +++ b/operationscore/SmootCoreObject.py @@ -4,6 +4,10 @@ import thread import util.Config as configGetter class SmootCoreObject(object): + """SmootCoreObject is essentially a super-object class which grants us some niceties. It allows + us to use objects as if they are dictionaries -- we use this to store their arguments + convienently -- note that querying for a parameter that does not exist will return None. It + also offers some basic ThreadSafety.""" def __init__(self, argDict, skipValidation = False): self.dieListeners = [] self.argDict = argDict @@ -13,8 +17,6 @@ class SmootCoreObject(object): for key in argDict: setattr(self, key, argDict[key]) self.init() #call init of inheriting class - # self.__setitem__ = self.argDict.__setitem__ - # self.__getitem__ = self.argDict.__getitem__ def init(self): pass @@ -37,7 +39,8 @@ class SmootCoreObject(object): return self.argDict[item] else: return None - + def __contains__(self, item): + return item in self.argDict def __getiter__(self): return self.argDict.__getiter__() diff --git a/operationscore/ThreadedSmootCoreObject.py b/operationscore/ThreadedSmootCoreObject.py index 967ee35..4b5d513 100644 --- a/operationscore/ThreadedSmootCoreObject.py +++ b/operationscore/ThreadedSmootCoreObject.py @@ -4,6 +4,8 @@ import thread import util.Config as configGetter from operationscore.SmootCoreObject import SmootCoreObject class ThreadedSmootCoreObject(SmootCoreObject, threading.Thread): + """ThreadedSmootCoreObject is a version of SmootCoreObject for objects that want to run on their + own thread""" def __init__(self, argDict, skipValidation = False): SmootCoreObject.__init__(self, argDict, skipValidation) threading.Thread.__init__(self) diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py index 2f21fd8..6ff2e67 100644 --- a/pixelcore/Pixel.py +++ b/pixelcore/Pixel.py @@ -2,12 +2,13 @@ import util.ColorOps as color import pdb from pixelevents.StepEvent import * import util.TimeOps as timeops -#Pixel keeps a queue of events (PixelEvent objects) (actually a dictionary -#keyed by event time). Every time is state is -#requested, it processes all the members of its queue. If a member returns none, -#it is removed from the queue. Otherwise, its value added to the Pixels color -#weighted by z-index. class Pixel: + """Pixel keeps a queue of events (PixelEvent objects) (actually a dictionary + keyed by event time). Every time is state is + requested, it processes all the members of its queue. If a member returns none, + it is removed from the queue. Otherwise, its value added to the Pixels color + weighted by z-index.""" + radius = 2 timeOff = -1 @@ -24,26 +25,22 @@ class Pixel: #processInput instead. Also, you shouldn't use this anyway. You should be #using the input method on the screen! def turnOnFor(self, time): - event = StepEvent.generate(time, (255,255,255)) #TODO: Move color to + event = StepEvent.generate(time, (255,255,255)) self.processInput(event, 0) - #arg #Add a pixelEvent to the list of active events def processInput(self,pixelEvent,zindex, scale=1,currentTime=None): #consider migrating arg to dict - #TODO: fix for multiple pixel events if currentTime == None: currentTime = timeops.time() - #if not currentTime in self.events: - # self.events[currentTime] = [] - #self.events[currentTime].append((zindex,scale, pixelEvent)) - self.events.append((currentTime, zindex, scale, pixelEvent)) #TODO: this is kindof - #gross + self.events.append((currentTime, zindex, scale, pixelEvent)) #TODO: clean this up, maybe? def clearAllEvents(self): self.events = [] - #Combines all PixelEvents currently active and computes the current color of - #the pixel. - def state(self, currentTime=timeops.time()): #TODO: this only evaluates at import time, I think + def state(self, currentTime=None): + """Combines all PixelEvents currently active and computes the current color of + the pixel.""" + if currentTime == None: + currentTime = timeops.time() if currentTime-self.lastRenderTime < 5: return self.lastRender if self.events == []: @@ -54,8 +51,7 @@ class Pixel: colors = [] for eventObj in self.events: #TODO: right color weighting code if len(self.events) > 50: - pdb.set_trace() - #TODO: this sucks. fix it + main_log.error('High pixel event count! Investigate!') eventTime, zindex, scale, pixelEvent = eventObj eventResult = pixelEvent.state(currentTime-eventTime) if eventResult != None: diff --git a/pixelcore/PixelEventManager.py b/pixelcore/PixelEventManager.py deleted file mode 100644 index 779a0ce..0000000 --- a/pixelcore/PixelEventManager.py +++ /dev/null @@ -1,2 +0,0 @@ -class PixelEventManager(object): - def init(self) diff --git a/pixelcore/PixelStrip.py b/pixelcore/PixelStrip.py index 662b8fe..595ce72 100644 --- a/pixelcore/PixelStrip.py +++ b/pixelcore/PixelStrip.py @@ -4,36 +4,21 @@ import util.Geo as Geo from pixelevents.StepEvent import * import math import pdb -#Python class representing a single Pixel strip (usually 50 Pixels) class PixelStrip: + """Python class representing a single Pixel strip (usually 50 Pixels)""" + def __init__(self, layoutEngine): self.initStrip(layoutEngine) self.argDict = layoutEngine.getStripArgs() + def initStrip(self, layoutEngine): pixelLocations = layoutEngine.getPixelLocations() self.pixels = [Pixel(l) for l in pixelLocations] + def __iter__(self): return self.pixels.__iter__() - def render(self, surface): - [l.render(surface) for l in self.pixels] - #step - def allOn(self, time): - [l.turnOnFor(time) for l in self.pixels] #TODO: add test-on method to - #pixels - def respond(self, responseInfo): - location = responseInfo[Strings.LOCATION] - if not 'PixelEvent' in responseInfo: - if 'Color' in responseInfo: - color = responseInfo['Color'] - else: - raise Exception('Need Color. Probably') - responseInfo['PixelEvent'] = StepEvent.generate(300, color) - (dist, pixel) = self.getPixelNearest(location) - pixel.processInput(responseInfo['PixelEvent'], 0) #TODO: z-index + + + - def getPixelNearest(self, location): - dists = [(Geo.dist(location, pixel.location), pixel) for pixel in self.pixels] - dists.sort() - return dists[0] - #just for now. diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py index b595847..9a81df7 100644 --- a/pixelcore/Screen.py +++ b/pixelcore/Screen.py @@ -10,9 +10,10 @@ 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. class Screen: + """Class representing a collection of Pixels grouped into PixelStrips. Needs a + PixelMapper, currently set via setMapper by may be migrated into the argDict.""" + def __init__(self): self.responseQueue = [] self.pixelStrips = [] @@ -20,14 +21,15 @@ class Screen: self.xPixelLocs = [] sizeValid = False self.pixelsSorted = False + def addStrip(self, lS): self.pixelStrips.append(lS) self.sizeValid = False #keep track of whether or not our screen size has self.pixelsSorted = False #been invalidated by adding more pixels - #Returns (pixelIndex, pixel). Does a binary search. def pixelsInRange(self, minX, maxX): + """Returns (pixelIndex, pixel). Does a binary search.""" if not self.pixelsSorted: self.computeXSortedPixels() minIndex = Search.find_ge(self.xPixelLocs, minX) @@ -41,10 +43,7 @@ class Screen: self.xSortedPixels.sort() self.xPixelLocs = [p[0] for p in self.xSortedPixels] self.pixelsSorted = True - #For debug only - def allOn(self): - [lS.allOn(-1) for lS in self.pixelStrips] - + def __iter__(self): #the iterator of all our pixel strips chained togther return itertools.chain(*[strip.__iter__() for strip in \ self.pixelStrips]) #the * operator breaks the list into args diff --git a/pixelevents/DecayEvent.py b/pixelevents/DecayEvent.py index f8d5ef0..8ff423c 100644 --- a/pixelevents/DecayEvent.py +++ b/pixelevents/DecayEvent.py @@ -3,6 +3,10 @@ import math from util.ColorOps import * import util.Geo as Geo class DecayEvent(PixelEvent): + """DecayEvent is a pixel event that can decay either Exponentially or Proportionally. Specify: + -- Exponential or Proportional + -- Controls the speed of decay.""" + def initEvent(self): self.coefficient = float(abs(self.Coefficient)) if self.DecayType == 'Exponential': diff --git a/pixelevents/SingleFrameEvent.py b/pixelevents/SingleFrameEvent.py index 767f403..252e31b 100644 --- a/pixelevents/SingleFrameEvent.py +++ b/pixelevents/SingleFrameEvent.py @@ -1,5 +1,8 @@ from operationscore.PixelEvent import * class SingleFrameEvent(PixelEvent): + """SingleFrameEvent is a PixelEvent that will only render for the first frame on which it is + queried""" + def initEvent(self): self.timeState = -1 def state(self, timeDelay): diff --git a/pixelmappers/GaussianMapper.py b/pixelmappers/GaussianMapper.py index c82f243..883a95d 100644 --- a/pixelmappers/GaussianMapper.py +++ b/pixelmappers/GaussianMapper.py @@ -1,8 +1,16 @@ from operationscore.PixelMapper import * import util.Geo as Geo class GaussianMapper(PixelMapper): + """GaussianMapper is a PixelMapper which weights pixels around an event proportional to a + gaussian surface. Specify: + -- The height of the gaussian surface + -- The width of the gaussian surface + -- the minimum weight event that can be returned + -- the maximum radius considered + """ + def mappingFunction(self, eventLocation, screen): - returnPixels = [] #TODO: consider preallocation and trimming + returnPixels = [] [x,y] = eventLocation potentialPixels = screen.pixelsInRange(x-self.CutoffDist, \ x+self.CutoffDist) diff --git a/pixelmappers/SimpleMapper.py b/pixelmappers/SimpleMapper.py index 19d44c4..1568de3 100644 --- a/pixelmappers/SimpleMapper.py +++ b/pixelmappers/SimpleMapper.py @@ -2,6 +2,10 @@ from operationscore.PixelMapper import * import util.Geo as Geo import sys class SimpleMapper(PixelMapper): + """SimpleMapper is a PixelMapper which maps events to the nearest Pixel. It also supports + strings of the form: + {x}>5, {y}<10, {x}*{y}<{x}, etc. (Conditons, separated by commas. and and or may also be + used).""" def mappingFunction(self, eventLocation, screen): if type(eventLocation) == type(tuple()): bestDist = sys.maxint @@ -19,7 +23,6 @@ class SimpleMapper(PixelMapper): return [] else: #{x}>5,{y}1) for i in range(4)]) == 4 + def addLocations(l1,l2): return tuple([l1[i]+l2[i] for i in range(len(l1))]) + def gaussian(x,height,center,width): a=height b=center c=width return a*math.exp(-((x-b)**2)/(2*c**2)) + def dist(l1, l2): - return math.sqrt((l1[0]-l2[0])**2+(l1[1]-l2[1])**2) - #return math.sqrt(sum([(l1[i]-l2[i])**2 for i in range(len(l1))])) + return math.sqrt((l1[0]-l2[0])**2+(l1[1]-l2[1])**2) #For speed + def randomLoc(boundingBox): #TODO: make less shitty loc = [] loc.append(random.randint(0, boundingBox[0])) loc.append(random.randint(0, boundingBox[1])) return tuple(loc) + def approxexp(x): + """Approximates exp with a 3 term Taylor Series.""" return 1+x+x**2/2+x**3/6 diff --git a/util/NetworkOps.py b/util/NetworkOps.py index 6c50c6d..8894b78 100644 --- a/util/NetworkOps.py +++ b/util/NetworkOps.py @@ -8,4 +8,3 @@ def getConnectedSocket(ip,port): except Exception as inst: main_log.error('Network down. All network based renderers and sensors will not function.', inst) - print (ip, port) diff --git a/util/PacketComposition.py b/util/PacketComposition.py index c4fcdc3..7b4fe95 100644 --- a/util/PacketComposition.py +++ b/util/PacketComposition.py @@ -6,6 +6,7 @@ UNI = 0 import pdb import util.TimeOps as timeops argDict = {'flags': 0, 'startcode': 0, 'pad':0} + def composePixelStripData(pixelStrip,currentTime=timeops.time()): packet = bytearray() for light in pixelStrip: @@ -19,6 +20,7 @@ def composePixelStripData(pixelStrip,currentTime=timeops.time()): #color = pixelStrip.pixels[i].state() #packet[i:i+2] = color # return bytearray(packet) + cache = {} def memoize(f): def helper(x): @@ -26,6 +28,7 @@ def memoize(f): cache[x] = f(x) return cache[x] return helper + @memoize def cachePacketHeader(port): packet = bytearray() @@ -35,11 +38,13 @@ def cachePacketHeader(port): packet.extend(portOutPacket(subDict)) packet.append(0x0) return packet + def composePixelStripPacket(pixelStrip,port, currentTime): packet = bytearray(cachePacketHeader(port)) data = composePixelStripData(pixelStrip, currentTime) packet.extend(data) return packet + def packheader(): header = bytearray() header.extend(struct.pack('L', MAGIC)) @@ -47,18 +52,20 @@ def packheader(): header.extend(struct.pack('H', PORTOUT)) header.extend(struct.pack('L', 0)) return header + def portOut(): header = packheader() header.extend(struct.pack('L', UNI)) return header + def portOutPayload(argDict): payload = bytearray() payload.extend(struct.pack('B', argDict['port'])) payload.extend(struct.pack('H', argDict['flags'])) - #payload.append(0x00) #somepadding? lolwtf. payload.extend(struct.pack('H', argDict['len'])) payload.extend(struct.pack('H', argDict['startcode'])) return payload + def portOutPacket(payloadArgs): packet = bytearray() packet.extend(portOut()) diff --git a/util/Search.py b/util/Search.py index f7e4b81..1499e23 100644 --- a/util/Search.py +++ b/util/Search.py @@ -1,13 +1,13 @@ from bisect import * def find_le(a, x): - 'Find rightmost value less than or equal to x' + """Find rightmost value less than or equal to x""" return bisect_right(a, x)-1 def find_ge(a, x): - 'Find leftmost value greater than x' + """Find leftmost value greater than x""" return bisect_left(a, x) -#returns parents of nodes that meed a given condition def parental_tree_search(root, childrenstr, conditionstr): + """Returns parents of nodes that meed a given condition""" ret = [] queue = [root] while queue: diff --git a/util/TimeOps.py b/util/TimeOps.py index dcd5038..841efab 100644 --- a/util/TimeOps.py +++ b/util/TimeOps.py @@ -1,6 +1,7 @@ import time as clock def time(): return clock.time()*1000 #all times in MS + class Stopwatch: def __init__(self): self.running = False -- cgit v1.2.3 From 44659801073c059aeac5a992dc241648263c74b6 Mon Sep 17 00:00:00 2001 From: mdan Date: Thu, 27 Jan 2011 17:58:47 -0500 Subject: Modifies OSC configuration and behavior. --- behaviors/TouchOSC.py | 3 ++- config/6thFloorOSC.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'config') diff --git a/behaviors/TouchOSC.py b/behaviors/TouchOSC.py index 1c41b5e..354b845 100644 --- a/behaviors/TouchOSC.py +++ b/behaviors/TouchOSC.py @@ -12,7 +12,8 @@ class TouchOSC(Behavior): self.xy = (-1,-1) def processResponse(self, sensorInputs, recursiveInputs): ret = [] - for data in sensorInputs: + if sensorInputs: + data = sensorInputs[-1]#for data in sensorInputs: if data['Path'] == '/1/fader1': try: self.h = data['Value'][0]*360.0 diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml index 792fd0c..d3f0e6f 100644 --- a/config/6thFloorOSC.xml +++ b/config/6thFloorOSC.xml @@ -42,7 +42,7 @@ osc 12345 - 10 + 20 -- cgit v1.2.3 From 6341992254c837b1d814b3eaa24b2ab3e729c8e2 Mon Sep 17 00:00:00 2001 From: eugue Date: Thu, 27 Jan 2011 20:27:12 -0500 Subject: Added HTMLInput, SmootWind behavior, and a config file for testing. --- behaviors/SmootWind.py | 32 +++++++ behaviors/XYMove.py | 2 +- config/HTMLTest.xml | 58 +++++++++++++ config/SmootWindTest.xml | 166 +++++++++++++++++++++++++++++++++++++ inputs/HTMLInput.py | 29 +++++++ pixelmappers/WindGaussianMapper.py | 18 ++++ util/Geo.py | 6 ++ 7 files changed, 310 insertions(+), 1 deletion(-) create mode 100755 behaviors/SmootWind.py create mode 100755 config/HTMLTest.xml create mode 100755 config/SmootWindTest.xml create mode 100755 inputs/HTMLInput.py create mode 100755 pixelmappers/WindGaussianMapper.py (limited to 'config') diff --git a/behaviors/SmootWind.py b/behaviors/SmootWind.py new file mode 100755 index 0000000..bf05ab2 --- /dev/null +++ b/behaviors/SmootWind.py @@ -0,0 +1,32 @@ +from operationscore.Behavior import * +import util.ComponentRegistry as compReg + +class SmootWind(Behavior): + def behaviorInit(self): + self.mapper = None + self.xFor = None + + def processResponse(self, sensorInputs, recursiveInputs): + if self.mapper == None: + try: + self.mapper = compReg.getComponent('windgaussmap') + except KeyError: + pass + if self.xFor == None: + try: + self.xFor = compReg.getComponent('xfor') + except KeyError: + pass + + for sensory in sensorInputs: + #print sensory + # input[0] is windspeed, [1] is dir + windSpeed = sensory[0] + windDir = sensory[1] + + #print self.mapper.argDict + self.mapper.argDict['Width'] = float(windSpeed) ** 3 + self.xFor.argDict['ParamOp'] = float(windSpeed) ** 2 + #print 'Width: ' + str(self.mapper.argDict['Width']) + #print 'xFor: ' + str(self.xFor.argDict['ParamOp']) + return (sensorInputs, recursiveInputs) diff --git a/behaviors/XYMove.py b/behaviors/XYMove.py index 0ba3baf..44a93bb 100644 --- a/behaviors/XYMove.py +++ b/behaviors/XYMove.py @@ -13,7 +13,7 @@ class XYMove(Behavior): for loc in sensor: oploc = dict(loc) self.insertStepIfMissing(oploc) - print oploc['YStep'] + #print oploc['YStep'] oploc['Location'] = Geo.addLocations((oploc['XStep'], oploc['YStep']), oploc['Location']) ret.append(oploc) return (ret, []) diff --git a/config/HTMLTest.xml b/config/HTMLTest.xml new file mode 100755 index 0000000..159cec4 --- /dev/null +++ b/config/HTMLTest.xml @@ -0,0 +1,58 @@ + + + + simplemap + + + + layouts/BasicSixStrip.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 30 + 0.1 + 10 + 1 + + + + + + renderers/Pygame.xml + + + + + inputs.HTMLInput + + weatherinput + 'http://sailing.mit.edu/weather/' + + 'rtWindSpeed = (\d+).*\s.*\s.*rtWindDir = (\d+)' + + + + + + + behaviors.EchoBehavior + + + weatherinput + + echo + False + + + + diff --git a/config/SmootWindTest.xml b/config/SmootWindTest.xml new file mode 100755 index 0000000..a494720 --- /dev/null +++ b/config/SmootWindTest.xml @@ -0,0 +1,166 @@ + + + + + simplemap + + + + layouts/60StripLayout.xml + + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 10 + 0.1 + 10 + 5 + + + + pixelmappers.WindGaussianMapper + + windgaussmap + 150 + 0.005 + 30 + 10 + + + + + + + renderers/Pygame.xml + + + + + inputs.PygameInput + + pygame + 1 + + + + inputs.HTMLInput + + weatherinput + 'http://sailing.mit.edu/weather/' + + 'rtWindSpeed = (\d+).*\s.*\s.*rtWindDir = (\d+)' + + + + + inputs.RandomLocs + + randomLoc + + + + + + behaviors/RandomColor.xml + + + behaviors/RandomColor.xml + + + (100,200,255) + (50,200,255) + (0,200,255) + (0,150,255) + + + + + behaviors/PixelDecay.xml + + + behaviors.XYMove + + xymove + 0 + 0 + + + + behaviors.BehaviorChain + + movebounce + + xymove + yfor + xfor + + + + + behaviors.ModifyParam + + yfor + YStep + Sensor + 10*(2*math.sin({x}/float(100))+math.sin({x}/float(50))) + + + + + behaviors.ModifyParam + + xfor + XStep + Sensor + + 25 + + + + + behaviors.SmootWind + + smootwind + + weatherinput + + + + + behaviors.ResponseMover + + mover + + + + behaviors.BehaviorChain + + xymover + + pygame + randomLoc + + + staticcolor + mover + decay + + {'mover':'movebounce'} + True + windgaussmap + + + + diff --git a/inputs/HTMLInput.py b/inputs/HTMLInput.py new file mode 100755 index 0000000..9697a32 --- /dev/null +++ b/inputs/HTMLInput.py @@ -0,0 +1,29 @@ +from operationscore.Input import * +import urllib, re + +""" +HTML Input, which takes 2 arguments: +- 'Src': a URL to a web page, and +- 'Regex': a Regex to parse data out of the web page. +The input parses the source code of the web page according to the regex, and processes the parsed regex groups. +""" +class HTMLInput(Input): + def inputInit(self): + self.src = self.argDict['Src'] + self.regex = self.argDict['Regex'] + + def getHTML(self): + self.sock = urllib.urlopen(self.src); + self.html = self.sock.read() + self.sock.close() + + def sensingLoop(self): + self.getHTML() + self.dataList = [] + + pattern = re.compile(self.regex) + matchObj = pattern.search(self.html) + self.dataList = matchObj.groups() + + self.respond(self.dataList) + diff --git a/pixelmappers/WindGaussianMapper.py b/pixelmappers/WindGaussianMapper.py new file mode 100755 index 0000000..c5d77ca --- /dev/null +++ b/pixelmappers/WindGaussianMapper.py @@ -0,0 +1,18 @@ +from operationscore.PixelMapper import * +import util.Geo as Geo +import math +class WindGaussianMapper(PixelMapper): + def mappingFunction(self, eventLocation, screen): + returnPixels = [] #TODO: consider preallocation and trimming + [x,y] = eventLocation + potentialPixels = screen.pixelsInRange(x-self.CutoffDist, x) + for (xloc,pixel) in screen.pixelsInRange(x-self.CutoffDist, x): + pixelDistx = math.fabs(pixel.location[0] - x) + pixelDisty = math.fabs(pixel.location[1] - y) + if pixelDistx < self.CutoffDist: + if pixelDisty < 30: + w = Geo.windtrail(pixelDistx, pixelDisty, self.Height, 0, self.Width) + if w > self.MinWeight: + returnPixels.append((pixel, w)) + + return returnPixels diff --git a/util/Geo.py b/util/Geo.py index 05ea9fe..0dde80b 100644 --- a/util/Geo.py +++ b/util/Geo.py @@ -26,3 +26,9 @@ def randomLoc(boundingBox): #TODO: make less shitty def approxexp(x): """Approximates exp with a 3 term Taylor Series.""" return 1+x+x**2/2+x**3/6 + +def windtrail(x,y,height,center,width): + a=height + b=center + c=width + return a*((math.exp(-((x-b))/(c)))**2)*(math.exp(-((y))/(0.2*c)))**2 -- cgit v1.2.3 From 3319a58ecc391f9aac092ade45f9f50dc2af5aa6 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 09:50:38 -0500 Subject: Finishing up for the demo --- behaviors/Accelerate.xml | 2 +- behaviors/DimColor.xml | 2 +- behaviors/Expand.py | 3 ++- behaviors/MITDoors.py | 7 +++++++ behaviors/ResponseMover.py | 8 +------- behaviors/XYMove.py | 1 - config/6thFloor.xml | 2 +- inputs/PygameInput.py | 2 +- pixelcore/Screen.py | 19 +++++++------------ 9 files changed, 21 insertions(+), 25 deletions(-) (limited to 'config') diff --git a/behaviors/Accelerate.xml b/behaviors/Accelerate.xml index f9de077..c78195b 100644 --- a/behaviors/Accelerate.xml +++ b/behaviors/Accelerate.xml @@ -3,6 +3,6 @@ Sensor StepSize - {val}*1.1 + {val}*1.01 diff --git a/behaviors/DimColor.xml b/behaviors/DimColor.xml index 58b0673..ef98fee 100644 --- a/behaviors/DimColor.xml +++ b/behaviors/DimColor.xml @@ -3,6 +3,6 @@ Sensor Color - [chan*.95 for chan in {val}] + [chan*.98 for chan in {val}] diff --git a/behaviors/Expand.py b/behaviors/Expand.py index 323e71f..f017c16 100644 --- a/behaviors/Expand.py +++ b/behaviors/Expand.py @@ -15,7 +15,8 @@ class Expand(Behavior): data = dict(data) data['Left'] -= data['ExpandRate'] data['Right'] += data['ExpandRate'] - data['Location'] = "{x}>" + str(data['Left']) + ", {x}<" + str(data['Right']) + data['Location'] = "{x}>" + str(data['Left']) + ", {x}<" +\ + str(data['Right'])+", {y}<50" ret.append(data) return (ret, []) diff --git a/behaviors/MITDoors.py b/behaviors/MITDoors.py index d602a55..03bef6d 100644 --- a/behaviors/MITDoors.py +++ b/behaviors/MITDoors.py @@ -1,4 +1,6 @@ from operationscore.Behavior import * +import math +import util.ComponentRegistry as compReg class MITDoors(Behavior): """MITDoors is a case-specific behavior to map keypresses to specific locations. Written for Kuan 1/26/11 by RCOH""" @@ -6,6 +8,11 @@ class MITDoors(Behavior): def behaviorInit(self): self.keymapping = {'q':[2,19], 'w':[22,36], 'e':[37,49], 'r':[52,69], 't':[76,91], 'y':[94,105], 'u':[106,117], 'i':[123,154], 'o':[158,161], 'p':[164,167], '[':[172,184]} + screenWidth = compReg.getComponent('Screen').getSize()[2] #(minx, miny,maxx, maxy) + maxKey = max([max(self.keymapping[v]) for v in self.keymapping]) + mult = screenWidth / float(maxKey) + for k in self.keymapping: + self.keymapping[k] = [int(val*mult) for val in self.keymapping[k]] def processResponse(self, sensorInputs, recursiveInputs): ret = [] for data in sensorInputs: diff --git a/behaviors/ResponseMover.py b/behaviors/ResponseMover.py index 59e353a..3d559df 100644 --- a/behaviors/ResponseMover.py +++ b/behaviors/ResponseMover.py @@ -7,11 +7,5 @@ class ResponseMover(Behavior): modulates the location.""" def processResponse(self, sensorInputs, recursiveInputs): - newResponses = sensorInputs - ret = [] - for recurInput in recursiveInputs: - outDict = dict(recurInput) - ret.append(outDict) - ret += newResponses - return (ret, ret) + return (recursiveInputs, recursiveInputs+sensorInputs) diff --git a/behaviors/XYMove.py b/behaviors/XYMove.py index 0ba3baf..11cee96 100644 --- a/behaviors/XYMove.py +++ b/behaviors/XYMove.py @@ -13,7 +13,6 @@ class XYMove(Behavior): for loc in sensor: oploc = dict(loc) self.insertStepIfMissing(oploc) - print oploc['YStep'] oploc['Location'] = Geo.addLocations((oploc['XStep'], oploc['YStep']), oploc['Location']) ret.append(oploc) return (ret, []) diff --git a/config/6thFloor.xml b/config/6thFloor.xml index 81f0c9f..ef195ec 100644 --- a/config/6thFloor.xml +++ b/config/6thFloor.xml @@ -186,7 +186,7 @@ behaviors.BehaviorChain - inpexpanddim + doors pygamekey diff --git a/inputs/PygameInput.py b/inputs/PygameInput.py index 399a77e..18f463d 100644 --- a/inputs/PygameInput.py +++ b/inputs/PygameInput.py @@ -23,7 +23,7 @@ class PygameInput(Input): if event.key == 27: self.die() if self['Keyboard']: - self.respond({'Key': event.key}) + self.respond({'Key': event.key, 'KeyChar': chr(event.key)}) return else: pygame.event.post(event) diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py index 9a81df7..ada8d4a 100644 --- a/pixelcore/Screen.py +++ b/pixelcore/Screen.py @@ -22,14 +22,14 @@ class Screen: sizeValid = False self.pixelsSorted = False - def addStrip(self, lS): - self.pixelStrips.append(lS) + def addStrip(self, strip): + self.pixelStrips.append(strip) self.sizeValid = False #keep track of whether or not our screen size has self.pixelsSorted = False #been invalidated by adding more pixels def pixelsInRange(self, minX, maxX): - """Returns (pixelIndex, pixel). Does a binary search.""" + """Returns (pixelIndex, pixel). Does a binary search. Sorts first if neccesary.""" if not self.pixelsSorted: self.computeXSortedPixels() minIndex = Search.find_ge(self.xPixelLocs, minX) @@ -48,12 +48,11 @@ class Screen: return itertools.chain(*[strip.__iter__() for strip in \ self.pixelStrips]) #the * operator breaks the list into args - #increment time -- This processes all queued responses. Responses generated - #during this period are added to the queue that will be processed on the next - #time step. #SUBVERTING DESIGN FOR EFFICIENCY 1/24/11, RCOH -- It would be cleaner to store the time on the responses #themselves, however, it is faster to just pass it in. def timeStep(self, currentTime=None): + """Increments time -- This processes all queued responses, adding that to a queue that will + be processed on the next time step.""" if currentTime == None: currentTime = timeops.time() tempQueue = list(self.responseQueue) @@ -66,6 +65,7 @@ class Screen: self.responseQueue.append(responseInfo) def getSize(self): + """Returns the size of the screen in the form: (minx, miny, maxx, maxy)""" if self.sizeValid: return self.size (minX, minY, maxX, maxY) = (sys.maxint,sys.maxint,-sys.maxint,-sys.maxint) @@ -79,24 +79,19 @@ class Screen: maxY = max(y, maxY) self.size = (0,0, maxX, maxY) self.sizeValid = True - print self.size - return (0, 0, maxX+100, maxY+100) #TODO: cleaner + return (0, 0, maxX, maxY) #private def processResponse(self, responseInfo, currentTime=None): #we need to make a new dict for #each to prevent interference - #[strip.respond(dict(responseInfo)) for strip in self.pixelStrips] if currentTime == None: currentTime = timeops.time() - print 'cachetime fail' if type(responseInfo) != type(dict()): pass if 'Mapper' in responseInfo: mapper = compReg.getComponent(responseInfo['Mapper']) else: mapper = compReg.getComponent(Strings.DEFAULT_MAPPER) - #if type(mapper) != type(PixelMapper): - # raise Exception('No default mapper specified.') pixelWeightList = mapper.mapEvent(responseInfo['Location'], self) main_log.debug('Screen processing response. ' + str(len(pixelWeightList)) + ' events\ generated') -- cgit v1.2.3 From ef1abfa913498e02a4ece3be4be45d2f03e47d05 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 15:19:21 -0500 Subject: Lots of stuff INCOMPLETE --- LightInstallation.py | 2 +- behaviors/ExpandingColorZones.py | 7 ++++--- behaviors/MITDoors.py | 1 + behaviors/RiseFall.py | 6 ++++++ behaviors/SmootWind.py | 24 +++++++++++++++++------- config/6thFloorOSC.xml | 30 +++++++++++++++++++++++++++++- config/Jennifer.xml | 1 + config/Kuan.xml | 9 +++++++++ config/SmootWindTest.xml | 12 ++++++++++-- inputs/OSCInput.py | 4 ++-- inputs/PygameInput.py | 5 ++++- pixelcore/Pixel.py | 4 +++- renderers/IndoorRenderer.py | 7 ++++++- util/NetworkOps.py | 6 ++++++ util/PacketComposition.py | 15 ++++++++++++--- 15 files changed, 111 insertions(+), 22 deletions(-) (limited to 'config') diff --git a/LightInstallation.py b/LightInstallation.py index 24ad8b1..c1f01e8 100755 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -139,7 +139,7 @@ class LightInstallation(object): def mainLoop(self): lastLoopTime = clock.time() - refreshInterval = 30 + refreshInterval = 30 while not self.dieNow: #dieNow is set if one of its constituents sends a die request. loopStart = clock.time() responses = self.evaluateBehaviors() diff --git a/behaviors/ExpandingColorZones.py b/behaviors/ExpandingColorZones.py index 345851e..75be761 100644 --- a/behaviors/ExpandingColorZones.py +++ b/behaviors/ExpandingColorZones.py @@ -2,13 +2,14 @@ from operationscore.Behavior import * from logger import main_log class ExpandingColorZones(Behavior): def behaviorInit(self): - self.mapping = {'r':[(132,0),(255,0,0)], 'g':[(400,0), (0,255,0)], - 'b':[(668,0), + self.mapping = {'s001':[(132,0),(255,0,0)], 's002':[(400,0), (0,255,0)], + 's003':[(668,0), (0,0,255)]} - self.mappingkey = 'KeyChar' + self.mappingkey = 'data' def processResponse(self, sensorInputs, recursiveInputs): ret = [] for data in sensorInputs: + print data data = dict(data) if self.mappingkey in data: try: diff --git a/behaviors/MITDoors.py b/behaviors/MITDoors.py index 03bef6d..cee47f0 100644 --- a/behaviors/MITDoors.py +++ b/behaviors/MITDoors.py @@ -23,5 +23,6 @@ class MITDoors(Behavior): data['Left'], data['Right'] = bounds data['Bottom'] = self['Bottom'] data['Location'] = (sum(bounds) / 2., self['Bottom']) + data['Oscillate'] = False ret.append(data) return (ret, []) diff --git a/behaviors/RiseFall.py b/behaviors/RiseFall.py index 109cd10..eea2283 100644 --- a/behaviors/RiseFall.py +++ b/behaviors/RiseFall.py @@ -29,7 +29,13 @@ class RiseFall(Behavior): data['Right'] = data['Location'][0]+data['Width']/2. currentTime = timeOps.time() deltaTime = currentTime-data['StartTime'] + #if data['Oscillate'] == True: data['Height'] = data['MaxHeight']*math.sin(deltaTime/data['Period']*(math.pi*2)) + #else: + # data['Height'] = data['MaxHeight'] + #if (currentTime-data['StartTime']) > data['Period']: + # del data['StartTime'] + data['Location'] = "{x}>"+str(data['Left']) + ", " +\ "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ {y}>"+str(data['Bottom']-data['Height']) diff --git a/behaviors/SmootWind.py b/behaviors/SmootWind.py index 347e2fc..804183c 100755 --- a/behaviors/SmootWind.py +++ b/behaviors/SmootWind.py @@ -22,12 +22,22 @@ class SmootWind(Behavior): for sensory in sensorInputs: print sensory # input[0] is windspeed, [1] is dir - windSpeed = sensory[0] - windDir = sensory[1] + if 0 in sensory and 1 in sensory: + windSpeed = sensory[0] + windDir = sensory[1] + #print self.mapper.argDict + self.mapper.argDict['Width'] = self.mapper.argDict['Width']+float(windSpeed)*2+20 + self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+float(windSpeed)*3+10*random.random(); + #print 'Width: ' + str(self.mapper.argDict['Width']) + #print 'xFor: ' + str(self.xFor.argDict['ParamOp']) + + elif 'Key' in sensory: + if sensory['Key'] == 273: + self.mapper.argDict['Width'] = self.mapper.argDict['Width']+10; + self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+5; + + elif sensory['Key'] == 274: + self.mapper.argDict['Width'] = self.mapper.argDict['Width']-10; + self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']-5; - #print self.mapper.argDict - self.mapper.argDict['Width'] = float(windSpeed)*2+20 - self.xFor.argDict['ParamOp'] = float(windSpeed)*3+10*random.random(); - #print 'Width: ' + str(self.mapper.argDict['Width']) - #print 'xFor: ' + str(self.xFor.argDict['ParamOp']) return (sensorInputs, recursiveInputs) diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml index 792fd0c..2215688 100644 --- a/config/6thFloorOSC.xml +++ b/config/6thFloorOSC.xml @@ -37,6 +37,14 @@ + + inputs.OSCInput + + osc2 + 1234 + 10 + + inputs.OSCInput @@ -79,6 +87,12 @@ False + + + sixaxis + + behaviors.ControllerOSC + touchosc @@ -262,13 +276,27 @@ + + behaviors.BehaviorChain + + mousechaser2 + + osc2 + + + sixaxis + singleframe + + True + gaussmap + + behaviors.BehaviorChain mousechaser - tcp osc diff --git a/config/Jennifer.xml b/config/Jennifer.xml index e6cfc40..179c462 100644 --- a/config/Jennifer.xml +++ b/config/Jennifer.xml @@ -98,6 +98,7 @@ colorbars pygamekey + udp colorzones diff --git a/config/Kuan.xml b/config/Kuan.xml index c85cb75..7d76ed4 100644 --- a/config/Kuan.xml +++ b/config/Kuan.xml @@ -82,6 +82,15 @@ 2000 + behaviors.MITDoors diff --git a/config/SmootWindTest.xml b/config/SmootWindTest.xml index 6b74450..f6e7a97 100755 --- a/config/SmootWindTest.xml +++ b/config/SmootWindTest.xml @@ -53,6 +53,14 @@ 1 + + inputs.PygameInput + + pygamekey + 10 + True + + inputs.HTMLInput @@ -141,8 +149,8 @@ smootwind - weatherinput - + pygamekey + diff --git a/inputs/OSCInput.py b/inputs/OSCInput.py index f867fb5..ba1e035 100644 --- a/inputs/OSCInput.py +++ b/inputs/OSCInput.py @@ -7,8 +7,8 @@ class OSCInput(Input): def inputInit(self): HOST = '' # Symbolic name meaning all available interfaces PORT = self['Port'] # Arbitrary non-privileged port - self.server = liblo.Server(PORT) - self.server.add_method(None,None, self.fallback) + self.server = liblo.Server(PORT) + self.server.add_method(None,None, self.fallback) # except liblo.ServerError, err: # main_log.error(str(err)) diff --git a/inputs/PygameInput.py b/inputs/PygameInput.py index 18f463d..414adf3 100644 --- a/inputs/PygameInput.py +++ b/inputs/PygameInput.py @@ -23,7 +23,10 @@ class PygameInput(Input): if event.key == 27: self.die() if self['Keyboard']: - self.respond({'Key': event.key, 'KeyChar': chr(event.key)}) + try: + self.respond({'Key': event.key, 'KeyChar': chr(event.key)}) + except: + self.respond({'Key': event.key}) return else: pygame.event.post(event) diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py index 6ff2e67..4e7cfce 100644 --- a/pixelcore/Pixel.py +++ b/pixelcore/Pixel.py @@ -1,4 +1,5 @@ import util.ColorOps as color +from logger import main_log import pdb from pixelevents.StepEvent import * import util.TimeOps as timeops @@ -57,7 +58,8 @@ class Pixel: if eventResult != None: scaledEvent = color.multiplyColor(eventResult,scale) if (scaledEvent[0] + scaledEvent[1] + scaledEvent[2]) < 5: - deadEvents.append(eventObj) + pass + #deadEvents.append(eventObj) else: colors.append(scaledEvent) else: diff --git a/renderers/IndoorRenderer.py b/renderers/IndoorRenderer.py index 531a732..710ca43 100644 --- a/renderers/IndoorRenderer.py +++ b/renderers/IndoorRenderer.py @@ -21,7 +21,7 @@ class IndoorRenderer(Renderer): for stripId in stripsInPowerSupply: self.stripLocations[stripId] = (ip, \ stripsInPowerSupply[stripId]) - + self.broadSocket = network.getBroadcastSocket(6038) def render(self, lightSystem, currentTime=timeops.time()): #try: for pixelStrip in lightSystem.pixelStrips: @@ -32,4 +32,9 @@ class IndoorRenderer(Renderer): self.sockets[ip] = network.getConnectedSocket(ip,sock_port) packet = composer.composePixelStripPacket(pixelStrip, port, currentTime) self.sockets[ip].send(packet, 0x00) + + synchPacket = composer.composeSynchPacket() + #pdb.set_trace() + #self.broadSocket.sendto(synchPacket, ('10.0.32.255', 6038)) + diff --git a/util/NetworkOps.py b/util/NetworkOps.py index 8894b78..3ece763 100644 --- a/util/NetworkOps.py +++ b/util/NetworkOps.py @@ -8,3 +8,9 @@ def getConnectedSocket(ip,port): except Exception as inst: main_log.error('Network down. All network based renderers and sensors will not function.', inst) + +def getBroadcastSocket(port): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + return s diff --git a/util/PacketComposition.py b/util/PacketComposition.py index 7b4fe95..75ef917 100644 --- a/util/PacketComposition.py +++ b/util/PacketComposition.py @@ -5,7 +5,7 @@ PORTOUT = 0x0108 UNI = 0 import pdb import util.TimeOps as timeops -argDict = {'flags': 0, 'startcode': 0, 'pad':0} +argDict = {'flags': 0, 'startcode': 0x0fff, 'pad':0} def composePixelStripData(pixelStrip,currentTime=timeops.time()): packet = bytearray() @@ -33,10 +33,10 @@ def memoize(f): def cachePacketHeader(port): packet = bytearray() subDict = dict(argDict) - subDict['len'] = 38500 #I have no idea why this works. + subDict['len'] = 150 #I have no idea why this works. subDict['port'] = port packet.extend(portOutPacket(subDict)) - packet.append(0x0) +# packet.append(0x0) return packet def composePixelStripPacket(pixelStrip,port, currentTime): @@ -61,10 +61,19 @@ def portOut(): def portOutPayload(argDict): payload = bytearray() payload.extend(struct.pack('B', argDict['port'])) + payload.extend(struct.pack('B',0)) payload.extend(struct.pack('H', argDict['flags'])) payload.extend(struct.pack('H', argDict['len'])) payload.extend(struct.pack('H', argDict['startcode'])) return payload +def composeSynchPacket(): + header = bytearray() + header.extend(struct.pack('L', MAGIC)) + header.extend(struct.pack('H', VERSION)) + header.extend(struct.pack('H', 0x0109)) + header.extend(struct.pack('L', 0)) + header.extend(struct.pack('L', 0)) + return header def portOutPacket(payloadArgs): packet = bytearray() -- cgit v1.2.3 From 3cf7f82b2c88181925e01c2736e13d8be7574ab9 Mon Sep 17 00:00:00 2001 From: eugue Date: Fri, 28 Jan 2011 15:19:40 -0500 Subject: get string data instead of int --- behaviors/MobileShakeBehavior.py | 29 +++++++++++++++++++---------- behaviors/MoveBehavior.py | 18 ++++++++++-------- config/MobileTest.xml | 28 ++++++++++++---------------- inputs/TCPInput.py | 2 ++ 4 files changed, 43 insertions(+), 34 deletions(-) (limited to 'config') diff --git a/behaviors/MobileShakeBehavior.py b/behaviors/MobileShakeBehavior.py index e25e929..b05cb5f 100644 --- a/behaviors/MobileShakeBehavior.py +++ b/behaviors/MobileShakeBehavior.py @@ -1,17 +1,26 @@ from operationscore.Behavior import * +import util.ComponentRegistry as compReg import util.Strings as Strings class MobileShakeBehavior(Behavior): + def behaviorInit(self): + self.mapper = None + def processResponse(self, sensorInputs, recursiveInputs): + if self.mapper == None: + try: + self.mapper = compReg.getComponent('mobilegaussmap') + except KeyError: + pass + #print sensorInputs - ret = [] for sInput in sensorInputs: - outDict = dict(sInput) - if 'type' in sInput and sInput['type'] == 2: - outDict['Location'] = '{x}>' + str(0) + ',{y}>' + str(0) - outDict['Color'] = [sInput['r'], sInput['g'], sInput['b']] - else: # dumb invisible pixel - outDict['Location'] = (-1, -1) - outDict['Color'] = [0, 0, 0] - ret.append(outDict) - return (ret, recursiveInputs) + if 'Shake' in sInput and sInput['Shake'] == 1: + #print 'increase!' + self.mapper.argDict['Width'] += 30 + #self.mapper.argDict['CutoffDist'] += 20 + sInput['Shake'] = 0 + print 'Width:' + str(compReg.getComponent('mobilegaussmap').argDict['Width']) + #print 'CutoffDist: '+ str(compReg.getComponent('mobilegaussmap').argDict['CutoffDist']) + + return (sensorInputs, recursiveInputs) diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index e504ca9..6f57437 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -13,20 +13,22 @@ class MoveBehavior(Behavior): else: currRecLocs = [{'Location' : (5, 5), 'Color' : [255, 255, 255]}] + #print sensorInputs if sensorInputs: # if input exists, change location ret = [] for currRecLoc in currRecLocs: currDict = dict(currRecLoc) for sensorInput in sensorInputs: - if 'type' in sensorInput and sensorInput['type'] == 1: - currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ - currDict['Location'][1] + sensorInput['y'] * self['YStep']) - currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] - #elif sensorInput['type'] == 2: - # currDict['Shake'] = 1 - # currDict['Force'] = sensorInput['force'] + if 'type' in sensorInput and int(sensorInput['type']) == 1: + #currDict['Shake'] = 0 + currDict['Location'] = (currDict['Location'][0] - int(sensorInput['x']) * self['XStep'], \ + currDict['Location'][1] + int(sensorInput['y']) * self['YStep']) + currDict['Color'] = [int(sensorInput['r']), int(sensorInput['g']), int(sensorInput['b'])] + elif int(sensorInput['type']) == 2: + #print sensorInput + currDict['Shake'] = 1 + #currDict['Force'] = sensorInput['force'] ret.append(currDict) - #print ret return (ret, ret) else: # if not, return current recursive location. diff --git a/config/MobileTest.xml b/config/MobileTest.xml index af94c25..63c3b47 100644 --- a/config/MobileTest.xml +++ b/config/MobileTest.xml @@ -26,6 +26,16 @@ 1 + + pixelmappers.GaussianMapper + + mobilegaussmap + 30 + 0.1 + 10 + 1 + + @@ -227,26 +237,12 @@ move + mobileshake decay True - gaussmap + mobilegaussmap - - behaviors.BehaviorChain - - shakeanddecay - - tcp - - - mobileshake - slowdecay - - True - simplemap - - diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py index 17ea7e6..2d8ab4d 100644 --- a/inputs/TCPInput.py +++ b/inputs/TCPInput.py @@ -38,6 +38,8 @@ class TCPInput(Input): for datagroup in data.split('\n'): if datagroup != None and datagroup != '': dataDict = json.loads(datagroup) + #if dataDict['type'] != 1: + #print dataDict self.respond(dataDict) except Exception as exp: print str(exp) -- cgit v1.2.3 From bd1119e82ff9f4bd8835ed6d3934f156a6da8b23 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 16:24:21 -0500 Subject: Fixed TCPInput bug. --- config/6thFloorOSC.xml | 67 +++++++++++++++++++++++++++++++++++++++++--------- inputs/TCPInput.py | 14 ++++++++++- 2 files changed, 69 insertions(+), 12 deletions(-) (limited to 'config') diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml index 2215688..aa7a07d 100644 --- a/config/6thFloorOSC.xml +++ b/config/6thFloorOSC.xml @@ -60,14 +60,14 @@ 10 - + inputs/MouseFollower.xml @@ -79,15 +79,60 @@ - - behaviors.EchoBehavior - - echo - 0 - False - - - + + behaviors.EchoBehavior + + echo + 0 + False + + + + behaviors.BehaviorChain + + moveanddecay + + tcp + + + move + decay + + True + gaussmap + + + + behaviors.MoveBehavior + + move + 3 + 3 + + + + behaviors.MobileShakeBehavior + + mobileshake + 3 + + + + behaviors.BehaviorChain + + shakeanddecay + + tcp + + + mobileshake + slowdecay + + True + simplemap + + + sixaxis diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py index 17ea7e6..51a6677 100644 --- a/inputs/TCPInput.py +++ b/inputs/TCPInput.py @@ -4,6 +4,7 @@ from operationscore.Input import * import socket, json, time import logging as main_log import string +from select import select class TCPInput(Input): """TCPInput is a input to receive input on a TCP port. In its current incarnation, it parses @@ -20,9 +21,20 @@ class TCPInput(Input): self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.bind((self.HOST, self.PORT)) self.sock.listen(1) - (self.conn, self.address) = self.sock.accept() + + isreadable=select([self.sock],[],[], 0)[0] + self.conn = None + if isreadable: + (self.conn, self.address) = self.sock.accept() def sensingLoop(self): + if self.conn == None: + isreadable=select([self.sock],[],[], 0)[0] + if isreadable: + (self.conn, self.address) = self.sock.accept() + else: + return + data = self.conn.recv(self.BUFFER_SIZE) main_log.debug('Incoming data', data) -- cgit v1.2.3 From b67a37ad06fa4c97dcdb32cecc71c7f492b12840 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 16:29:36 -0500 Subject: Picking up some files that were lost. --- behaviors/ControllerOSC.py | 67 +++++++++++++++++++++++++++++++++++++++++++ behaviors/Sink.py | 42 +++++++++++++++++++++++++++ behaviors/SynchTest.py | 12 ++++++++ config/SynchTest.xml | 39 +++++++++++++++++++++++++ pixelevents/SynchTestEvent.py | 15 ++++++++++ 5 files changed, 175 insertions(+) create mode 100644 behaviors/ControllerOSC.py create mode 100644 behaviors/Sink.py create mode 100644 behaviors/SynchTest.py create mode 100644 config/SynchTest.xml create mode 100644 pixelevents/SynchTestEvent.py (limited to 'config') diff --git a/behaviors/ControllerOSC.py b/behaviors/ControllerOSC.py new file mode 100644 index 0000000..ce2cf26 --- /dev/null +++ b/behaviors/ControllerOSC.py @@ -0,0 +1,67 @@ +from operationscore.Behavior import * +from logger import main_log +#import util.ColorOps as color +import colorsys +from numpy import array +import pdb +import util.ComponentRegistry as compReg + +speedfactor = 15 +vel_decay = .00 + +def constrainLocation(v,c): + if v[0] > c[0]: + v[0] = c[0] + elif v[0]<0: + v[0] = 0 + + if v[1] > c[1]: + v[1] = c[1] + elif v[1]<0: + v[1] = 0 + + return v + +class ControllerOSC(Behavior): + def behaviorInit(self): + self.xy = array((0,0)) + self.v_xy = array((0,0)) + self.v_decay = vel_decay + + self.start_hsv = [0,1,1] + self.dest_hsv = [0,1,1] + self.ssize = compReg.getComponent('Screen').getSize()[-2:] #896 x 310 + + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + if sensorInputs: + data = sensorInputs[-1]#for data in sensorInputs: + if data['Path'] == '/sixaxis/xy': + #try: + x = data['Value'][0] + y = data['Value'][1] + main_log.error(str(x)) + if y < 0: + self.start_hsv[1] = 1.0+y #s + else: + self.start_hsv[2] = 1.0-y + self.start_hsv[0] = (x+1) * 180.0 + elif data['Path'] == '/sixaxis/lrud': + val=data['Value'] + vy = val[3]-val[2] + vx = val[1]-val[0] + #pdb.set_trace() + #self.v_xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1]) + self.v_xy = array((vx, vy)) * speedfactor + else: + main_log.error('Sensor Inputs: ' + str(sensorInputs)) + self.xy = self.xy + self.v_xy + constrainLocation(self.xy,self.ssize) + self.v_xy -= self.v_decay + if self.v_xy[0] < 0: + self.v_xy[0] = 0 + if self.v_xy[1] < 0: + self.v_xy[1] = 0 + ret.append({'Color':[i*255 for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':(int(self.xy[0]), int(self.xy[1]))}) + + return (ret, []) diff --git a/behaviors/Sink.py b/behaviors/Sink.py new file mode 100644 index 0000000..52d0be2 --- /dev/null +++ b/behaviors/Sink.py @@ -0,0 +1,42 @@ + +from operationscore.Behavior import * +import math +import util.TimeOps as timeOps +#Required Args: +#Period (ms), MaxHeight, Width +class Sink(Behavior): + """RiseFall is a behavior that creates a rising and falling column of light. Specify: + -- the maximum height that it rises to. + -- the width of the column OR and + -- the period of oscillation in ms + + Designed to be used as part of a recursive hook. + """ + + def processResponse(self, sensorInputs, recurInputs): + ret = [] + for data in sensorInputs: + #first time with behavior: + data = dict(data) + if not 'StartTime' in data: + data['StartTime'] = timeOps.time() + data['Period'] = self['Period'] + data['MaxHeight'] = self['MaxHeight'] #Consider just using += + if not 'Bottom' in data: + data['Bottom'] = data['Location'][1] + if 'Width' in self: #TODO: improve + data['Width'] = self['Width'] + data['Left'] = data['Location'][0]-data['Width']/2. + data['Right'] = data['Location'][0]+data['Width']/2. + currentTime = timeOps.time() + deltaTime = currentTime-data['StartTime'] + data['Height'] = data['MaxHeight']*math.cos(deltaTime/data['Period']*(math.pi*2)) + + data['Location'] = "{x}>"+str(data['Left']) + ", " +\ + "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ + {y}>"+str(data['Bottom']-data['Height']) + + ret.append(data) + return (ret, []) + + diff --git a/behaviors/SynchTest.py b/behaviors/SynchTest.py new file mode 100644 index 0000000..e7b8acc --- /dev/null +++ b/behaviors/SynchTest.py @@ -0,0 +1,12 @@ +from operationscore.Behavior import * +from pixelevents.SynchTestEvent import * +import pdb +class SynchTest(Behavior): + def behaviorInit(self): + self.rendered = False + def processResponse(self, sensorInputs, recurs): + if not self.rendered: + self.rendered = True + print 'here1' + return ([{'Location':'True', 'PixelEvent':SynchTestEvent({'Color':(255,0,0)})}], []) + return ([], []) diff --git a/config/SynchTest.xml b/config/SynchTest.xml new file mode 100644 index 0000000..fcb8293 --- /dev/null +++ b/config/SynchTest.xml @@ -0,0 +1,39 @@ + + + + + simplemap + + + + layouts/60StripLayout.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + + + renderers/60StripSeq.xml + + + renderers/Pygame.xml + + + + + + + behaviors.SynchTest + + synch + True + + + + diff --git a/pixelevents/SynchTestEvent.py b/pixelevents/SynchTestEvent.py new file mode 100644 index 0000000..3e7ed0c --- /dev/null +++ b/pixelevents/SynchTestEvent.py @@ -0,0 +1,15 @@ +from operationscore.PixelEvent import * +class SynchTestEvent(PixelEvent): + """SynchTestEvent is an event to test the synchronization of the power supplies""" + def initEvent(self): + self.eventstate = 0 + self.cachedDelay = 0 + def state(self, timeDelay): + if timeDelay != self.cachedDelay: + self.eventstate += 1 + self.cachedDelay = timeDelay + color = [0]*3 + color[self.eventstate % 3] = 150 + if self.eventstate > 500: + self.eventstate = 0 + return color -- cgit v1.2.3 From da934a838305bab72bd12dcd2b83e689f7c1cc3f Mon Sep 17 00:00:00 2001 From: Jim Salem Date: Fri, 28 Jan 2011 18:28:25 -0500 Subject: New Flasher behavior which fades colors in and out. Several new color functions. Created a "firefly" demo (moving colored bubbles that fade in and out) --- behaviors/EchoBehavior.py | 5 +- behaviors/Flasher.py | 41 +++++ behaviors/RandomSetBrightColorBehavior.py | 14 ++ config/FireflyDemo.xml | 261 ++++++++++++++++++++++++++++++ util/ColorOps.py | 15 ++ 5 files changed, 335 insertions(+), 1 deletion(-) create mode 100644 behaviors/Flasher.py create mode 100644 behaviors/RandomSetBrightColorBehavior.py create mode 100644 config/FireflyDemo.xml (limited to 'config') diff --git a/behaviors/EchoBehavior.py b/behaviors/EchoBehavior.py index 6ef4fcb..c4af7c0 100644 --- a/behaviors/EchoBehavior.py +++ b/behaviors/EchoBehavior.py @@ -9,6 +9,9 @@ class EchoBehavior(Behavior): for sensory in sensorInputs: outDict = {} outDict[Strings.LOCATION] = sensory[Strings.LOCATION] - outDict['Color'] = (255,0,0) + if self['Color'] != None: + outDict['Color'] = self['Color'] + else: + outDict['Color'] = (255,0,0) ret.append(outDict) return (ret, []) diff --git a/behaviors/Flasher.py b/behaviors/Flasher.py new file mode 100644 index 0000000..4a2dad4 --- /dev/null +++ b/behaviors/Flasher.py @@ -0,0 +1,41 @@ +# Implements a pulsing/flashing behavior. +# Jim Salem: jsalem@gmail.com +# +# Args: +# Factor - The speed of flashing. Must be b/w 0 and 1. Default is .95 +# + +from operationscore.Behavior import * +import util.ColorOps as colorops +import pdb +class Flasher(Behavior): + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + for response in sensorInputs: + # Get the multiplier + if self['Factor'] != None: + factor = self['Factor'] + else: + factor = 0.95 + # Initialize the first time + if not 'FireflyStartColor' in response: + response['FireflyValue'] = 1.0 + response['FireflyDir'] = 1 + response['FireflyStartColor'] = response['Color']; + else: + # Update the current value + if response['FireflyDir'] == 1: + response['FireflyValue'] = response['FireflyValue'] * factor + if response['FireflyValue'] <= 0.01: + response['FireflyValue'] = 0.01 + response['FireflyDir'] = 0 + else: + response['FireflyValue'] = response['FireflyValue'] / factor + if response['FireflyValue'] >= 1.0: + response['FireflyValue'] = 1.0 + response['FireflyDir'] = 1 + + # Compute the color + response['Color'] = colorops.multiplyColor(response['FireflyStartColor'], response['FireflyValue']) + ret.append(response) + return (ret, []) #no direct ouput diff --git a/behaviors/RandomSetBrightColorBehavior.py b/behaviors/RandomSetBrightColorBehavior.py new file mode 100644 index 0000000..f278858 --- /dev/null +++ b/behaviors/RandomSetBrightColorBehavior.py @@ -0,0 +1,14 @@ +from operationscore.Behavior import * +import util.ColorOps as color +import pdb +import colorsys +import random +class RandomSetBrightColorBehavior(Behavior): + """Sets a random color that is bright.""" + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + for sensory in sensorInputs: + newDict = dict(sensory) + newDict['Color'] = color.randomBrightColor() + ret.append(newDict) + return (ret, []) diff --git a/config/FireflyDemo.xml b/config/FireflyDemo.xml new file mode 100644 index 0000000..8008168 --- /dev/null +++ b/config/FireflyDemo.xml @@ -0,0 +1,261 @@ + + + + + + + + + + simplemap + + + + layouts/60StripLayout.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 30 + 0.1 + 10 + 1 + + + + + + + renderers/Pygame.xml + + + + + inputs.PygameInput + + pygameclick + 10 + True + + + + inputs.PygameInput + + pygamekey + 10 + True + + + + inputs.UDPInput + + udp + 3344 + 50 + + + + + inputs/MouseFollower.xml + + + + + + behaviors.RandomSetBrightColorBehavior + + setbrightcolor + + + + + behaviors/RandomColor.xml + + + (255,0,0) + (0,0,255) + + + + + behaviors/PixelDecay.xml + + .5 + + + + behaviors/PixelDecay.xml + + + behaviors/SingleFrame.xml + + + behaviors/PixelDecay.xml + + .01 + + + + behaviors.XYMove + + xymove + 5 + 2 + + + + behaviors.RestrictLocation + + xbounce + {val}*-1 + XStep + {x}<0 or {x}>800 + + + + behaviors.RestrictLocation + + ybounce + {val}*-1 + YStep + {y}<0 or {y}>200 + + + + behaviors.BehaviorChain + + movebounce + + xymove + ybounce + xbounce + + + + + behaviors.Flasher + + flasher + + + + + behaviors.BehaviorChain + + flashermovebounce + + randmovement + ybounce + xbounce + + flasher + + + + + behaviors.Square + + square + 15 + + + + behaviors/LoopAndDie.xml + + 80 + + + + behaviors.RandomWalk + + randmovement + 20 + + + + + behaviors.ModifyParam + + fadecolor + Sensor + Color + [chan*.98 for chan in {val}] + + + + + behaviors.BehaviorChain + + runcolordecay + + pygameclick + + + setbrightcolor + mover + decay + + {'mover':'flashermovebounce'} + True + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors/Accelerate.xml + + + behaviors.EchoBehavior + + echo + 0 + (90,90,90) + False + + + + behaviors.BehaviorChain + + mousechaser + + followmouse + + + echo + square + singleframe + + True + + + + + behaviors/RunningBehavior.xml + + + diff --git a/util/ColorOps.py b/util/ColorOps.py index 037957a..d971ad0 100644 --- a/util/ColorOps.py +++ b/util/ColorOps.py @@ -1,4 +1,5 @@ import random +import colorsys from util.TimeOps import Stopwatch def randomColor(): return [random.randint(0,255) for i in range(3)] @@ -23,3 +24,17 @@ def combineColors(colors): def multiplyColor(color, percent): return safeColor([channel*(percent) for channel in color]) + +def floatToIntColor(rgb): + rgb[0] = int(rgb[0]*256 + .5) + rgb[1] = int(rgb[1]*256 + .5) + rgb[2] = int(rgb[2]*256 + .5) + return safeColor(rgb) + +def randomBrightColor(): + hue = random.random() + sat = random.random()/2.0 + .5 + val = 1.0 + hue, sat, val = colorsys.hsv_to_rgb(hue, sat, val) + ret = [hue, sat, val] + return floatToIntColor(ret) -- cgit v1.2.3 From 277a5143165d2553ce5e97f151cc6b3cea426468 Mon Sep 17 00:00:00 2001 From: rcoh Date: Sat, 29 Jan 2011 21:15:28 -0500 Subject: A couple bits of cleanup to the firefly code --- behaviors/Flasher.py | 12 +++--- config/FireflyDemo.xml | 106 ++----------------------------------------------- 2 files changed, 10 insertions(+), 108 deletions(-) (limited to 'config') diff --git a/behaviors/Flasher.py b/behaviors/Flasher.py index 4a2dad4..1d79d41 100644 --- a/behaviors/Flasher.py +++ b/behaviors/Flasher.py @@ -1,14 +1,14 @@ -# Implements a pulsing/flashing behavior. -# Jim Salem: jsalem@gmail.com -# -# Args: -# Factor - The speed of flashing. Must be b/w 0 and 1. Default is .95 -# from operationscore.Behavior import * import util.ColorOps as colorops import pdb class Flasher(Behavior): + """Implements a pulsing/flashing behavior. + Jim Salem: jsalem@gmail.com + + Args: + Factor - The speed of flashing. Must be b/w 0 and 1. Default is .95 + """ def processResponse(self, sensorInputs, recursiveInputs): ret = [] for response in sensorInputs: diff --git a/config/FireflyDemo.xml b/config/FireflyDemo.xml index 8008168..856569e 100644 --- a/config/FireflyDemo.xml +++ b/config/FireflyDemo.xml @@ -33,11 +33,9 @@ - renderers/Pygame.xml @@ -67,62 +65,18 @@ 50 - - - inputs/MouseFollower.xml - - behaviors.RandomSetBrightColorBehavior - - setbrightcolor - - - - - behaviors/RandomColor.xml + behaviors.RandomSetBrightColorBehavior - - (255,0,0) - (0,0,255) - - - - - behaviors/PixelDecay.xml - - .5 + setbrightcolor behaviors/PixelDecay.xml - - behaviors/SingleFrame.xml - - - behaviors/PixelDecay.xml - - .01 - - - - behaviors.XYMove - - xymove - 5 - 2 - - behaviors.RestrictLocation @@ -141,24 +95,12 @@ {y}<0 or {y}>200 - - behaviors.BehaviorChain - - movebounce - - xymove - ybounce - xbounce - - - behaviors.Flasher flasher - behaviors.BehaviorChain @@ -167,8 +109,7 @@ randmovement ybounce xbounce - - flasher + flasher @@ -179,12 +120,6 @@ 15 - - behaviors/LoopAndDie.xml - - 80 - - behaviors.RandomWalk @@ -192,17 +127,6 @@ 20 - - - behaviors.ModifyParam - - fadecolor - Sensor - Color - [chan*.98 for chan in {val}] - - - behaviors.BehaviorChain @@ -226,36 +150,14 @@ mover - - behaviors/Accelerate.xml - behaviors.EchoBehavior echo 0 - (90,90,90) + (90,90,90) False - - behaviors.BehaviorChain - - mousechaser - - followmouse - - - echo - square - singleframe - - True - - - - - behaviors/RunningBehavior.xml - -- cgit v1.2.3 From e34b4dbf8ba67c5374e43bea8b469172025a9163 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 29 Jan 2011 18:50:58 -0800 Subject: 6thFloorOsc commented out renderer to lights, default LightInstallation config and profile.py for OSC :) --- LightInstallation.py | 2 +- Profile.py | 2 +- config/6thFloorOSC.xml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'config') diff --git a/LightInstallation.py b/LightInstallation.py index c1f01e8..41cc925 100755 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -193,7 +193,7 @@ class LightInstallation(object): def main(argv): if len(argv) == 1: - l = LightInstallation('LightInstallationConfig.xml') + l = LightInstallation('config/6thFloor.xml') else: l = LightInstallation(argv[1]) diff --git a/Profile.py b/Profile.py index 2f180c9..2f796b2 100644 --- a/Profile.py +++ b/Profile.py @@ -1,4 +1,4 @@ import cProfile from LightInstallation import main -command = """main(['', 'config/6thFloor.xml'])""" +command = """main(['', 'config/6thFloorOSC.xml'])""" cProfile.runctx(command, globals(), locals(), filename="smootlight.profile") diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml index cb1fd10..ca99b2b 100644 --- a/config/6thFloorOSC.xml +++ b/config/6thFloorOSC.xml @@ -29,9 +29,9 @@ - + renderers/Pygame.xml -- cgit v1.2.3 From 482a94fd48627153b923931d6ff21ebf57fad6f7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 29 Jan 2011 19:34:24 -0800 Subject: removed duplicate OSC server--one is much faster. Building more into custom input would probably be even faster. --- config/6thFloorOSC.xml | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'config') diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml index ca99b2b..05c2973 100644 --- a/config/6thFloorOSC.xml +++ b/config/6thFloorOSC.xml @@ -40,19 +40,19 @@ inputs.OSCInput - osc2 + osc 1234 10 - + inputs.PygameInput @@ -110,7 +110,7 @@ 3 - + sixaxis @@ -188,7 +188,7 @@ {y}<0 or {y}>200 - + + behaviors.AllPixelsLeft @@ -245,7 +245,7 @@ allpixels - + + behaviors.BehaviorChain - mousechaser2 + SixaxisChase - osc2 + osc sixaxis @@ -339,9 +339,8 @@ behaviors.BehaviorChain - mousechaser + OSCTouchChase - osc -- cgit v1.2.3