diff options
author | Russell Cohen <rcoh@mit.edu> | 2010-11-24 01:09:12 -0500 |
---|---|---|
committer | Russell Cohen <rcoh@mit.edu> | 2010-11-24 01:09:12 -0500 |
commit | b042647b68abdc82490ca6e059993b8eba28904c (patch) | |
tree | a9ee95a38e98b377c251b7b2e9af9cbd8056cf7c /pixelcore/PixelStrip.py | |
parent | 407ac922fc4178021cf3a16dfb1bd875b6083ac4 (diff) |
Refactoring complete! Made modules/packages as appropriate. Finally.
Diffstat (limited to 'pixelcore/PixelStrip.py')
-rw-r--r-- | pixelcore/PixelStrip.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/pixelcore/PixelStrip.py b/pixelcore/PixelStrip.py new file mode 100644 index 0000000..14c87d9 --- /dev/null +++ b/pixelcore/PixelStrip.py @@ -0,0 +1,40 @@ +from pixelcore.Pixel import * +from pixelevents.StepEvent import * +import pygame +import math +import Util +import pdb +#Python class representing a single Pixel strip (usually 50 Pixels) +class PixelStrip: + def __init__(self, layoutEngine): + self.initStrip(layoutEngine) + self.argDict = layoutEngine.getStripArgs() + def initStrip(self, layoutEngine): + pixelLocations = layoutEngine.getPixelLocations() + self.pixels = [Pixel(l, (0,0,0)) 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): + print 'PixelEvent', responseInfo + location = responseInfo[Util.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 = [(Util.dist(location, pixel.location), pixel) for pixel in self.pixels] + dists.sort() + return dists[0] + #just for now. + |