# -*- coding: utf-8 -*- import pygame, os, platform, random from pygame.locals import * background_color = (0,0,0) white=(255,255,255) red=(255,0,0) green=(0,255,0) yellow=(255,255,0) blue=(0,0,255) cyan=(51,255,255) purple=(153,51,153) colors=[red,green,yellow,cyan,blue,purple] colors_no_load=[cyan,blue,purple] letter_colors=['A','a'] # height in cm = 0.35 aka 0.35 degree on retina at 53 cm from screen height_letter=20 #font initially 100 (px) # computer screen dimensions in cm screen_width = 25.6 screen_height = 14.4 # assume pixels are square, returns integer #def cm_to_pix(cm): # return int(round(W*float(cm)/screen_width)) # time presentation (ms) time_blank=250 time_letter=500 # screen dimensions (px) W=900 H=600 # table of contingencies (condition 2) tp_c2=0 # true positive tn_c2=0 # true negative fp_c2=0 # false positive fn_c2=0 # false negative # numbers of red in one block ntarget_c2=0 # numbers of trials ntrials=10 pygame.init() screen=pygame.display.set_mode((W,H)) police = pygame.font.Font(None, height_letter) # Boucle principale for trial in range(ntrials): screen.fill(background_color) pygame.display.flip() pygame.time.wait(time_blank) theletter=random.randrange(len(letter_colors)) thecolor=random.randrange(len(colors)) letter_to_display=police.render(letter_colors[theletter],1,colors[thecolor]) screen.blit(letter_to_display, (W/2,H/2)) pygame.display.flip() pygame.time.wait(time_letter) # count right answers boucle=True while boucle: for evenement in pygame.event.get(): if evenement.type == pygame.KEYDOWN: if evenement.key == pygame.K_w: if (thecolor==0): tp_c2+=1 boucle=False else: boucle=False results=str(tp_c2)+" true positive on "+str(ntarget_c2) screen.fill(background_color) police = pygame.font.Font(None, 50) results_to_display=police.render(results,1,green) screen.blit(results_to_display,(100,100)) pygame.display.flip() pygame.time.wait(3000) pygame.quit()