增加 psychopy 中的顶点以创建进度条

Increasing vertices in psychopy to create progress bar

我正在尝试为 fMRI 任务创建一个进度条,以便当参与者回答正确时,进度条会根据剩余的试验 amount/questions 呈指数上升。 我已经想出如何使条形图仅向上移动到指定值(如下所示),但我似乎无法让它将每个正确的问题向上移动 10%..

我把进度条功能放在例程的'each frame'代码组件中。

progverts = [ [0,-0.8], [0,-0.7], [0.2,-0.7] ,[0.2,-0.8] ]

counter = 0

progTest = visual.ShapeStim(win, units='', lineWidth=1.5, lineColor='red', lineColorSpace='rgb', 
   fillColor='yellow', fillColorSpace='rgb', vertices=progverts, 
   closeShape=True, pos=(0, 0), size=1, ori=0.0, opacity=1.0,
   contrast=1.0, depth=0, interpolate=True, name=None, autoLog=None, autoDraw = False)

def progressbar ():
   global counter 
   global progverts 

   progTest.setAutoDraw(True)
   win.flip()
   core.wait(.5)

   if trials.thisN == 0: 
       if ParticipantKeys.corr  == 1:
           progTest.vertices = [ [0,-0.8], [0,-0.65], [0.2,-0.65] ,[0.2,-0.8] ]

本质上,我试图找出一种方法让 progverts[1] 和 progverts[2] 在每个正确答案时增加它们的 y 轴..

这是一个解决方案。阅读下面代码中的注释,了解为什么我在这里和那里更改了一些东西。我已经回答了你的问题,就好像这是一个纯代码问题一样。但是,您似乎正在使用 Builder 代码组件,因此下面有一个 Builder 版本。

编码器版本

# Some parameters.
RISE_SPEED = 0.02  # how much to increase height in each frame. (here 2% increase every frame)
RISE_END = 1.0  # end animation at this unit height

# Set up the window and bar. 
from psychopy import visual
win = visual.Window()
progTest = visual.Rect(win, width=0.2, height=0.1, pos=(0, -0.75), 
                       lineColor='red', fillColor='yellow')  # no need to set all the default parameters. Just change the ones you need

# While the height is less than RISE_END.
while progTest.height < RISE_END:
    # Increase the height (y-length in both directions) and then move up on Y so that the base stays put.
    progTest.height *= 1 + RISE_SPEED
    progTest.pos[1] += progTest.height*RISE_SPEED/2  # the y-position only

    # Show it. 
    progTest.draw()
    win.flip()

请注意,由于您只是使用矩形条,因此 visual.Rect 很方便,因为它有一个 height 参数。在幕后,visual.Rect 只是一个 visual.ShapeStim,但是 Rect 方法更容易创建和操作矩形,这是一个足够频繁的用例以保证它的存在。

生成器版本

只需将它放在代码组件的“运行 每帧”部分,并确保在使用 Builder 创建的同一例程中具有progTest

RISE_SPEED = 0.02  # how much to increase height in each frame. (here 2% increase every frame)
RISE_END = 1.0  # end animation at this unit height
progTest.height *= 1 + RISE_SPEED
progTest.pos[1] += progTest.height*RISE_SPEED/2  # the y-position only