加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

the simmon effect(in psychology) :build the function of subj

发布时间:2020-12-15 07:35:34 所属栏目:Java 来源:网络整理
导读:# the real experiment for simon effect # load the library which is our need import pygame import sys import random from pygame.locals import * # creat the subject information function def sub_info(): sub_ID = input( " please input your num
#the real experiment for simon effect
#load the library which is our need
import pygame
import sys
import random
from pygame.locals import *


#creat the subject information function
def sub_info():
    sub_ID = input("please input your number: ")
    sub_name = input("please input your name: ")
    sub_male = input("please input your male: ")
    sub_age = input("please input your age: ")
    return sub_ID,sub_name,sub_male,sub_age
#the variable result will be a tuple 
result = sub_info()
#turn the tuple to a list
result = list(result)

pygame.init()
win = pygame.display.set_mode((800,600),DOUBLEBUF|HWSURFACE)
left = (200,300)
right = (600,300)
red  =(255,0)
blue = (0,255)
black = (0,0)

#wait for the pressed key

def wait4key(duration,key_list):
    """the function is to wait for subject to press the right key,and the experient will continue untill thesubject press the key
duration : the time which is the subject wait to press the key,if the time is too long,the experiment willcontinue automaticly.
key_list: the key which the subject need to press to continue the experiment,and the key_list must be a list such as [K_A,K_/]"""
    
    fake_bool =False
    time_out = False

    #empty the event before 
    pygame.event.clear()
    
    #use for count the time
    start_time = pygame.time.get_ticks()
    
    #if the subject does not press the right key,he will in the while loop all the time untill the duration is exhausted
    while  not (fake_bool or time_out):
        end_time = pygame.time.get_ticks()
        #if the duration is too long,the experiment will continue
        if end_time - start_time > duration:
            time_out = True
        #if subject press the right key,the experimet will continue
        for i in pygame.event.get():
            if i.type ==KEYDOWN:
                if i.key in key_list:
                    #prepare for the result of the function
                    response_time = pygame.time.get_ticks()
                    key_name = pygame.key.name(i.key)
                    #if has the right key,the loop will quit
                    fake_bool = True
    #in the end,if subject press the key,we will collect the time,and the name of the key
    if fake_bool:
        return start_time,response_time,key_name
    #the purpose of the next line is stay the same with the result
    else:
        return start_time,None,None
        
#experiment for 10 times

#creat the list
#L mean left,R mean right,RE mean the color red,BL mean the color blue
lis = [ ["L","RE","Z"],["L","BL","/"],["R","/"]]

#creat a function to ran one trial
def one_trial_list(pars):
#the parameters must be a list which contains the location,color,right response of the stimuli and the the sequence of the element of parameters should not change"""
    global left
    global right
    global red
    global blue
    global black
    loc,col,ress=pars
    if loc =="L":
        pos = left
    if loc =="R":
        pos = right
    if col =="BL":
        color = red
    if col == "RE":
        color = blue

    win.fill(black)
    pygame.draw.circle(win,pos,20,0)
    pygame.display.flip()
    result1 = wait4key(2000,[K_z,K_SLASH])
    #turn the result1 which is the result of the wait4key function to a list 
    result1 = list(result1)
    print(result + result1)


#random our lis which contains four trails
lis1 = lis*2
random.shuffle(lis1)

#run four trials
for i in lis1:
    one_trial_list(i)
    
    #when one trail end,fill the window black again
    win.fill(black)
    pygame.display.flip()
    pygame.time.delay(500)
pygame.quit()
sys.exit()
 

the function sub_info is the function which is added based on the last experiment programme

the result is

?

?we also change the print result

?

what we need to pay attention is that:

we turn the result such as result1,result to a list and then compile them to a single list,then print it

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读