##
#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()的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. fn project 打包Function

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

  7. cvpr2015papers

    @http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...

  8. jquery-jsrender使用

      JsRender是一款基于jQuery的JavaScript模版引擎 特点: · 简单直观 · 功能强大 · 可扩展的 · 快如闪电 jsrender使用比较简单,本文简单结束一些常用的 使用过程 ...

  9. [转载] google mock cookbook

    原文: https://code.google.com/p/googlemock/wiki/CookBook Creating Mock Classes Mocking Private or Prot ...

随机推荐

  1. bootstrap 按钮组件

    按钮组件主要的类名: .btn-toolbar     把几个  .btn-group 组合在一起,更复杂的组件 .btn-group .btn-group-vertical   垂直堆叠显示    ...

  2. num12---组合模式

    案例描述: 学校下有多个学院,每个学院下有多个专业系. 把学校.院系.专业  全都看成某个组织类型,含有添加add方法,删除remove方法,显示print方法. 如果有新增的院系.专业,新增加对应的 ...

  3. 事务特性ACID及隔离级别

    注:例子引用来自:https://www.cnblogs.com/WJ-163/p/6023054.html 事务就是一组原子性的SQL查询,或者说一个独立的工作单元. 银行应用是解释事务必要性的一个 ...

  4. C/C++中的排序和查找

    以下内容来自<C/C++程序设计实用案例教程> 1.排序 1.1使用qsort函数 C/C++库函数提供了快速排序函数qsort(q时quick的简写),需要引入头文件<stdlib ...

  5. 什么是JWT以及具体应用

    jwt理论阮大神已经解释的很到位了 http://www.ruanyifeng.com/blog/2018/07/json_web_token-tutorial.html jwt官网收录了多种实现库, ...

  6. python上获得随机字符

    import random import string print(string.ascii_letters) # 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO ...

  7. Aliyun搭建svn服务器外网访问报错权限配置失败错误

    搭建完后所有的配置如下 [root@iZuf655czz7lmtn8v15tsjZ conf]# pwd /home/SVN/conf [root@iZuf655czz7lmtn8v15tsjZ co ...

  8. c++ 有符号int和无符号int做加减乘除问题

    c++ 有符号int和无符号int做加算术运算的问题: 一.运算过程先把有符号的补码数直接看成无符号数,在和无符号数进行算术运算 二.int和unsigned int类型进行混合算数运算时,运算结果为 ...

  9. mysql--容器无法启动

    mysql服务总是在重启状态 查看mysql容器日志 # docker logs 镜像名称 InnoDB: If this error appears when you are creating an ...

  10. Mysql:MySQL数据管理

    Mysql:MySQL数据管理 外键管理 外键概念 如果公共关键字在一个关系中是主关键字,那么这个公共关键字被称为另一个关系的外键.由此可见,外键表示了两个关系之间的相关联系.以另一个关系的外键作主关 ...