How to randomise screen positions for 20 images

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10):
Win 10
PsychoPy version (e.g. 1.84.x): 3
Standard Standalone? (y/n) If not then what?:y
What are you trying to achieve?:
I would like to present 20 object images in succession in one set sequence of random screen locations against a background reference grid.

I have found one or two similar threads but none which fully answer my question.

Attached:
(1) my routine
(2) my flow
(3) conditions file

NOTE: the images and the background are all working and they are appearing fine in the centre of the screen.

any general observations upon looking at my screenshots very welcome.

Cheers,
Tom

@TomH, if you only present 1 image at a time, but want them to appear at random locations in a grid, you can do this using a code component (note, this demo has more than 20 locations):

Begin Experiment

##### Create grid
xLocs = [-.2, -.1, 0, .1, .2]
yLocs = [-.2, -.1, 0, .1, .2]
locs = []

for x in xLocs:
    for y in yLocs:
        locs.append([x, y])

# Shuffle the locations
shuffle(locs)
i = 0  # current index for locations

Begin Routine

currentLoc = locs[i]
imageStim.pos = currentLoc

End Routine

i += 1  # increment location index

Just make sure, that you run the same amount of loop iterations as you have locations, otherwise you will get an index error when attempting to access locations out of the list range. Here is a working demonstration:

randomLocsSequence.psyexp (8.1 KB)

Thank you for the very informative reply - I learned a lot seeing that example.

Unfortunately i’m still not getting it to run.

(1) I made an attempt to set my grid to having 20 locations
(2) I set the number of loop iterations to len(locs)

Any clarification you might be able to offer is appreciated.

Best wishes,
Tom

@TomH, the error is because the imageStim variable was just a placeholder, you would have to change it to image, or the name of your image component that changes location (apologies, I should have commented the code). Also, in my demo, I did not have a conditions file, so I used nReps to control the number of presentations. The number of presentations in your experiment is controlled by the number of rows in your conditions file (nTrials), by the number of blocks (nReps), so total number of trials will be nTrials * nReps. Instead, if you only want 1 presentation of your 20 stim, just set nReps to 1, and let the number of rows in your conditions file control the number of stimuli that are presented.

Thanks a lot that done the trick!

NOTE* For anyone else trying something similar remember to check the units on the grid - i thought it wasn’t working for a bit when it actually was because the grid I had drawn was too small.

1 Like

Hello again,

Returning to exact same paradigm above - is it possible to set it such that within each participant’s experience, they are only exposed to one set order of objects and locations in several different psychopy routines (i.e., the order and locations which were initially randomly generated in the first phase)? So can I keep a randomly generated set of objects and locations constant after being initially randomly generated?

Sorry if that’s poorly worded, if there is any further information that might clarify things please let me know.

Best wishes,
Tom