例如,在我的例子中,从ElementArrayStim派生的一组随机点在刺激窗口上传播,群集以(0,0)为中心移动,在x = 5处移动。最终,这些点中的每一个都将击中窗口的右边界。如何使这些点在平滑过渡中重新出现在左窗口边界?
答案 0 :(得分:0)
策略是研究psychopy.visual.ElementArrayStim.xys
,它是所有N个元素当前坐标的Nx2 numpy.array
。您可以获得x坐标超过某个值的N个指标,并且对于这些指标,将x坐标更改为另一个值。在您的情况下,您可以围绕y轴翻转它。
所以:
# Set up stimuli
from psychopy import visual
win = visual.Window(units='norm')
stim = visual.ElementArrayStim(win, sizes=0.05)
BORDER_RIGHT = 1 # for 'norm' units, this is the coordinate of the right border
# Animation
for frame in range(360):
# Determine location of elements on next frame
stim.xys += (0.01, 0) # move all to the right
exceeded = stim.xys[:,0] > BORDER_RIGHT # index of elements whose x-value exceeds the border
stim.xys[exceeded] *= (-1, 1) # for these indicies, mirror the x-coordinate but keep the y-coordinate
# Show it
stim.draw()
win.flip()