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 # sometimes the random distribution of stimuli results in a very low interaction on your part.
23 # in order to address this, do some ITERATIONS and take the maximum of all random distributions.
26 # UPPER ThresHold, above which N is increased
29 # LOWER ThresHold, below which N is decreased
38 IFS
= ['1.png','2.png','3.png','4.png','5.png','6.png','7.png','8.png']
39 SFS
= ['1.ogg','2.ogg','3.ogg','4.ogg','5.ogg','6.ogg','7.ogg','8.ogg']
41 ### END CONFIGURATION SECTION ###
43 TRIALS
= MINTRIALS
+ N
44 TOPLEFT
=((RESOLUTION
[0]-SIZE
[0])/2,(RESOLUTION
[1]-SIZE
[1])/2)
47 from random
import randint
48 from pygame
import display
, image
, key
, Surface
, mixer
, event
, mouse
, font
49 from pygame
import FULLSCREEN
, KEYDOWN
50 from pygame
.transform
import scale
59 print >> sys
.stderr
, "FATAL:",die
63 if not len(IFS
) == len(SFS
):
64 print >> sys
.stderr
, "FATAL: amount of stimuli for different modalities do not match!"
68 def __init__(self
,imagefile
,soundfile
,trgtimg
,trgtsnd
):
69 self
.image
= scale(image
.load(imagefile
), SIZE
).convert()
70 self
.sound
= mixer
.Sound(soundfile
)
71 self
.trgtimg
= trgtimg
72 self
.trgtsnd
= trgtsnd
73 self
.result
= [not(self
.trgtimg
),not(self
.trgtsnd
)]
76 surface
= display
.get_surface()
77 surface
.fill((255,255,255))
78 surface
.blit(self
.image
,TOPLEFT
)
82 surface
.fill((255,255,255))
86 for e
in event
.get(KEYDOWN
):
87 keypresses
+= [e
.dict['unicode']]
88 if unicode(KEYLEFT
) in keypresses
:
90 #print "user hit key \""+ KEYLEFT +"\" correctly"
93 #print "user hit key \""+ KEYLEFT +"\" incorrectly"
94 self
.result
[0] = False
95 if unicode(KEYRIGHT
) in keypresses
:
97 #print "user hit key \""+ KEYRIGHT +"\" correctly"
100 #print "user hit key \""+ KEYRIGHT +"\" incorrectly"
101 self
.result
[1] = False
105 return [l
[randint(0,len(l
)-1)]]+nfroml(n
-1,l
)
113 return 1+nback(n
,l
[1:])
115 return nback(n
,l
[1:])
118 tmp1
= nfroml(TRIALS
,l
)
119 positives1
= nback(N
,tmp1
)
120 for i
in range(0,ITERATIONS
):
121 tmp2
= nfroml(TRIALS
,l
)
122 positives2
= nback(N
,tmp2
)
123 if positives1
< positives2
:
124 #print positives1, "<", positives2
126 positives1
= positives2
131 iis
= cheatshuffle(range(0,len(IFS
)-1))
132 sis
= cheatshuffle(range(0,len(SFS
)-1))
133 for i
,j
,k
in zip(iis
,sis
,range(0,len(iis
)-1)):
135 trials
.append(Trial(IFS
[i
],SFS
[j
],False,False))
138 trials
.append(Trial(IFS
[i
],SFS
[j
],iis
[k
]==iis
[nb
],sis
[k
]==sis
[nb
]))
143 mf
= font
.Font(font
.get_default_font(),FONTSIZE
)
144 foo
= display
.get_surface()
146 foo
.blit(mf
.render(string
,True,(0,255,0),(0,0,0)),TOPLEFT
)
150 for e
in event
.get(KEYDOWN
):
151 es
+= [e
.dict['unicode']]
164 display
.set_mode(RESOLUTION
, FULLSCREEN
)
168 mouse
.set_visible(False)
181 vp
= (vis
/TRIALS
)*100
182 ap
= (acu
/TRIALS
)*100
183 message
= """percentage in visual modality:%i\n
184 percentage in acoustic modality:%i\n""" %(int(vp
),int(ap
))
186 if vp
>= UPPERTH
and ap
>= UPPERTH
:
188 elif vp
< LOWERTH
or ap
< LOWERTH
and N
> 1:
191 if __name__
== "__main__":