Hi all,
I'm using pyglet for experiments in cognitive science, where we want
to obtain accurate information on when images are presented and erased
from the screen. I've developed the code below to play around with
different display rates and the timing thereof, and I'm encountering
some odd behavior. The script repeats a timing test multiple times,
each time waiting some delay then showing a square on the screen then
waiting another delay before taking the square off the screen. When I
make the onset delay either an integer or any value <1 refresh, the
results make sense (very close to the expected timing error), but when
I make the onset delay a non-integer value >1 I observe seemingly
nonsensical results of near-zero timing error. Am I approaching the
problem incorrectly somehow?
my_refresh = 60 #specify your refresh rate
import pyglet, time
win=pyglet.window.Window(fullscreen=True)
win.dispatch_events() #display won't work unless an intial dispatch
has been done
win.set_exclusive_mouse() #ensures the mouse is invisible
#set the background and drawing colors
pyglet.gl.glClearColor(0, 0, 0, 0)
pyglet.gl.glColor3f(1,1,1)
#clear both buffers
win.flip()
win.clear()
win.flip()
win.clear()
#precalculate the vertices of a box to draw
box_x1=win.width/2-win.width/4
box_y1=win.height/2-win.height/4
box_x2=win.width/2+win.width/4
box_y2=win.height/2+win.height/4
reps = 100 #specify the number of times to run the test
on_delay_in_refreshes = 1 #specify the delay between test start and
box on
off_delay_in_refreshes = 1 #specify the delay between box on and box
off
#good values: 1.0,1.0 -> both dead-on (as expected)
#good values: 0.5,0.5 -> onset off by half a refresh, offset off by a
whole refresh (as expected)
#good values: 0.5,1.5 -> onset off by half a refresh, offset is dead-
on (as expected)
#bad values: 1.5,1.5 -> both dead-on (not expected)
observed_on_error = [] #initialize a collector for box on timing error
observed_off_error = [] #initialize a collector for box off timing
error
for rep in range(reps):
win.clear()
win.flip() #flip first so that the trial is synced with the refresh
rate
start=time.time() #record the time of trial start
win.clear()
pyglet.gl.glRectf(box_x1,box_y1,box_x2,box_y2) #buffer the box
box_on=False
done=False
expected_on_time = start+on_delay_in_refreshes/float(my_refresh) #pre-
calculate the box on time
expected_off_time = expected_on_time+off_delay_in_refreshes/float
(my_refresh) #pre=calculate the box off time
while not done:
if not box_on: #if the box hasn't been drawn
if time.time()>=expected_on_time: #if it's time to draw
the box
win.flip() #show the buffered box
observed_on_error.append(time.time()-expected_on_time) #record the
on time error
box_on=True
win.clear() #buffer a blank screen
else: #if the box has been drawn
if time.time()>=expected_off_time: #if it's time to
turn off the
box
win.flip() #show the buffered blank screen
observed_off_error.append(time.time()-expected_off_time) #record
the off time error
done=True
#show statistics
print 'On Mean: '+str((sum(observed_on_error)/float(reps)*1000))+'
milliseconds'
print 'On Min: '+str((min(observed_on_error)*1000))+' milliseconds'
print 'On Max: '+str((max(observed_on_error)*1000))+' milliseconds'
print 'Off Mean: '+str((sum(observed_off_error)/float(reps)*1000))+'
milliseconds'
print 'Off Min: '+str((min(observed_off_error)*1000))+' milliseconds'
print 'Off Max: '+str((max(observed_off_error)*1000))+' milliseconds'
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---