| Reference | Downloads | Github

Counterbalancing Image Side


I have two images presented on a screen and I want to counterbalance the side they appear on so that in one trial an image will appear on the left and in a subsequent trial it will appear on the right side of the screen, I was wondering how to do this.

Thanks in advance!

If you want to have a conditional presentation where an image on the right must follow an image on the left, you can add some code in a code component to do this. You can have a single image component to do this, so long as they are not appearing simultaneously. Make sure code component is ordered after your image component

# Begin experiment

imPositions = [(-.5, 0), (.5, 0)]
shuffle(imPositions)  # to randomize first position

# Begin routine

if image.pos[0] == -.5:
    image.setPos((.5, 0))
    image.setPos((-.5, 0))

Thank you!
When I tried to do this it flipped the side that the image appears on the screen every subsequent trial, I was wondering if there was a way to randomize the side the image appears on (e.g. ~Left, Left, Right, Left~ instead ~Left, Right, Left, Right~)

Ok I was basing my solution on this. Yes, no problem, see code:

# Begin experiment

imPositions = [(-.5, 0), (.5, 0)]

# Begin routine
shuffle(imPositions)  # to randomize position
image.setPos(imPositions[0])  # Now position is random on every trial

That worked! Thank you!