| Reference | Downloads | Github

Draw multiple TextStim objects on screen within a single frame


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(
                        # take the letter for that position
                        stimObject.pos = j[1]
                        # and add it to the right position
                        # draw this on the screen
                    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']) ):
                    trials_loop.append({'state':'delay_on', 'timestamp': trial_clock.getTime()} )
                    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 :slight_smile:

Many thanks in advance!

Have a look at my Navon figure demo

I use auto draw to show hide the objects