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
import random
from pygame.locals import * #creat the subject information function
def sub_info():
sub_ID = input("please input your number: ")
sub_name = input("please input your name: ")
sub_male = input("please input your male: ")
sub_age = input("please input your age: ")
return sub_ID, sub_name,sub_male,sub_age
#the variable result will be a tuple
result = sub_info()
#turn the tuple to a list
result = list(result) 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 #creat the list
#L mean left ,R mean right , RE mean the color red, BL mean the color blue
lis = [ ["L","RE","Z"],
["L","BL","/"],
["R","RE","Z"],
["R","BL","/"]] #creat a function to ran one trial
#the list for store our result
lis2 = []
def one_trial_list(pars):
#the parameters must be a list which contains the location, color ,right response of the stimuli and the the sequence of the element of parameters should not change"""
global left
global right
global red
global blue
global black
global result
loc,col,ress=pars
if loc =="L":
pos = left
if loc =="R":
pos = right
if col =="BL":
color = red
if col == "RE":
color = blue win.fill(black)
pygame.draw.circle(win,color,pos,20,0)
pygame.display.flip()
result1 = wait4key(2000,[K_z,K_SLASH])
#turn the result1 which is the result of the wait4key function to a list
result1 = list(result1)
#join two list and then give it to a new variable
result2 = result + result1
#turn the list to a string and add a space to the end
#we need to turn the element of result2 to string type, because some element are int
resul_map = map(str,result2)
result2 = ",".join(resul_map) + "\n"
print(result2)2
return result2 #random our lis which contains four trails
lis1 = lis*2
random.shuffle(lis1) #run four trials and write our result to a new file
#open a file
with open("C:/Users/mike1/Desktop/simmon_result.txt","w",encoding = "utf-8") as f1: for i in lis1:
result4 = one_trial_list(i)
#write every result to the file
f1.write(result4) #when one trail end ,fill the window black again
win.fill(black)
pygame.display.flip()
pygame.time.delay(500)
pygame.quit()
sys.exit()
the result
we also creat a file in the window
simmon effect(psychology experiment) : this time, we add file_function who can creat a file in the window which contains our result的更多相关文章
- 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 sy ...
- 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 ...
- 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 ...
- How can I add a new user as sudoer using the command line?
Two ways to use sudo command for a standard user account: First, If you want to use sudo command for ...
- FreeHttp (a fiddler add in to temper the http)
introduction FreeHttp is a Fiddler plugin. With FreeHttp you can modify the request or response mess ...
- 2 Add Two Numbers
// Java public ListNode addTwoNumbers(ListNode l1, ListNode l2) { return add(l1, l2, false); } priva ...
- How to add alias on Mac(It's common for most system)
Since these files are hidden you will have to do an ls -a to list them. If you don't have one you ca ...
- Your project is not referencing the ".NETPortable,Version=v4.5,Profile=Profile259" framework. Add a reference to ".NETPortable,Version=v4.5,Profile=Profile259" in the "frameworks" section of your proj
i want to add nuget packages to my portable class library project , then i add a project.json to my ...
- git add详解
git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的文件. git add -u :他仅监控 ...
随机推荐
- 文件传输协议-FTP
一.FTP概述 FTP(File Transfer Protocol 文件传输协议)C/S结构的应用层协议.由服务端和客户端两个部分共同实现文件传输功能 FTP服务器普遍部署于内网中,具有容易部署.方 ...
- python 中列表 元组 字典 集合的区别
先看图片解释 (1)列表 什么是列表呢?我觉得列表就是我们日常生活中经常见到的清单.比如,统计过去一周我们买过的东西,把这些东西列出来,就是清单.由于我们买一种东西可能不止一次,所以清单中是允许有重复 ...
- Linux 发行版本简述
在撰写这篇文章前,先向linux创始人 Linus Torvalds 先生致敬,感谢您二十多年前的无私开源! 其次向二十多年来维护更新的开发者们致敬! Lin ...
- Ubuntu下LAMP的环境配置教程
总体来说,Ubuntu下安装LAMP环境是比较简单的,只需按照命令行执行即可,记录操作以备不时之需. 一,首先更新Ubuntu里面所有的软件 sudo apt-get update 二.之后安装Apa ...
- IT运维软件免费送 智和信通战疫活动火热进行中
突如其来的“新型冠状病毒”疫情牵动了全国人民的心,这是一场与病毒抗争,为生命逆行与时间赛跑的战役.举国上下众志成城面对疫情,在线医疗.在线教学.在线办公.在线会议.电商销售成为热点.线上经济的火热给企 ...
- C++ 解决列车重排问题
问题节选自<<数据结构.算法与应用(C++语言描述)>>, 思路与代码为原创, 如有疏漏及问题欢迎指正 问题描述: 一辆列车有n节车厢, 车厢排列乱序(如: 284657139 ...
- ASP.NET MVC通用权限管理系统(响应布局)源码更新介绍
一.asp.net mvc 通用权限管理系统(响应布局)源码主要以下特点: AngelRM(Asp.net MVC)是基于asp.net(C#)MVC+前端bootstrap+ztree+lodash ...
- 复制表结构创建分表 再设置自增ID
CREATE TABLE table_name1 LIKE table_name ALTER TABLE test AUTO_INCREMENT=x
- Android Studio 学习笔记(五):WebView 简单说明
Android中一个用于网页显示的控件,实际上,也可以看做一个功能最小化的浏览器,看起来类似于在微信中打开网页链接的页面.WebView主要用于在app应用中方便地访问远程网页或本地html资源.同时 ...
- opencv —— approxPolyDP 生成逼近曲线
生成逼近曲线:approxPolyDP 函数 该函数采用 Douglas-Peucker 算法(也称迭代终点拟合算法).可以有效减少多边形曲线上点的数量,生成逼近曲线,简化后继操作. 经典的 Doug ...