aboutsummaryrefslogtreecommitdiff
path: root/pixelcore/PixelStrip.py
blob: 14c87d98032ab58622dcad9b51f070dd86b43f15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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.