aboutsummaryrefslogtreecommitdiff
path: root/pixelcore/Pixel.py
diff options
context:
space:
mode:
authorGravatar Thomas B Thompson <tbent@spice.(none)>2011-01-04 00:04:05 -0500
committerGravatar Thomas B Thompson <tbent@spice.(none)>2011-01-04 00:04:05 -0500
commit134de4472d3f2fa913944770595de9221dd27fdf (patch)
treecf83e29a1ef4931a15f9b30125fedbd8fba8caf9 /pixelcore/Pixel.py
parentf9aeaf10e3c9077504a78374640e79415734546b (diff)
worked on profiling, made a bunch of changes, huge speedup!
Diffstat (limited to 'pixelcore/Pixel.py')
-rw-r--r--pixelcore/Pixel.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py
index f66d0bb..9f5cc85 100644
--- a/pixelcore/Pixel.py
+++ b/pixelcore/Pixel.py
@@ -1,7 +1,7 @@
import util.ColorOps as color
import pdb
from pixelevents.StepEvent import *
-import util.TimeOps as clock
+import util.TimeOps as timeops
#Pixel keeps a queue of events (PixelEvent objects) (actually a dictionary
#keyed by event time). Every time is state is
#requested, it processes all the members of its queue. If a member returns none,
@@ -10,12 +10,15 @@ import util.TimeOps as clock
class Pixel:
radius = 2
timeOff = -1
+
def __init__(self, location):
self.location = location
self.events = {}
self.memState = None
+
def turnOn(self):
self.turnOnFor(-1)
+
#Turn the light white for 'time' ms. Really only meant for testing. Use
#processInput instead. Also, you shouldn't use this anyway. You should be
#using the input method on the screen!
@@ -23,34 +26,42 @@ class Pixel:
event = StepEvent.generate(time, (255,255,255)) #TODO: Move color to
self.processInput(event, 0)
#arg
+
#Add a pixelEvent to the list of active events
def processInput(self,pixelEvent,zindex): #consider migrating arg to dict
- self.events[clock.time()] = (zindex, pixelEvent)
+ self.events[timeops.time()] = (zindex, pixelEvent)
+
def clearAllEvents(self):
self.events = {}
+
#Combines all PixelEvents currently active and computes the current color of
#the pixel.
def invalidateState(self):
self.memState = None
+
def state(self):
if self.memState != None:
return self.memState
- if len(self.events) == 0:
+ if self.events == []:
return (0,0,0)
deadEvents = []
- currentTime = clock.time()
+ currentTime = timeops.time()
resultingColor = (0,0,0)
+ colors = []
for eventTime in self.events: #TODO: right color weighting code
(zindex,event) = self.events[eventTime]
eventResult = event.state(currentTime-eventTime)
if eventResult != None:
- resultingColor = color.combineColors(eventResult, resultingColor)
+ colors.append(eventResult)
else:
deadEvents.append(eventTime)
+
+ resultingColor = color.combineColors(colors)
[self.events.pop(event) for event in deadEvents]
resultingColor = [int(round(c)) for c in resultingColor]
self.memState = tuple(resultingColor)
return tuple(resultingColor)
+
def __str__(self):
return 'Loc: ' + str(self.location)