1 import util.ColorOps as color
2 from logger import main_log
3 import pdb
4 from pixelevents.StepEvent import *
5 import util.TimeOps as timeops
7 """Pixel keeps a queue of events (PixelEvent objects) (actually a dictionary
8 keyed by event time). Every time is state is
9 requested, it processes all the members of its queue. If a member returns none,
10 it is removed from the queue. Otherwise, its value added to the Pixels color
11 weighted by z-index. To get the current color of the pixel, call the state method."""
12
13 radius = 2
14 timeOff = -1
15
17 self.location = location
18 self.events = []
19 self.lastRenderTime = timeops.time()
20 self.lastRender = (0,0,0)
21
24
25
26
27
31
32
34 if currentTime == None:
35 currentTime = timeops.time()
36 self.events.append((currentTime, zindex, scale, pixelEvent))
39
40 - def state(self, currentTime=None):
41 """Combines all PixelEvents currently active and computes the current color of
42 the pixel."""
43 if currentTime == None:
44 currentTime = timeops.time()
45 if currentTime-self.lastRenderTime < 5:
46 return self.lastRender
47 if self.events == []:
48 self.lastRenderTime = currentTime
49 return (0,0,0)
50 deadEvents = []
51 resultingColor = (0,0,0)
52 colors = []
53 for eventObj in self.events:
54 if len(self.events) > 50:
55 main_log.error('High pixel event count! Investigate!')
56 eventTime, zindex, scale, pixelEvent = eventObj
57 eventResult = pixelEvent.state(currentTime-eventTime)
58 if eventResult != None:
59 scaledEvent = color.multiplyColor(eventResult,scale)
60 if (scaledEvent[0] + scaledEvent[1] + scaledEvent[2]) < 5:
61 pass
62
63 else:
64 colors.append(scaledEvent)
65 else:
66 deadEvents.append(eventObj)
67
68 resultingColor = color.combineColors(colors)
69 [self.events.remove(event) for event in deadEvents]
70 resultingColor = [int(round(c)) for c in resultingColor]
71 self.lastRender = tuple(resultingColor)
72 self.lastRenderTime = currentTime
73 return tuple(resultingColor)
74
76 return 'Loc: ' + str(self.location)
77