#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. [教程分享]锐族MP3刷固件教程

    转载自我的博客:https://blog.ljyngup.com/archives/163.html/ (废话较多见谅) 在到学校前发现几个月前锐族mp3的固件更新了,赶紧刷了一个,发现网上关于这个售 ...

  2. [Effective Java 读书笔记] 第三章类和接口 第十八--十九条

    十八条 接口优于抽象类 接口的特点: 1.一个类可以实现多个接口,不能继承多个类(抽象类) 2.接口不能有具体的方法实现,只定义标准类型 骨架类: 即实现一个abstract类来实现接口,提供给其他类 ...

  3. Python3(五) 包、模块、函数与变量作用域

    一.Python项目的组织结构 最顶级的组织结构:包(文件夹) 第二个层级:模块(文件) 第三个层级:类 第四个层级:函数.变量(不属于组织结构,是类本身的特性) 二.Python包与模块的名字 1. ...

  4. JMeter接口测试-提取动态列表最后一个值的两种方法

    前言 在用JMeter做接口测试时,我们经常会遇到,一个接口返回一个json串,在这个json串中,某个节点的值是一个列表,而且这个列表的长度是动态变化的.今天我们来学习两种提取动态列表最后一个值的两 ...

  5. 《自拍教程24》在Windows上配置环境变量

    我们说的环境变量,一般是指的是Path环境变量. 第一步:点击"我的电脑",右键,"属性" 第二步:点击"高级系统设置",弹出的窗口选&qu ...

  6. Node.js的__dirname,__filename,process.cwd(),./的一些坑

    参考博客:https://github.com/jawil/blog/issues/18

  7. ClientAbortException :客户端异常终止

    ClientAbortException :客户端异常终止 java.io.IOException: 你的主机中的软件中止了一个已建立的连接. 罪魁祸首: <img src="chec ...

  8. Executor 任务执行器

    Executor: 是一个接口 用于执行提交的任务 解耦任务提交和执行(线程的创建及调度) Executor的实现可以根据实际需求延展不同的逻辑:1. 对于提交的任务同步或者异步执行,如下同步执行: ...

  9. printf函数中*修饰符的作用,如:%*d

    在printf函数中,我们可以用数字修饰来控制打印的字段宽度和精度,如下(为强调视觉效果,均填充0): #include <stdio.h> int main() { ; float f= ...

  10. Spring Boot自动配置如何工作

    通过使用Mongo和MySQL DB实现的示例,深入了解Spring Boot的@Conditional注释世界. 在我以前的文章“为什么选择Spring Boot?”中,我们讨论了如何创建Sprin ...