【问题标题】:How to create a continuous visual.Window background/wrapping of background?如何创建连续的visual.Window背景/背景包装?
【发布时间】:2015-12-04 07:07:21
【问题描述】:

例如,在我的例子中,从 ElementArrayStim 派生的一组随机点分布在整个刺激窗口中,以 (0,0) 为中心的簇在 x=5 处移动。最终,这些点中的每一个都会碰到窗口的右边界。如何让这些点在平滑过渡中重新出现在左侧窗口边界上?

【问题讨论】:

    标签: python psychopy


    【解决方案1】:

    策略是查看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()
    

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2015-05-06
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多