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 ...
随机推荐
- Linux系统基础认知
什么是操作系统? 操作系统作为接口的示意图: 没有安装操作系统的计算机,通常被称为裸机 如果想在 裸机 上运行自己所编写的程序,就必须用机器语言书写程序 如果计算机上安装了操作系统,就可以在操作系统上 ...
- Trie(字典树)的侃侃
Trie是什么 ? 字典树 : 见名知意(在树上进行查询). 跟字典相关的必定与查询有密切的关系, 查询就需要一定的媒介作为支撑,树就为这种查询提供支撑. Trie做什么 ? 实现字符串快速检索的多叉 ...
- C语言实现matlab的interp2()函数
项目要用到matlab中的Vq = interp2(X,Y,V,Xq,Yq)函数,即把一个已知经纬度和对应值的矩阵,插值变换到一个给定经纬度网格中,也就是对给定网格填值,需要用到插值,这里使用双线性内 ...
- create-react-app 打包后静态文件过大 webpack优化
在最近的项目里,页面和静态文件并不是很多的情况下,打包后发现产出的静态资源却很大. 1.关掉sourcemap 在config/webpack.config.js文件里,大概30几行的位置添加这样一句 ...
- 【学习底层原理系列】重读spring源码1-建立基本的认知模型
开篇闲扯 在工作中,相信很多人都有这种体会,与其修改别人代码,宁愿自己重写. 为什么? 先说为什么愿意自己写: 从0-1的过程,是建立在自己已有认知基础上,去用自己熟悉的方式构建一件作品.也就是说, ...
- 后台+下载(wget)+多个下载url
有时候我们需要让linux下载多个文件,并且后台下载,不去占用当前控制台. 比如我们需要下载中文维基的三个文件: https://dumps.wikimedia.org/zhwiki/latest/z ...
- PWA 学习笔记
深入学习网址:https://developer.mozilla.org/zh-CN/docs/Web/Progressive_web_apps 一. 基本介绍 1. 渐进式:适用所有浏览器,因为它是 ...
- [Python]random生成随机6位验证码
#!/usr/bin/env pyhton # coding:utf-8 # @Time : 2020-02-16 10:07 # @Author : LeoShi # @Site : # @File ...
- 【HDU - 2859 】Phalanx (dp 最大对称子图)
Phalanx 先搬翻译 Descriptions: 给你一个矩阵,只由小写或大写字母构成.求出它的最大对称子矩阵的边长. 其中对称矩阵是一个k*k的矩阵,它的元素关于从左下角到右上角的对角线对称.例 ...
- codewars--js--ten minutes walk
题目: You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten ...