Randomizing image location...kind of

Hi, I’m completely new to Psychopy so bear with me here. I have this image priming thing set up, with the excel sheet to all of my images attatched. Right now, when I run the experiment, the images just appear in the middle of the screen. I know how to adjust the location, but I do not know how to set it so it will randomly assign images to either the left or right side of the screen. Any help would be appreciated :slight_smile:

Hello, welcome to the forum!
To clarify, do you have two images for each trial?
What kind of randomization are we talking about? Do you want to have 2 locations for each trial and assign each image one of those locations? Are we talking about a more flexible range of locations?

It would be very helpful if you could attach the experiment/an image.

Hi, thanks for getting back. So I have a pool of images for each of the 2 conditions, with 80 images in each pool. What happens is there is a dot in the middle of the screen, and what I want to happen is for when the images to play, rather than appearing in one set location, I want them to flash on either the left side of the dot or the right side of the dot at random. Then after each image the participants will hit either the left key or the right key depending on which side the image appeared on at random.

I assume you know how to randomize the conditions and the image that is being displayed, correct me if I am wrong.

About the locations. My solution would be to create a list containing the locations you want to randomize.
You said you want the right side and the left side of the screen, so the list would look like this:
[(-0.5, 0), (0.5, 0)]

Then, at the start of each routine, we would like to get a random location (either left or right) and assign it to your image:

# Begin Experiment:
import random
locations = [(-0.5, 0), (0.5, 0)]

# Begin Routine:
img.pos = random.choice(locations)

The result will give you exactly what you asked for. Here’s an example:
Example.zip (30.1 KB)

Let me know if you need any help :slight_smile:

1 Like

Since the correct answer also depends on the location, you could have:

Begin Experiment

locations = [[(-0.5, 0),'left'], [(0.5, 0),'right']]

Begin Routine


with the image position set to locations[0][0] Each Repeat and the keyboard correct answer set to locations[0][1]


Hi thanks for the help, it almost works- the images I have are attached through an excel sheet rather than being directly uploaded (80 images, 2 conditions). I think that may be messing with the code you sent a little bit- is there a fix for that? Thank you so much again

This was also going to be my follow up question lol, thank you so much

1 Like

Any chance you could upload your experiment here? Including the excel sheet as well as some images. You could also create a simplistic version of your experiment so that you won’t upload 160~ images.

Also, make sure you update the path to your image every repeat (instead of constant):

Here is a smaller version of the experiment, I really appreciate the help
Test Run.zip (5.2 MB)

You almost had it.
In your code component, you wrote the following:

img.pos = random.choice(locations)

The issue is your image isn’t named img. It’s named blackfaces. The following works:

blackfaces.pos = random.choice(locations)

You can copy the code component and do the same in the second routine. All you need to pay attention to is the name of your image :slight_smile: