'PsychoPy: can I slow down a dynamic stimuli that refreshes every frame?

I made a simple random walk as a stimulus to elicit smooth pursuit eye movements. However, the stimulus now refreshes at my screen refresh rate and is thus hard to trace with the eye. Is there any way I can manipulate t so that it skips frames or in other words, slows down?

Below is the code that I used within PsychoPy builder:

for i in range(100):
            step = random.choice(['n','s','e','w'])
            if (step == 'n') & (y < 0.5):
                y = y + 0.01
            elif (step == 'n') & (y > 0.5):
                y = y - 0.01
            elif (step == 's') & (y > -0.5):
                y = y - 0.01
            elif (step == 's') & (y < -0.5):
                y = y + 0.1
            elif (step == 'e') & (x < 0.75):
                x = x + 0.01
            elif (step == 'e') & (x > 0.75):
                x = x - 0.01
            elif (step == 'w') & (x > -0.75):
                x = x - 0.01
            else:
                x = x + 0.01
                
polygon.pos = (x,y)

Thanks for the help!



Solution 1:[1]

For code placed in the "Each frame" tab, you can crudely throttle the drawing speed by not updating on every frame, but on some proportion of frames. Builder maintains a variable called frameN, which increments from 0 at the start of each routine. So to update at, say 6 Hz rather than 60 Hz, you would just check whether the current frame number is a multiple of 10:

if frameN % 10 == 0: # only change position on every 10th frame
    step = random.choice(['n','s','e','w'])
    if (step == 'n') & (y < 0.5):
        y = y + 0.01
    # etc
    polygon.pos = (x,y)

But regardless of programming, isn't a randomly and discretely-stepping target a terrible stimulus to elicit smooth pursuit, which is inherently a continuous predictive process? There's a reason why decades of smooth pursuit research has used either linear ramps or smoothly varying sinusoidal functions. This can include the superposition of waves of differing frequencies and amplitudes, to give the continuous equivalent of a seemingly randomly varying target motion.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael MacAskill