用PsychoPy做视觉搜索任务实验

不靠谱PsychoPy入门教程目录:

  1. PsychoPy入门00安装

  2. PsychoPy入门01文字和图片的呈现

  3. PsychoPy入门02按键等待&反应时

  4. PsychoPy入门03视频和音频的呈现

  5. PsychoPy入门04等级评定

  6. PsychoPy入门05循环和随机

  7. PsychoPy入门06数据记录

  8. PsychoPy入门07鼠标的使用

  9. 用PsychoPy做视觉搜索任务实验


帮师妹做的程序,虽然最后没有采用。可能用这个做动画还是有点儿吃力,在我的电脑上可以妥妥的跑起来,放师妹的电脑上就各种卡 o(╯□╰)o

不管啦。实验要求是:

  • 在屏幕上某个范围内搞出n个白色的小圆,其中四个是追踪目标。小圆出现的位置是随机的。
  • 静止呈现一秒钟。4个追踪目标上有小红点儿做提示。
  • 然后这些球就开始动了。运动方向是随机的,每隔一秒转换一次方向。

程序写完之后运行起来是这样的:

用PsychoPy做视觉搜索任务实验_第1张图片

被试的任务就是盯着那几个追踪目标,然后在运动结束之后,选出四个目标来。选择部分就要用到一下鼠标。还有设置什么诱导刺激,就是在运动过程中,某个小圆会搞小动作,看被试能不能注意到。有兴趣的同学可以试试玩儿。

gif图的代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from psychopy import visual, core, event,gui
import random, math,time

win = visual.Window(fullscr = False, size = [900,700], color = [-1,-1,-1], units = 'pix')
#win = visual.Window(fullscr = True, size = [1366, 768], color = [-1,-1,-1], units = 'pix')     #全屏模式
x,y = win.size
yuan0 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'target')
yuan1 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'target')
yuan2 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'target')
yuan3 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'target')
yuan4 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
yuan5 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
yuan6 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
yuan7 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
yuan8 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
yuan9 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
yuan10 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
yuan11 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
yuan12 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
yuan13 = visual.Circle(win, radius=7, edges=60, size = [1,1], fillColor='white', name = 'nontarget')
induce_point_non = visual.Circle(win, radius=4, edges=60, size = [1,1], fillColor='black', opacity = 0, name = 'induce_point_non')
induce_point = visual.Circle(win, radius=4, edges=60, size = [1,1], fillColor='black', opacity = 0, name = 'induce_point')

boundary = visual.ShapeStim(win, fillColor=[-0.3,-0.3,-0.3], opacity = 0.5, 
                            vertices=[(y/3+15,y/3+15),(y/3+15,-(y/3+15)),(-(y/3+15),-(y/3+15)),(-(y/3+15),y/3+15)])
timer = core.Clock()

def item_select(num):
    items = [eval('yuan'+str(i)) for i in range(num)]
    x,y = win.size
    start_pos = [(random.uniform(-(y/3-yuan0.radius*5),y/3-yuan0.radius*5),random.uniform(-(y/3-yuan0.radius*5),y/3-yuan0.radius*5)) for i in range(len(items))]
    for i in range(len(items)):
        items[i].pos = start_pos[i]
    t=1
    while t:
        t = 1
        for i in range(len(items)):
            for j in range(i+1,len(items)):
                x,y=items[i].pos
                a,b=items[j].pos
                if math.sqrt((x-a)**2+(y-b)**2)<=yuan0.radius*6:
                    items[j].pos = (random.uniform(-(y/3-yuan0.radius*5),y/3-yuan0.radius*5),random.uniform(-(y/3-yuan0.radius*5),y/3-yuan0.radius*5))
                    t += 1
        if t == 1:
            break
    return [items, start_pos]

#-----静止呈现
def present(items,s):
    while timer.getTime()

完整的程序可以在这儿下载:
链接:http://pan.baidu.com/s/1c2ICTBa 密码: rs74

有什么疑问或者建议可以评论给我哦。不保证能解决哦。

你可能感兴趣的:(用PsychoPy做视觉搜索任务实验)