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 ...
随机推荐
- 使用docker19.03.6部署zabbix
可参考官方文档:https://www.zabbix.com/documentation/4.0/zh/manual/installation/containers 1)启动一个空的mysql服务器实 ...
- 申请Let’s Encrypt通配符HTTPS证书(certbot ACME v2版)
1.获取certbot-auto# 下载 # 下载 wget https://dl.eff.org/certbot-auto # 设为可执行权限 chmod a+x certbot-auto 2.开始 ...
- 《Head first设计模式》学习笔记
1. 单例模式 2. 工厂模式 3. 抽象工厂 4. 策略模式 5. 观察者模式 6. 装饰者模式 7. 命令模式 8. 适配器模式 9. 外观模式 10. 模版方法模式 11. 迭代器模式 设计模式 ...
- 来看看你对Python变量理解到位了没有
变量是编程的基础概念,Python 的变量也看似很简单,但是如果理解不当,生搬硬套,可能会遇到一些麻烦. 下面用 10 个代码示例展示 Python 的 变量 本质. 以下内容有对应的 视频 手把手详 ...
- 20200220--python学习第13天
今日内容 作业题(21题) 推导式 装饰器 模块[可选] 内容回顾 1.函数 a.参数 def func(a1,a2):pass def func(a1,a2=None):pass 默认参数推荐使用不 ...
- windows服务器 IIS FTP服务
一.安装ftp,如果服务器没有,去windows组件里面装一下. 安装IIS,安装FTP(版本不同,选项不相同,这两项必选) 二.装完之后在IIS管理中心创建FTP站点 创建类型 ftp站点: ...
- 大数四则运算之减法运算-----c语言版
/* 分三种情况: 1.减数长度大于被减数 交换减数与被减数,输出负号,方便减 2.减数长度等于被减数(分三种情况) a.减数大于被减数,类似1情况1 b.减数等于被减数,两数相等,直接输出0,完成. ...
- linux学习--1. 文件系统
文件目录结构 闲话篇: linux我也是最近才开始学,写随笔是为分享学习经验的同时也留着供自己以后来参考.因为linux一切皆文件的基本哲学思想.所以我决定从文件目录开始写. 正文: 首先linux文 ...
- Python 钩子函数详解
###### 钩子函数 ``` import pluggy hookspec = pluggy.HookspecMarker('aaa') hookimpl = pluggy.HookimplMark ...
- MongoDB导入导出以及数据库备份111
-------------------MongoDB数据导入与导出------------------- 用命令行打开mongo安装路径如图: 执行后, 在此处输入命令,如:mongoexport ...