不靠譜PsychoPy入門教程目錄:
幫師妹做的程序筐乳,雖然最后沒有采用叨恨∮嗬瑁可能用這個(gè)做動(dòng)畫還是有點(diǎn)兒吃力溜嗜,在我的電腦上可以妥妥的跑起來艇棕,放師妹的電腦上就各種卡 o(╯□╰)o
不管啦。實(shí)驗(yàn)要求是:
- 在屏幕上某個(gè)范圍內(nèi)搞出n個(gè)白色的小圓巩检,其中四個(gè)是追蹤目標(biāo)元咙。小圓出現(xiàn)的位置是隨機(jī)的。
- 靜止呈現(xiàn)一秒鐘湃密。4個(gè)追蹤目標(biāo)上有小紅點(diǎn)兒做提示诅挑。
- 然后這些球就開始動(dòng)了。運(yùn)動(dòng)方向是隨機(jī)的泛源,每隔一秒轉(zhuǎn)換一次方向拔妥。
程序?qū)懲曛筮\(yùn)行起來是這樣的:
被試的任務(wù)就是盯著那幾個(gè)追蹤目標(biāo),然后在運(yùn)動(dòng)結(jié)束之后达箍,選出四個(gè)目標(biāo)來没龙。選擇部分就要用到一下鼠標(biāo)。還有設(shè)置什么誘導(dǎo)刺激幻梯,就是在運(yùn)動(dòng)過程中兜畸,某個(gè)小圓會(huì)搞小動(dòng)作,看被試能不能注意到碘梢。有興趣的同學(xué)可以試試玩兒咬摇。
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]
#-----靜止呈現(xiàn)
def present(items,s):
while timer.getTime()<s:
boundary.draw()
for i in range(len(items)):
items[i].draw()
win.flip()
def static_present(items):
timer.reset()
present(items,1) #最初呈現(xiàn)時(shí)間,1s煞躬。
for i in range(4): #【追蹤目標(biāo)】四個(gè)肛鹏。
items[i].fillColor = 'red'
present(items,2) #顯示目標(biāo)逸邦,2s。
for i in range(len(items)):
items[i].fillColor = 'white'
#-----運(yùn)動(dòng)
def movement(items,time):
event.clearEvents()
moveAngle = [random.uniform(0,2*math.pi) for i in range(len(items))]
x,y = win.size
timer.reset()
timer_2 = core.Clock()
timer_2.reset()
while timer.getTime()<time:
timeUse = timer_2.getTime()
timer_2.reset()
boundary.draw()
for i in range(len(items)):
a,b = items[i].pos
if not int(abs(a)) < (y/3+yuan0.radius) : #邊緣碰撞
moveAngle[i]=2*math.pi-moveAngle[i]
if not int(abs(b)) < (y/3+yuan0.radius) :
moveAngle[i]=math.pi-moveAngle[i]
for j in range(i+1,len(items)): #小球碰撞
h,k= items[i].pos - items[j].pos
if math.sqrt(h**2+k**2)<=(yuan0.radius*4) : #如果相遇在扰,交換運(yùn)動(dòng)方向缕减。
moveAngle[i],moveAngle[j] = moveAngle[j],moveAngle[i]
items[i].pos+=[math.sin(moveAngle[i])*timeUse*100, math.cos(moveAngle[i])*timeUse*100] #運(yùn)動(dòng)速度
for i in range(len(items)):
induce_point.draw()
induce_point_non.draw()
items[i].draw()
win.flip()
items,start_pos=item_select(12)
static_present(items)
for j in range(6):
movement(items, 1) #每次1s
有什么疑問或者建議可以評(píng)論給我哦。不保證能解決哦芒珠。