2016-05-31 27 views
0

我在psychopy中工作,我想在几帧的过程中从一个位置到另一个位置有一个文本刺激幻灯片。我已经在文本刺激的位置部分尝试了[frameN,0],但我不确定如何设置终点(时间/帧和位置)。感谢您提前给予帮助!心理移动textstim与终点

回答

1

首先计算每个帧的步长。这只是结束和开始坐标之间的差异除以帧数。 numpy阵列就派上用场了,虽然在这里你能做到这一点的基础蟒蛇,以及:

import numpy as np 
start_pos = np.array([-0.5, 0]) # [x, y] norm units in this case where TextSTim inherits 'units' from the Window, which has 'norm' as default. 
end_pos = np.array([0.5, 0.5]) 
animation_duration = 30 # duration in number of frames 
step_pos = (end_pos - start_pos)/animation_duration 

然后把它用:

# Set up psychopy stuff 
from psychopy import visual 
win = visual.Window() 
text = visual.TextStim(win, text='Watch me slide!') 

# Animate 
text.pos = start_pos 
for i in range(animation_duration): 
    text.pos += step_pos # add to existing value. This is shorthand for writing: text_pos = text.pos + step_pos 
    text.draw() 
    win.flip()