blob: 662b8fe8e9abc683a326da69a16c99b8ec47c2ca (
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
|
from pixelcore.Pixel import *
import util.Strings as Strings
import util.Geo as Geo
from pixelevents.StepEvent import *
import math
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) 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):
location = responseInfo[Strings.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 = [(Geo.dist(location, pixel.location), pixel) for pixel in self.pixels]
dists.sort()
return dists[0]
#just for now.
|