增加精神变态中的顶点以创建进度b

2024-05-23 14:36:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试为功能磁共振成像任务创建一个进度条,这样当参与者回答正确时,进度条会根据剩余的试验量/问题呈指数级上移。 我已经想出了如何使条上移到一个指定的值(如下所示),但我似乎不能让它移动到每一个正确的问题,比方说10%。。在

我把进度条函数放在例程的“每个帧”代码组件中。在

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] ]

基本上,我想找出一种方法,让预测者[1]和预测者[2]在每个正确答案的基础上增加他们的y轴。。在


Tags: 进度条功能nonetrueifcounterrgb参与者
1条回答
网友
1楼 · 发布于 2024-05-23 14:36:41

这里有一个解决方案。请阅读下面代码中的注释,以了解为什么我在这里和那里更改了一些内容。我已经回答了你的问题,好像这是一个纯粹的代码问题。但是,看起来您可能正在使用构建器代码组件,因此下面有一个构建器版本。在

编码器版本

# 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方法更容易创建和操作矩形,这是一个足够频繁的用例来保证它的存在。在

生成器版本

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

^{pr2}$

相关问题 更多 >