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 sys,random
from pygame.locals import * 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
for i in range(10):
r1 = random.choice([0,1])
if r1 == 0:
pos = left
else:
pos = right r2 = random.choice([0,1])
if r2 == 0:
color = red
else:
color = blue win.fill(black)
pygame.draw.circle(win,color,pos,20,0)
pygame.display.flip()
result = wait4key(2000,[K_z,K_SLASH])
print(result)
#when subject press the key , we will black the window for 0.5 seconds until next stimuli appears
win.fill(black)
pygame.display.flip()
pygame.time.delay(500)

the result include the stilmuli start time ,the suject response time , and the key subject pressed

simon effect (psychology experiment ) : build the function of wait4key()的更多相关文章
- 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 ...
- the simmon effect(in psychology) :build the function of subject_information(modify the experiment programme),before we begin the experiment
#the real experiment for simon effect #load the library which is our need import pygame import sys i ...
- 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 ...
- 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 ...
- 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 ...
- fn project 打包Function
Option 1 (recommended): Use the fn cli tool We recommend using the fn cli tool which will handle a ...
- cvpr2015papers
@http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...
- jquery-jsrender使用
JsRender是一款基于jQuery的JavaScript模版引擎 特点: · 简单直观 · 功能强大 · 可扩展的 · 快如闪电 jsrender使用比较简单,本文简单结束一些常用的 使用过程 ...
- [转载] google mock cookbook
原文: https://code.google.com/p/googlemock/wiki/CookBook Creating Mock Classes Mocking Private or Prot ...
随机推荐
- Go语言实现:【剑指offer】二叉树中和为某一值的路径
该题目来源于牛客网<剑指offer>专题. 输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路 ...
- [Redis-CentOS7]Redis安装(-)
系统环境 CentOS Linux release 7.7.1908 (Core) yum安装 yum install redis Loaded plugins: fastestmirror Load ...
- Windows2008R2搭建共享存储服务器
说明: 为了方便公司个部门软件.项目.文档等资料的归档和保存,实现公司内部资料共享及重要资料备份,防止因个人计算机系统故障或硬件故障导致数据丢失而造成数据无法恢复的损失,特建立共享服务器 1.在共享服 ...
- 前端之gojs插件的基本使用
gojs是一个前端插件,可以通过代码动态的生成流程图,各自展示图 参考网址:https://gojs.net/latest/index.html 如果你想使用,需要先下载对应的文件 我们能用的到的其实 ...
- Linux监控-历史细项数据回溯
Linux监控数据回溯 网络服务监控 应用场景: lvs 后端内网端机器网络波动监控: nginx 80.443端口连接监控: mysql 连接监控 以上为抛砖引玉,根据环境安装到监控工具(open ...
- MySQL之ERROR 1558 (HY000): Column count of mysql.user is wrong.解决方案
一.场景 我本想在MySQL5.7上执行下列语句创建一个新用户: CREATE USER "remote"@"%" IDENTIFIED BY "12 ...
- Ansible学习笔记(一):部署管理Windows机器遇到的一些坑
在给国盛通上海测试环境做Ansible管理Windows服务器的时候,遇到了一些坑,Google解决掉了,特此记录,坑用红色标记. 一.环境说明 1.Ansible管理主机 操作系统:CentOS 7 ...
- vue router引入路由与路由配置容易犯错的地方与常见的报错与处理报错
首先npm安装vue-router插件,就不说了其次: 先看下我本地的目录结构吧 第一步:在src目录下新建一个专门存放router的index.js文件里面的内容为: import Vue from ...
- SpringBoot支持SpringData es
ElasticSearch CRUD 1.springboot springData es spring data 是spring对数据访问抽象.这些数据可以放入db,index,nosql等包含以下 ...
- Java基础之一、入门知识
资料来源于<明解 Java>日本作者 写的很详细 1:命令---java 类名 该命令不是去执行类名.class文件(文件名和类名有可能不一致),切记是表示执行具体的类: 2:“字符”+数 ...