There are various ways to animate random dot patterns, varying in how long each dot lives and the behaviour of the incoherent dots. This implementation uses a pattern where dots never die and all dots move with a constant speed. The coherent dots differ only in having a consistent direction. (Other versions are easy to implement too).

from psychopy import *
#create a window to draw in
myWin =visual.Window((600,600), allowGUI=True,
    bitsMode=None, units='norm')

#INITIALISE SOME STIMULI
dotPatch =visual.DotStim(myWin, rgb=(1.0,1.0,1.0),
    fieldPos=(0.0,0.0), nDots=200, fieldSize=(0.5,0.5),
    speed=0.01, coherence=0.5)
message =visual.TextStim(myWin,text='Hit Q to quit',
    pos=(0,-0.5))

trialClock =core.Clock()
while True:#quits after 20 secs
    dotPatch.draw()
    message.draw()
    myWin.flip()#redraw the buffer

    #handle key presses each frame
    for key in event.getKeys():
        if key in ['escape','q']:
            core.quit()
    event.clearEvents()#keep the event buffer from overflowing
 
Valid XHTML 1.0! Valid CSS!