#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,0)
blue = (0,0,255)
black = (0,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 the\
subject press the key
duration : the time which is the subject wait to press the key ,if the time is too long ,the experiment will\
continue 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","RE","Z"],
["R","BL","/"]] #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,color,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

the simmon effect(in psychology) :build the function of subject_information(modify the experiment programme),before we begin the experiment的更多相关文章

  1. The `android.dexOptions.incremental` property is deprecated and it has no effect on the build process.

    编译报错:The android.dexOptions.incremental property is deprecated and it has no effect on the build pro ...

  2. simon effect (psychology experiment ) : build the function of wait4key()

    ## #the real experiment for simon effect #load the library which is our need import pygame import sy ...

  3. simmon effect(psychology experiment) : this time, we add file_function who can creat a file in the window which contains our result

    #the real experiment for simon effect #load the library which is our need import pygame import sys i ...

  4. simmon effect : build the funcion of trail list

    #the real experiment for simon effect #load the library which is our need import pygame import sys i ...

  5. Android Studio升级到3.1.4后打开旧项目警告:The `android.dexOptions.incremental` property is deprecated and it has no effect on the build process.

    现象截图 问题原因&解决方案 在build.gralde中,对Android开发过程中突破的方法数的限制,做了如下解决配置: dexOptions { incremental true jav ...

  6. fn project 打包Function

      Option 1 (recommended): Use the fn cli tool We recommend using the fn cli tool which will handle a ...

  7. PostgreSQL function examples

    warehouse_db=# CREATE TABLE warehouse_tbl(warehouse_id INTEGER NOT NULL,warehouse_name TEXT NOT NULL ...

  8. Mysql ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA

    ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declar ...

  9. verilog中的function用法与例子

    函数的功能和任务的功能类似,但二者还存在很大的不同.在 Verilog HDL 语法中也存在函数的定义和调用. 1.函数的定义 函数通过关键词 function 和 endfunction 定义,不允 ...

随机推荐

  1. 3、实战:OutOfMemoryError异常

    目的:第一,通过代码验证Java虚拟机规范中描述的各个运行时区域存储的内容:第二,工作中遇到实际的内存溢出异常时,能根据异常的信息快速判断是哪个区域的内存溢出,知道什么样的代码可能会导致这些区域内存溢 ...

  2. 使用递归函数用来输出n个元素的所有子集(数据结构、算法与应用)

    例如,三个元素的集合A = {a,b,c}的所有子集是:空集a,b,c,ab,ac,bc,abc,共八个 分析: 对于集合A中的每个元素,在其子集中都可能存在或者不存在,所以A的子集有23种. 可以设 ...

  3. 基于MySQL+MHA+Haproxy部署高可用负载均衡集群

    一.MHA 概述 MHA(Master High Availability)是可以在MySQL上使用的一套高可用方案.所编写的语言为Perl 从名字上我们可以看到.MHA的目的就是为了维护Master ...

  4. MySQL读写分离---Mycat

    一.什么是读写分离 在数据库集群架构中,让主库负责处理事务性查询,而从库只负责处理select查询,让两者分工明确达到提高数据库整体读写性能.当然,主数据库另外一个功能就是负责将事务性查询导致的数据变 ...

  5. spring cloud微服务快速教程之(七) Spring Cloud Alibaba--nacos(一)、服务注册发现

    0.前言 什么是Spring Cloud Alibaba? Spring Cloud Alibaba 是阿里开源的,致力于提供微服务开发的一站式解决方案.此项目包含开发分布式应用微服务的必需组件,方便 ...

  6. vue的组件传值

    1.父组件向子组件传值 父组件: 123456789101112 <template> <child :name="name"></child> ...

  7. MongoDB入门(介绍、安装)

    一.什么是MongoDB? MongoDB is a document database with the scalability and flexibility that you want with ...

  8. tomcat 访问权限设置

    1.全局设置,设置允许某些IP能够访问到tomcat服务器,或不能访问tomcat服务器 只需要编辑tomcat的server.xml,增加适当代码即可. 修改如下:在<Host>  &l ...

  9. [Redis-CentOS7]Redis字符串操作(二)

    登录Redis # redis-cli 127.0.0.1:6379> 添加字符串 EX 超期时间60s 127.0.0.1:6379> set username 'leoshi' OK ...

  10. 杭电-------2053Switch Game(C语言)

    /* 题目大意是指:有n个灯泡,按1-n编号,要操作n次,第i次操作是将标号是i的倍数的变成相反状态.最终求得是n次操作后,编号为n的灯泡的状态,其实就是求n的约束有多少个,及灯泡n被操作了多少次*/ ...