Lasta
Lasta

Reputation: 71

Manipulate presented timer in a psychopy experiment

In the experiment, participants see an elapsed time display in the top right of the screen. My goal is to manipulate this display over different conditions. In detail, in one condition, the elapsed timer should go by 1.2-time as fast, in another condition, only 0.8-time as fast as the real time. Of course, the timer should still display only full numbers (1,2,3 etc) without decimals. Whats a simple way to implement this?

I've tried adding or multiplying the timer with a constant, but this leads to a lot of decimals. If I were to round these numbers up or down, the timer would not be exact anymore, as each increase in the timer wouldn't necessarily equal to e.g. 1,2 seconds.

Upvotes: 1

Views: 472

Answers (1)

Michael MacAskill
Michael MacAskill

Reputation: 2421

Create two PsychoPy text stimuli and a PsychoPy timer. In a loop, update the text stimuli with the current time value from the Clock object. This is just a time in seconds, starting from 0, so you can just multiply it by a constant to get the desired time dilation. e.g.

from psychopy import visual, event, core

win = visual.Window(units='height')
normal_text = visual.TextStim(win=win, pos=(0, 0.1))
faster_text = visual.TextStim(win=win, pos=(0, -0.1))

timer = core.Clock() # starts here at 0. Can be reset to 0 if needed.

# run until a key press:
while not event.getKeys():
    # update the time value:
    current_time = timer.getTime()

    normal_text.text = round(timer.getTime(), ndigits=1)
    faster_text.text = round(timer.getTime() * 1.2, ndigits=1)

    # display them on screen:
    normal_text.draw()
    faster_text.draw()
    win.flip()

You should see that when one text stimulus displays 12.0, the other is still on 10.0.

Re your issues with rounding, note that you can tell the rounding function to round to a specific number of decimal places, as above, but also you should do the multiplication before the rounding, or else the number of digits will indeed grow again.

Upvotes: 1

Related Questions