Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Randomize image position

Hello, I am trying to present 3 images on the same screen but I'd like their position on screen to be random. In that way, for example, image 'happy' will not always be on position1 but its position will be randomized on each trial. Is there a way to present all images in all possible position combinations without hardcoding it? Thanks :)

....
position1 = (250,0)
position2 = (0,0)
position3 = (-250,0)
#define and preload stimuli
happy = stimuli.Picture("images\happy.png", position=position1)
sad = stimuli.Picture("images\sad.png", position=position2)
angry = stimuli.Picture("images\angry.png", position=position3)
....

#present stimuli
happy.present(update=False)
sad.present(update=False, clear=False)
angry.present(clear=False)
....


Comments

  • Hi,


    you could do something like

    import itertools
    
    all_combinations = list(itertools.permutations([position1, position2, position3]))
    
    block = expyriment.design.Block()
    for combination in combinations:
        trial = expyriment.design.Trial()
        happy = stimuli.Picture("images\happy.png", position=combination[0])
        sad = stimuli.Picture("images\sad.png", position=combination[1])
        angry = stimuli.Picture("images\angry.png", position=combination[2])
        trial.add_stimulus(happy)
        trial.add_stimulus(sad)
        trial.add_stimulus(angry)
        block.add_trial(trial)
    
    exp.add_block(block)
    
    
    

    and then loop over this structure

    for block in exp.blocks:
        for trial in block.trials:
            expyriment.stimuli.FixCross().present()
            exp.clock.wait(1000 - trial.preload_stimuli()
            trial.stimuli[0].present(update=False)
            trial.stimuli[1].present(clear=False, update=False)
            trial.stimuli[2].present(clear=False)
            exp.clock.wait(2000)
    
  • Hi,

    exactly what I was looking for! Thanks for the help!

  • Sorry for coming back to this, but in this way I cannot find a way to return the option chosen.

    For example after generating a random location of the images

    all_combinations = list(itertools.permutations([position1, position2, position3]))
    random.shuffle(all_combinations)
    

    then the images on the screen will be presented like this:

    [angry] [sad] [happy]

    and the participant chooses the [angry] face

    I can only report back on expyriment output the 'left' key that is pressed, the reaction time or the position of the image that was chosen, but not which image. In that case the position will be (-250,0). But for me this is not valuable information because it is not 'paired' with the angry face.

    I would really appreciate if you know a way to resolve this! Thanks :)

Sign In or Register to comment.