diff options
author | rcoh <rcoh@mit.edu> | 2011-02-17 02:45:27 -0500 |
---|---|---|
committer | rcoh <rcoh@mit.edu> | 2011-02-17 02:45:27 -0500 |
commit | 67c62d8c9e650f594e9aea348b8ed0c1351c7d81 (patch) | |
tree | e71d7ac7fc2538eda3e43e8e591342cab9620d06 | |
parent | 2df9e408a0ff74539862c4a4e562a878cc11a329 (diff) |
Added JPGInput to process images. Modified Input and LightInstallation to support passing multiple
inputs simultaeneously. Added FadeIn Pixel event. Needs work / configurability.
-rwxr-xr-x | LightInstallation.py | 5 | ||||
-rw-r--r-- | behaviors/StepLight.xml | 7 | ||||
-rw-r--r-- | config/C5Sign.xml | 2 | ||||
-rw-r--r-- | config/C5Work.xml | 78 | ||||
-rw-r--r-- | inputs/JPGInput.py | 33 | ||||
-rw-r--r-- | operationscore/Input.py | 6 | ||||
-rw-r--r-- | pixelcore/Pixel.py | 2 | ||||
-rw-r--r-- | pixelevents/FadeIn.py | 12 | ||||
-rw-r--r-- | renderers/PygameRenderer.py | 2 |
9 files changed, 143 insertions, 4 deletions
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 @@ +<Behavior> + <Class>behaviors.AddPixelEvent</Class> + <Args> + <Class>pixelevents.StepEvent</Class> + <LightTime>4500</LightTime> + </Args> +</Behavior> 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 @@ <Id>centerleft</Id> <Id>center</Id> </Inputs> - <TimeMap>{'scanningbars':0,'runcolordecay':10,'expandingcircles':10}</TimeMap> + <TimeMap>{'scanningbars':10,'runcolordecay':10,'expandingcircles':10}</TimeMap> <InputMap>{'scanningbars':'centerleft', 'runcolordecay':'center',\ 'expandingcircles':'center'}</InputMap> <RenderToScreen>True</RenderToScreen> 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 @@ +<!---All configuration items contain a "Class" tag specifying the python class they represent, and an "Args" tag specifying the args to be passed in.--> +<LightInstallation> + <InstallationConfiguration> + <Defaults> + <PixelMapper>simplemap</PixelMapper> + </Defaults> + </InstallationConfiguration> + <PixelConfiguration> + <InheritsFrom>layouts/C5SignLayout.xml</InheritsFrom> + </PixelConfiguration> + <PixelMapperConfiguration> + <PixelMapper> + <Class>pixelmappers.SimpleMapper</Class> + <Args> + <Id>simplemap</Id> + <CutoffDist>20</CutoffDist> + </Args> + </PixelMapper> + <PixelMapper> + <Class>pixelmappers.GaussianMapper</Class> + <Args> + <Id>gaussmap</Id> + <CutoffDist>1</CutoffDist> + <MinWeight>0.1</MinWeight> + <Width>1</Width> + <Height>.5</Height> + </Args> + </PixelMapper> + <PixelMapper> + <Class>pixelmappers.C5SignMapper</Class> + <Args> + <Id>c5signmapper</Id> + <CutoffDist>20</CutoffDist> + </Args> + </PixelMapper> + </PixelMapperConfiguration> + <RendererConfiguration> + <Renderer Scale="5"> + <InheritsFrom>renderers/Pygame.xml</InheritsFrom> + </Renderer> + <Renderer> + <InheritsFrom>renderers/C5Renderer.xml</InheritsFrom> + </Renderer> + </RendererConfiguration> + <InputConfiguration> + <InputElement> + <Class>inputs.JPGInput</Class> + <Args> + <Id>jpg</Id> + <RefreshInterval>5000</RefreshInterval> + <Directory>../../C5SignImages</Directory> + </Args> + </InputElement> + <InputElement> + <Class>inputs.PygameInput</Class> + <Args> + <Id>pygamekey</Id> + <RefreshInterval>10</RefreshInterval> + <Keyboard>True</Keyboard> + </Args> + </InputElement> + </InputConfiguration> + <BehaviorConfiguration> + <Behavior> + <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom> + <Args> + <Class>pixelevents.FadeIn</Class> + <Id>image</Id> + <Inputs> + <Id>jpg</Id> + </Inputs> + <Coefficient>.0005</Coefficient> + <RenderToScreen>True</RenderToScreen> + <Mapper>gaussmap</Mapper> + </Args> + </Behavior> + </BehaviorConfiguration> +</LightInstallation> 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() |