1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| # -*- coding: cp1252 -*-
import pygame, os, platform , random , numpy, math
from pygame.locals import *
from random import *
#definition des couleurs
rouge=(255,0,0)
vert_clair=(0,100,0)
bleu_clair=(0,0,255)
bleu=(0,0,100)
noir=(0,0,0)
jaune=(255,255,0)
orange=(255,140,0)
vert=(0,250,0)
couleurs=[rouge,vert,noir,bleu,bleu_clair,vert_clair,jaune,orange]
def aud(file_input):
leson= pygame.mixer.Sound(file_input)
lecanal=leson.play()
pygame.time.wait(250)
def blank_interval():
screen.fill((245,245,245))
def retention():
pygame.draw.circle(screen, (0,0,0) , (W/2, H/2), 10)
def parametre():
Nb_formes = randint(2,8) # entre 2 et 8 formes
W, H = screen.get_size() # les paramètres sont fait pour s'adapter à tous les écrans
liste_x=[W/12,(3*W)/12,(5*W)/12,(7*W)/12,(9*W)/12,(11*W)/12] # la position des cercles suit un cadrillage virtuel
liste_y=[H/8,(3*H)/8,(5*H)/8,(7*H)/8]
taille = H/10 # taille du rayon des cercles
i = 1
tmp = []
params = []
while i <= Nb_formes :
tmp = []
a = randint(0,5)
b = randint(0,3)
x = liste_x[a]
y = liste_y[b]
positioncircle=(x,y)
couleur = couleurs[randint(0, len(couleurs)-1)]
tmp.append(positioncircle)
tmp.append(couleur)
tmp.append(Nb_formes)
tmp.append(taille)
i = i+1
params.append(tmp)
return params
def stimuli(parametre):
i=0
while i < parametre[0][2] :
pygame.draw.circle(screen,parametre[i][1],parametre[i][0],parametre[i][3])
i = i+1
pygame.draw.circle(screen, (0,0,0) , (W/2, H/2), 10)
def choice1_parametre(parametre):
tmp=[]
params =[]
i= 0
coul = couleurs[randint(0, len(couleurs)-1)]
position = [((9*W)/12,H/2),((3*W)/12,H/2)]
taille = H/10
a = randint(0,parametre[0][2]-1)
tmp.append(a)
tmp.append(coul)
tmp.append(position)
tmp.append(taille)
i=i+1
params.append(tmp)
return params
def choice1(choice1_parametre):
Nb_formes = 2
i = 0
while i <= Nb_formes:
pygame.draw.circle(screen,choice1_parametre[0][1],((9*W)/12,H/2),choice1_parametre[0][3])
pygame.draw.circle(screen,choice1_parametre[1][1],((3*W)/12,H/2),choice1_parametre[1][3])
i = i+1
while True:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_RIGHT:
return -1
elif event.key == K_LEFT:
return +1
try:
subject = raw_input('subject name (letters only, no spaces): ')
myfile = open(subject + '.txt', 'wt')
print >>myfile, 'SUBJECT','parametre', subject , parametre
if platform.system() == 'Windows': os.environ['SDL_VIDEODRIVER'] = 'directx'
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode([0,0], FULLSCREEN | DOUBLEBUF)
W, H = screen.get_size()
nouvel_essai=True
t0 = pygame.time.get_ticks()
t1=0
at_rep =1
j=0
par=[]
while True:
screen.fill((245,245,245))
if nouvel_essai:
par = parametre()
t0= pygame.time.get_ticks()
nouvel_essai=False
if j > 0:
break
t1=pygame.time.get_ticks()
if 30 < t1-t0 <2000:
retention()
if 2000 < t1-t0 < 2250:
aud('son.wav')
if 2250 < t1-t0 < 2500:
aud('son.wav')
if 2500 < t1-t0 < 2750:
blank_interval()
if 2750 < t1-t0< 3000:
aud('son.wav')
if 3000 < t1-t0 < 4500:
retention()
if 4500 < t1-t0 < 4650:
stimuli(par)
if 4650 < t1-t0 < 5850:
retention()
if 5850 < t1-t0 :
response = choice1(par)
#if 8850 < t1-t0 :
#choice2(par)
if t1-t0 > 12000:
j=j+1
nouvel_essai=True
pygame.display.flip()
finally:
try: myfile.close()
except: pass
pygame.quit() |
Partager