##
#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. 苹果系统iOS、macOS应用管理机制

    iOS.macOS系统应用管理机制 苹果系统包括:iOS.macOS.watchOS.tvOS.应用软件的生命周期为:开发.上线.安装.使用.卸载.这篇文档将从应用生命周期的各个环节介绍苹果系统对应用 ...

  2. qt creator源码全方面分析(2-0)

    目录 Extending Qt Creator Manual 生成领域特定的代码和模板 代码片段 文件和项目模板 自定义向导 支持其他文件类型 MIME类型 高亮和缩进 自定义文本编辑器 其他自定义编 ...

  3. 20200220--python学习第13天

    今日内容 作业题(21题) 推导式 装饰器 模块[可选] 内容回顾 1.函数 a.参数 def func(a1,a2):pass def func(a1,a2=None):pass 默认参数推荐使用不 ...

  4. mysql 启动,停止,重启

    启动mysql: 方式一:sudo /etc/init.d/mysql start  方式二:sudo start mysql 方式三:sudo service mysql start sudo ./ ...

  5. 搭建fastdfs文件服务器

    一.安装FastDFS环境 1.跟踪服务器(Tracker Server) tracker1:192.168.2.134 tracker2:192.168.2.135 2.存储服务器(Storage ...

  6. 10个用于C#.NET开发的基本调试工具

    在调试软件时,工具非常重要.获取正确的工具,然后再调试时提起正确的信息.根据获取的正确的错误信息,可以找到问题的根源所在.找到问题根源所在,你就能够解决该错误了. 你将看到我认为最基本的解决在C# . ...

  7. 1Python学习CentOS 7 Linux环境搭建

    鉴于python3目前已成流行之势,而各发行版Linux依然是自带python2.x,笔者尝试在centos7下,部署Python3.x与2.x共存环境 本文参考博主良哥95网址https://blo ...

  8. 如何用apply实现一个bind?

    面试题:如何用apply实现一个bind? Function.prototype._bind = function(target) { // 保留调用_bind方法的对象 let _this = th ...

  9. Vue中使用NProgress实现进度条

    简介 NProgress是页面跳转或者发生异步请求是浏览器顶部的进度条 GitHub地址:https://github.com/rstacruz/nprogress 在线演示地址:http://ric ...

  10. 安装Nginx到CentOS(YUM)

    运行环境 系统版本:CentOS Linux release 7.3.1611 软件版本:nginx-1.12.2 硬件要求:无 安装过程 1.配置YUM源 [root@localhost ~]# r ...