From b042647b68abdc82490ca6e059993b8eba28904c Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Wed, 24 Nov 2010 01:09:12 -0500 Subject: Refactoring complete! Made modules/packages as appropriate. Finally. --- pixelcore/PixelStrip.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 pixelcore/PixelStrip.py (limited to 'pixelcore/PixelStrip.py') 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. + -- cgit v1.2.3