3 ### BEGIN CONFIGURATION SECTION ###
5 RESOLUTION
= (1024,768)
7 # which SIZE of the visible area?
10 # how many TRIALS per round (MINimum)
13 # LENGTH of STimulus presentation in seconds
16 # LENGTH of Break between Trials in seconds
19 # which N-back initially?
22 # UPPER ThresHold, above which N is increased
25 # LOWER ThresHold, below which N is decreased
34 IFS
= ['1.png','2.png','3.png','4.png','5.png','6.png','7.png','8.png']
35 SFS
= ['1.ogg','2.ogg','3.ogg','4.ogg','5.ogg','6.ogg','7.ogg','8.ogg']
38 ### END CONFIGURATION SECTION ###
40 TOPLEFT
=((RESOLUTION
[0]-SIZE
[0])/2,(RESOLUTION
[1]-SIZE
[1])/2)
43 from random
import randint
44 from pygame
import display
, image
, key
, Surface
, mixer
, event
, mouse
, font
45 from pygame
import FULLSCREEN
, KEYDOWN
46 from pygame
.transform
import scale
50 for f
in IFS
+SFS
+[BASE
]:
55 print >> sys
.stderr
, "FATAL:",die
59 if not len(IFS
) == len(SFS
):
60 print >> sys
.stderr
, "FATAL: amount of stimuli for different modalities do not match!"
64 def __init__(self
,imagefile
,soundfile
,trgtimg
,trgtsnd
):
65 self
.image
= scale(image
.load(imagefile
), SIZE
).convert()
66 self
.fill
= scale(image
.load(BASE
),SIZE
).convert()
67 self
.sound
= mixer
.Sound(soundfile
)
68 self
.trgtimg
= trgtimg
69 self
.trgtsnd
= trgtsnd
70 self
.result
= [not(self
.trgtimg
),not(self
.trgtsnd
)]
73 surface
= display
.get_surface()
74 surface
.fill((255,255,255))
75 surface
.blit(self
.image
,TOPLEFT
)
79 surface
.blit(self
.fill
,TOPLEFT
)
83 for e
in event
.get(KEYDOWN
):
84 keypresses
+= [e
.dict['unicode']]
85 if SPACE
in keypresses
:
87 if unicode(KEYLEFT
) in keypresses
:
89 #print "user hit key \""+ KEYLEFT +"\" correctly"
92 #print "user hit key \""+ KEYLEFT +"\" incorrectly"
93 self
.result
[0] = False
94 if unicode(KEYRIGHT
) in keypresses
:
96 #print "user hit key \""+ KEYRIGHT +"\" correctly"
99 #print "user hit key \""+ KEYRIGHT +"\" incorrectly"
100 self
.result
[1] = False
106 result
.append(l
[randint(0,len(l
)-1)])
107 for i
in range(0,MINTRIALS
):
109 result
.append(result
[-N
])
111 # be strict about probabilities
114 result
.append(myl
[randint(0,len(myl
)-1)])
119 iis
= myrandom(range(0,len(IFS
)-1))
120 sis
= myrandom(range(0,len(SFS
)-1))
121 for i
,j
,k
in zip(iis
,sis
,range(0,len(iis
))):
123 trials
.append(Trial(IFS
[i
],SFS
[j
],False,False))
126 trials
.append(Trial(IFS
[i
],SFS
[j
],iis
[k
]==iis
[nb
],sis
[k
]==sis
[nb
]))
133 print "(Hint: while training, you can hit SPACE to abort)"
134 print "Hit '"+KEYLEFT
+"' if the",str(N
)+". previous image is identical to the one shown"
135 print "Hit '"+KEYRIGHT
+"' if the",str(N
)+". previous sound is identical to the one heard"
137 print "Ready to train with N=%i?" %(N),
138 spam
= raw_input(" [Yes/No]? ")
139 if re
.match("y(es)?", spam
, re
.I
):
141 elif re
.match("n(o)?", spam
, re
.I
):
145 display
.set_mode(RESOLUTION
, FULLSCREEN
)
149 mouse
.set_visible(False)
152 if not trial
.runtrial():
162 vp
= (vis
/(MINTRIALS
+N
))*100
163 ap
= (acu
/(MINTRIALS
+N
))*100
164 message
= "percentage in visual modality:%i\npercentage in acoustic modality:%i\n" %(int(vp
),int(ap
))
166 if vp
>= UPPERTH
and ap
>= UPPERTH
:
168 elif (vp
< LOWERTH
or ap
< LOWERTH
) and N
> 1:
171 if __name__
== "__main__":