Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple timers in Python (Pygame)
    primarykey
    data
    text
    <p>I'm an amateur programmer. I am trying to write a simple program that will measure the reaction time for a series of visual stimuli (flashes of squares) that will be used for a biology experiment. Here's my code (beware, first time coding a graphical interface):</p> <pre><code>stimulus = pygame.Rect(100,250,100,100) #draw on surface object time.sleep(2) #wait for 2 seconds before it appears screen.fill(BLACK) pygame.draw.rect(screen,WHITE,stimulus) pygame.display.update(stimulus) #record time stimulus appeared t0 = time.clock() #clear screen ("flash" illusion) time.sleep(0.5) #***PROBLEM*** screen.fill(BLACK) pygame.display.update(stimulus) while True: for event in pygame.event.get(): if event.type == KEYDOWN: t1 = time.clock() print t1-t0 if event.type == QUIT: pygame.quit() sys.exit() </code></pre> <p>The program was working fine before I included the block with the line marked "problem". The reaction time printed seemed reasonable. However, I want the square to disappear after a while, as though it just "flashed". After including the time.sleep(0.5), the time printed is no longer correct. It is always 0.5xxxx or greater, no matter how fast I press. Is there any workaround?</p> <p>P.S. I need it to disappear because I want to present a sequence of flashes with predetermined (not constant) pauses in between.</p> <p>Thanks.</p> <p><strong>Edit</strong></p> <p>I need to achieve two things: 1. The shape must flash on the screen for 0.5 sec. 2. The program must create a timestamp (e.g. write to a list) every time the spacebar is pressed (even if it is pressed randomly twice between two flashes).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload