Hi,
I’m coding an iconic memory experiment using Coder (no code snippets from the Builder).
In this experiment I need to present up to 20 letters in specific locations on the screen. I need single-frame precision, since in some cases I will present the stimulus array for only one frame. My problem is that my code for drawing multiple text objects takes too long (i.e. more than a single frame), and I’m looking for a way to optimize it.
Here is the code I am using at the moment:
for frame in range(stimExpTime + soaCue + cueExpTime):
if frame < stimExpTime:
for j in enumerate(trial['ArrayPos']): # --> This loop takes more than 16ms
# for every predetermined position on the screen
stimObject = visual.TextStim(
win=mywin,
text=trial['Array'][j[0]],
# take the letter for that position
height=exp['fontsizeStimuli'])
stimObject.pos = j[1]
# and add it to the right position
stimObject.draw()
# draw this on the screen
mywin.flip()
trials_loop.append({'state':'stimulus_on', 'timestamp': trial_clock.getTime()} )
# so here I get ~32ms readout for each frame. If I run the same code but don't present any stimuli (i.e., comment out the loop above), I get a ~16ms readout, as expected.
# this part below works as expected
elif (frame >= exp['stimExpTime']) & (frame < (exp['stimExpTime'] + exp['soaCue']) ):
print('delay')
mywin.flip()
trials_loop.append({'state':'delay_on', 'timestamp': trial_clock.getTime()} )
else:
print('cue')
cueLine.draw()
mywin.flip()
trials_loop.append({'state':'cue_on', 'timestamp': trial_clock.getTime()} )
I guess my question is whether it’s possible to combine multiple text objects together in one objects, so that I can to that at ISI and only draw the combined object in the frame-based loop?
I hope this is clear enough
Many thanks in advance!