Hello Stackoverflow community, I am having trouble with a bit of code using the shuffle function:
red_image = 'DDtest/210red.png'
green_image = 'DDtest/183green.png'
b = [red_image, green_image]
c = shuffle(b)
win = visual.Window(size=(1280, 800), fullscr=True, screen=0, monitor='testMonitor', color=[-1,-1,-1], colorSpace='rgb')
teststimulus = visual.ImageStim(win=win,
image= c, mask=None,
ori=0, pos=pos1, size=[0.5,0.5],
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-1.0)
teststimulus.setAutoDraw(True)
win.flip()
event.waitKeys(keyList = ['space'])
What this program is supposed to do is shuffle the order of the picture is displayed. For whatever reason, when I do this it just displays a white block instead. I certain the problem is the shuffle function because it works fine is I try to display a static picture. Any advice as to what the problem might be? Any help will be greatly appreciated. :)
I do feel that there a few things in Python that one has to get used to. One thing is that often objects are handled "in place". This is true for shuffle
too. Actually, you would have been fine using b
. Python just shuffles the list argument itself. So every time you call shuffle(b)
, you'll get a random ordering of your two picture names in the b
object (you can leave out the "c =" part).
Looking at your code, you then still have to pick one of the pictures for ImageStim
because the list always stays the same size (two picture names, just randomly ordered after each call). So you would have to do something like image=b[0]
(first name) or image=b[1]
(second name).
I didn't check all the code, so I don't know whether it will run for sure.
Best,
Axel