I want to create a Dual Task where participants have to judge two numbers. I created the following function to show the stimuli and collect responses. My problem is that the shown stimuli are flickering on the screen. Why is that so and how can I prevent it from happening?
Thanks in advance!
def StimPresent(a_soa, b_s1, c_s2, posS2, posDummy):
"""
Function StimPresent(a, b, c) presents stimulus_1 (b) for SOA ((a) number of frames),
then it adds stimulus_2 (d) and shows both for max 60 frames
and returns time of stimulus onset (tim)
"""
positionMouse1 = [] # to get position of mouse at time of S1 onset
positionMouse2 = [] # to get position of mouse at time of response
allRTs = [] # array, all RTs are written in here (R1 and R2), clickTime and voiceTime will be appended
clickAnswer = False
clickTime = 0.0
OnsetS1 = 0.0
theRT1 = 0.0
deadlineS1 = 210 # deadline for giving an answer to S1 is 3500 milliseconds
clickArea = 'None'
vk.pyo_init()
voiceAnswer = False
OnsetS2 = 0.0
voiceOnset = 0.0
voiceOffset = 0.0
theRT2 = 0.0
deadlineS2 = 210+a_soa # deadline for answering to S2 is 5000 ms
event.clearEvents()
myMouse.clickReset()
while True: # loop is exited when break conditions are met
for frameN in range(a_soa+60+300): # duration is time in which participants can give an answer (SOA+60+300)
if event.getKeys(keyList='escape, q'):
myWin.close()
core.quit()
if frameN <= a_soa: # shows S1 for SOA
b_s1.draw()
rectL.draw()
rectM.draw()
rectR.draw()
if clickAnswer == False: # draws response areas for mouse click (r1) as long as no answer was given
r1AreaLeft.draw()
r1AreaRight.draw()
myWin.flip()
elif frameN <= (a_soa+60): # shows S1 and S2 after SOA for in total 1000ms (60 frames)
b_s1.draw()
rectL.draw()
rectM.draw()
rectR.draw()
# set positions and add S2 and dummy
c_s2.setPos(posS2)
dummy.setPos(posDummy)
c_s2.draw()
dummy.draw()
myWin.flip()
if clickAnswer == False: # draws response areas for mouse click (r1) as long as no answer was given
r1AreaLeft.draw()
r1AreaRight.draw()
else: # shows only rectangles until deadline has passed
rectL.draw()
rectM.draw()
rectR.draw()
if clickAnswer == False: # draws response areas for mouse click (r1) as long as no answer was given
r1AreaLeft.draw()
r1AreaRight.draw()
myWin.flip()
if frameN == 0: # RT S1 starting immediately after flip
OnsetS1 = RT1.getTime()
positionMouse1 = myMouse.getPos()
if frameN == (a_soa+1):
OnsetS2 = RT2.getTime() #RT S2 starting immediately after soa flip
''' Retrieving R1'''
#while clickAnswer == 0: # making sure that only one click is taken as answer per trial
if myMouse.isPressedIn(r1AreaLeft, buttons=[0]): # other coding option instead of while loop: and clickAnswer == 0:
clickTime = RT1.getTime()
allRTs.append(1) #(clickTime)
theRT1 = clickTime - OnsetS1
positionMouse2 = myMouse.getPos()
clickArea = 'left'
rectM.setLineColor('green')
clickAnswer = True
elif myMouse.isPressedIn(r1AreaRight, buttons=[0]): # other coding option instead of while loop: and clickAnswer == 0:
clickTime = RT1.getTime()
allRTs.append(1) #(clickTime)
theRT1 = clickTime - OnsetS1
positionMouse2 = myMouse.getPos()
clickArea = 'right'
rectM.setLineColor('red')
clickAnswer = True
elif (clickAnswer == False) and (frameN > deadlineS1): # 210 as deadline for R1 (3500ms)
clickTime = [('NaN', 0.0)]
allRTs.append(clickTime)
theRT1 = [('NaN')]
positionMouse2 = [('NaN')]
clickArea = 'None'
clickAnswer = True
''' Retrieving R2'''
if vk.OnsetVoiceKey(sec=2, file_out='thisTrial.trial'): # and clickAnswer == 1 # sec: duration to record in seconds; file_out: name for output filename (for microphone input)
voiceOnset = RT2.getTime()
allRTs.append(voiceOnset)
rectR.setLineColor('red')
if clock.getTime() - OnsetS2 > deadlineS2:
voiceOnset = [('NaN', 0.0)]
allRTs.append(voiceOnset)
if frameN > deadlineS2:
break
theRT1 = clock.getTime() - OnsetS1
theRT2 = clock.getTime() - OnsetS2
#event.clearEvents()
#myMouse.clickReset()
#myWin.flip()
if vk.OffsetVoiceKey(sec=0):
voiceOffset = clock.getTime()
rectL.setLineColor('red')
voiceAnswer = True # to end while loop
RSI()
elif (voiceOnset == [('NaN', 0.0)]) and (frameN > deadLineS2):
voiceAnswer = True # to end while loop
RSI()
#RSI()
return [b_s1, c_s2, a_soa, OnsetS1, clickTime, theRT1, positionMouse1, positionMouse2, clickArea, OnsetS2, voiceOnset, voiceOffset, theRT2]