Howdy, Stranger!

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

Supported by

Show multiple images at the same time at random positions

Hello everyone,

in my experiment I'd like to show 10 small images at the same time for about 3 minutes. So I created a sketchpad with 10 images on different positions. This works fine, but of course the images always appear at the same positions. But I want the images to appear at a different position every time I restart the experiment.

I created a sketchpad with 10 predefined positions for the images, but I can't find a solution how to show the images randomly at these 10 positions.

I thought about creating an inline script, in which I create a list with the pictures and shuffle the list. Like this (a shorter verison with only three images and three positions):


import random

cv=Canvas ()

#image positions
pos1=(-416,224)
pos2=(-256,-128)
pos3=(-96,0)

# Load images from the file pool
a = pool['Def1.png']
b = pool['Def2.png']
c = pool['Def3.png']

# create list
df = [a,b,c]

random.shuffle(df)

Is this correct so far and how do I go from there?

How can I let the images appear at the same time randomly at the three positions?


Greetings

Christian

Comments

  • Hi Christian,

    If I understand correctly, there are three fixed positions, and you want to vary which picture is presented where. Is that right?

    In that case, the easiest approach is probably to first draw three static images at these three locations, using a sketchpad , and then change the script so that the file keyword is variably defined, like so:

    draw image file=[image1] x=-416 y=224 center=1
    draw image file=[image2] x=-256 y=-128 center=1
    draw image file=[image3] x=-96 y=0 center=1
    

    And then you randomize which images are assigned to the variables image1, image2, and image3. The shuffle_horiz loop operation might come in useful, but you can also do it in a script.

    Hope this helps!

    Cheers!

    Sebastiaan

  • Hi Sebastiaan,

    that worked great! Thanks a lot. :)

    Greetings

    Christian

Sign In or Register to comment.