aboutsummaryrefslogtreecommitdiff
path: root/pixelcore/Pixel.py
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-01-04 17:23:30 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-01-04 17:23:30 -0500
commit1679719e7ca8ce433c5714474a32c926161dc5b8 (patch)
treedc75dc66ee8695fe786df2b48c0e6911332ed7c5 /pixelcore/Pixel.py
parent395e99394ead5d0d656e74fed23dc780652b6090 (diff)
Some performance improvements -- we also synchronize all the frames, giving us a meaning that even
if things slow down, rendering doesn't look weird.
Diffstat (limited to 'pixelcore/Pixel.py')
-rw-r--r--pixelcore/Pixel.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py
index 9f5cc85..b9fc07f 100644
--- a/pixelcore/Pixel.py
+++ b/pixelcore/Pixel.py
@@ -14,7 +14,8 @@ class Pixel:
def __init__(self, location):
self.location = location
self.events = {}
- self.memState = None
+ self.lastRenderTime = timeops.time()
+ self.lastRender = (0,0,0)
def turnOn(self):
self.turnOnFor(-1)
@@ -28,24 +29,23 @@ class Pixel:
#arg
#Add a pixelEvent to the list of active events
- def processInput(self,pixelEvent,zindex): #consider migrating arg to dict
- self.events[timeops.time()] = (zindex, pixelEvent)
+ def processInput(self,pixelEvent,zindex, currentTime=None): #consider migrating arg to dict
+ if currentTime == None:
+ currentTime = timeops.time()
+ self.events[currentTime] = (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 self.events == []:
+ def state(self, currentTime=timeops.time()): #TODO: this only evaluates at import time, I think
+ if currentTime-self.lastRenderTime < 5:
+ return self.lastRender
+ if self.events == {}:
+ self.lastRenderTime = currentTime
return (0,0,0)
deadEvents = []
- currentTime = timeops.time()
resultingColor = (0,0,0)
colors = []
for eventTime in self.events: #TODO: right color weighting code
@@ -59,7 +59,8 @@ class Pixel:
resultingColor = color.combineColors(colors)
[self.events.pop(event) for event in deadEvents]
resultingColor = [int(round(c)) for c in resultingColor]
- self.memState = tuple(resultingColor)
+ self.lastRender = tuple(resultingColor)
+ self.lastRenderTime = currentTime
return tuple(resultingColor)
def __str__(self):