Vizard 7 » Tutorials & Examples » Example scripts » Interaction » Measuring reaction time
7.7

Measuring reaction time

\examples\input\tutorial_reactionTime.py

This script uses precisely timed input recording to measure your reaction time. Press

any key when the color changes to green.

"""
This script uses precisely timed input recording to measure your reaction time.
Press any key when the color changes to green.
Can you get under .2 seconds?
"""
import viz
viz.go()

import vizinfo
vizinfo.InfoPanel()

#Add quad to screen
quad = viz.addTexQuad( viz.SCREEN , pos=(0.5,0.5,0) , scale=(4,4,4) )

#Display time on screen
timeDisplay = viz.addText( 'Time:', viz.SCREEN , pos=(0.1,0.2,0) )

import viztask

def TestReactionTime():

    while True:

        #Set quad to red color
        quad.color(viz.RED)

        #Wait random amount of time
        yield viztask.waitTime( vizmat.GetRandom(1.5,2.5) )

        #Set quad color to green
        quad.color(viz.GREEN)

        #Wait for next frame to be drawn to screen
        d = yield viztask.waitDraw()

        #Save display time
        displayTime = d.time

        #Wait for keyboard reaction
        d = yield viztask.waitKeyDown(None)

        #Calculate reaction time
        reactionTime = d.time - displayTime

        #Print and display time
        print('Reaction time:',reactionTime)
        timeDisplay.message( 'Time: %.5f' % (reactionTime) )

viztask.schedule( TestReactionTime() )