From 67c62d8c9e650f594e9aea348b8ed0c1351c7d81 Mon Sep 17 00:00:00 2001 From: rcoh Date: Thu, 17 Feb 2011 02:45:27 -0500 Subject: Added JPGInput to process images. Modified Input and LightInstallation to support passing multiple inputs simultaeneously. Added FadeIn Pixel event. Needs work / configurability. --- LightInstallation.py | 5 ++- behaviors/StepLight.xml | 7 ++++ config/C5Sign.xml | 2 +- config/C5Work.xml | 78 +++++++++++++++++++++++++++++++++++++++++++++ inputs/JPGInput.py | 33 +++++++++++++++++++ operationscore/Input.py | 6 +++- pixelcore/Pixel.py | 2 ++ pixelevents/FadeIn.py | 12 +++++++ renderers/PygameRenderer.py | 2 +- 9 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 behaviors/StepLight.xml create mode 100644 config/C5Work.xml create mode 100644 inputs/JPGInput.py create mode 100644 pixelevents/FadeIn.py diff --git a/LightInstallation.py b/LightInstallation.py index 19d6c54..3f9500f 100755 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -182,8 +182,11 @@ class LightInstallation(object): def processResponse(self,inputDict, responseDict): inputId = inputDict['Id'] boundBehaviorIds = self.inputBehaviorRegistry[inputId] + if not isinstance(responseDict, list): + responseDict = [responseDict] try: - [compReg.getComponent(b).addInput(responseDict) for b in boundBehaviorIds] + for r in responseDict: + [compReg.getComponent(b).addInput(r) for b in boundBehaviorIds] except: pass #Behavior run before loading. Not a big deal. diff --git a/behaviors/StepLight.xml b/behaviors/StepLight.xml new file mode 100644 index 0000000..3bb773a --- /dev/null +++ b/behaviors/StepLight.xml @@ -0,0 +1,7 @@ + + behaviors.AddPixelEvent + + pixelevents.StepEvent + 4500 + + diff --git a/config/C5Sign.xml b/config/C5Sign.xml index 024f0d8..77f6bcc 100644 --- a/config/C5Sign.xml +++ b/config/C5Sign.xml @@ -208,7 +208,7 @@ centerleft center - {'scanningbars':0,'runcolordecay':10,'expandingcircles':10} + {'scanningbars':10,'runcolordecay':10,'expandingcircles':10} {'scanningbars':'centerleft', 'runcolordecay':'center',\ 'expandingcircles':'center'} True diff --git a/config/C5Work.xml b/config/C5Work.xml new file mode 100644 index 0000000..6aac21a --- /dev/null +++ b/config/C5Work.xml @@ -0,0 +1,78 @@ + + + + + simplemap + + + + layouts/C5SignLayout.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 1 + 0.1 + 1 + .5 + + + + pixelmappers.C5SignMapper + + c5signmapper + 20 + + + + + + renderers/Pygame.xml + + + renderers/C5Renderer.xml + + + + + inputs.JPGInput + + jpg + 5000 + ../../C5SignImages + + + + inputs.PygameInput + + pygamekey + 10 + True + + + + + + behaviors/PixelDecay.xml + + pixelevents.FadeIn + image + + jpg + + .0005 + True + gaussmap + + + + diff --git a/inputs/JPGInput.py b/inputs/JPGInput.py new file mode 100644 index 0000000..fd58a47 --- /dev/null +++ b/inputs/JPGInput.py @@ -0,0 +1,33 @@ +from operationscore.Input import * +from PIL import Image +import util.ComponentRegistry as compReg +import os +class JPGInput(Input): + def inputInit(self): + self.images = [] + self.imageIndex = 0 + compReg.getLock().acquire() + minX,minY,maxX,maxY = compReg.getComponent('Screen').getSize() + compReg.getLock().release() + sWidth = maxX-minX + sHeight = maxY-minY + for filename in os.listdir(self['Directory']): + path = os.path.join(self['Directory'], filename) + if '.jpg' in path or '.bmp' in path: + im = Image.open(path) #file to open + (w,h)=im.size + print w,h + xScale = sWidth/float(w) + yScale = sHeight/float(h) + pixels = [] + for x in range(w): + for y in range(h): + rgb = im.getpixel((x,y)) + pixels.append({'Location':(x*xScale+minX,minY+y*yScale),'Color':rgb}) + + self.images.append(pixels) + + def sensingLoop(self): + self.imageIndex += 1 + self.imageIndex = self.imageIndex % len(self.images) + self.respond(self.images[self.imageIndex]) diff --git a/operationscore/Input.py b/operationscore/Input.py index 5a835ec..7720847 100644 --- a/operationscore/Input.py +++ b/operationscore/Input.py @@ -17,7 +17,11 @@ class Input(ThreadedSmootCoreObject): self.inputInit() def respond(self, eventDict): - eventDict['InputId'] = self['Id'] + if isinstance(eventDict, list): + for d in eventDict: + d['InputId'] = self['Id'] + else: + eventDict['InputId'] = self['Id'] self.parentScope.lock.acquire() self.parentScope.processResponse(self.argDict, eventDict) self.parentScope.lock.release() diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py index cf5a328..308e7ea 100644 --- a/pixelcore/Pixel.py +++ b/pixelcore/Pixel.py @@ -66,6 +66,8 @@ class Pixel: deadEvents.append(eventObj) resultingColor = color.combineColors(colors) + #if colors: + # resultingColor = [c / len(colors) for c in resultingColor] [self.events.remove(event) for event in deadEvents] resultingColor = [int(round(c)) for c in resultingColor] self.lastRender = tuple(resultingColor) diff --git a/pixelevents/FadeIn.py b/pixelevents/FadeIn.py new file mode 100644 index 0000000..c080476 --- /dev/null +++ b/pixelevents/FadeIn.py @@ -0,0 +1,12 @@ +import math +from operationscore.PixelEvent import * +from util.ColorOps import * +import util.Geo as Geo +class FadeIn(PixelEvent): + def state(self, timeDelay): + decay = math.sin(timeDelay/float(1000)) + if timeDelay > 5000: + return None + if timeDelay > 2000 and timeDelay < 4000: + decay = 1 + return multiplyColor(self.Color,decay) diff --git a/renderers/PygameRenderer.py b/renderers/PygameRenderer.py index 8be272c..ad50c1e 100644 --- a/renderers/PygameRenderer.py +++ b/renderers/PygameRenderer.py @@ -25,7 +25,7 @@ class PygameRenderer(Renderer): for light in lightSystem: scaledLoc = [l*scale for l in light.location] pygame.draw.circle(self.background, light.state(currentTime), scaledLoc, \ - 5) + self['Scale']) self.screen.blit(self.background, (0,0)) pygame.display.flip() -- cgit v1.2.3