首页 > 解决方案 > 在 PsychoPy 中生成一个精确定时的扩张圈

问题描述

使用 PsychoPy,我正在尝试编写一个简单的脚本来生成一个扩大的圆圈:

1) 在 250 毫秒内将视角从 2 度扩展到 20 度。

2) 在 20 度再保持 250 毫秒。

3) 重复 n 次,重复之间的刺激间隔为 500 ms(空白,灰屏)。

到目前为止我的 Python 代码:

from psychopy import visual, core, event

# Define the window/background.
win=visual.Window([800,600],monitor="testMonitor",units="deg")

# Setting up some variables: I'm not sure how best to use them:

# Number of epochs (repetitions)
EPOCH=15

# Stimulus initial size
INIT_RAD=2

# Stimulus end size
END_RAD=10

# Duration of expansion
EXPANSION_MS=250

# Hold duration
HOLD_TIME_MS=250

# ISI duration
ISI_MS=500

# Time-to-frame conversion assuming a 60Hz FR and RR
FRAMES=int((60*EXPANSION_MS)/1000)
print(FRAMES)

# Define the stimulus
circle=visual.Circle(win,radius=1,edges=1000,fillColor='black',lineColor='black')

for e in range(EPOCH):
    for f in range(FRAMES):
        while circle.radius<10:
            circle.radius+=1
            circle.draw()
            win.flip()
#        for f in range(FRAMES): # Doesn't seem to work - takes much longer than 250 ms.
#            circle.radius=20
#            circle.draw()
#            win.flip()
    print(circle.radius)
    circle.radius=1

# Get keys to quit.
if len(event.getKeys())>0:
    event.clearEvents()
    win.close()

我对 Python 还是很陌生,如果有人能提供一些建议,我将不胜感激。

标签: python-3.xpsychopy

解决方案


推荐阅读