如何创建连续的visual.Windowbackground/wrapping背景?
How to create a continuous visual.Window background/wrapping of background?
例如,在我的例子中,从 ElementArrayStim 派生的一组随机点分布在刺激 window 上,该簇以 (0,0) 为中心,在 x=5 处移动。最终,这些点中的每一个都将击中 window 的右边界。如何使这些点在平滑过渡中重新出现在左侧 window 边界?
策略是查看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()
例如,在我的例子中,从 ElementArrayStim 派生的一组随机点分布在刺激 window 上,该簇以 (0,0) 为中心,在 x=5 处移动。最终,这些点中的每一个都将击中 window 的右边界。如何使这些点在平滑过渡中重新出现在左侧 window 边界?
策略是查看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()