here is my code:
from psychopy import visual, event, gui
import random, os
from random import shuffle
from PIL import Image
import glob
# import images sequences and randomize in the same order
a = glob.glob("DDtest/targetimagelist1/*")
b = glob.glob("DDtest/distractorimagelist1/*")
c = glob.glob("DDtest/targetimagelist2/*")
d = glob.glob("DDtest/distractorimagelist3/*")
indices = random.sample(range(len(a)), len(a))
a = map(a.__getitem__, indices)
b = map(b.__getitem__, indices)
c = map(c.__getitem__, indices)
d = map(d.__getitem__, indices)
def loop():
# randomizes the location of the stimuli
loc = [1, 2]
location = random.choice(loc)
if location == 1:
pos1 = [-.05,-.05]
pos2 = [.05, .05]
else:
pos1 = [.05, .05]
pos2 = [-.05, -.05]
# randomizes the image lists
type = [1,2]
trialtype = random.choice(type)
if trialtype == 1:
target = a
distractor = b
else:
target = c
distractor = d
# Create window and stimuli.
win = visual.Window(size=(1280, 800), fullscr=True, screen=0, monitor='testMonitor', color=[-1,-1,-1]) # removed a default value
targetstim = visual.ImageStim(win=win, pos=pos2, size=[0.5,0.5])
targetstim.autoDraw = True
distractorstim = visual.ImageStim(win=win, pos=pos1, size=[0.5,0.5])
distractorstim.autoDraw = True
distractorstim.image = distractor[i]
targetstim.image = target[i]
# Display and wait for answer
win.flip()
event.waitKeys(keyList = ['space'])
# loop
for i in range(len(a)):
loop()
So here is my problem: I have 64 images in each file. The current program terminates when the 64 images have been displayed (length is based on the amount of images in 'a'). What I would like is for the file to terminate when all images have been displayed (128 trials). Is there anyway to do this? I will appreciate any help or guidance. :)
Edit:
I tried doing this to the loop:
# loop
for i in range(len(a)*2):
loop()
What happens when I do this, the images cycle as they did before except when I get a little past 64 (65-67) it tries to call an image that is outside the range, and this causes an "IndexError:list index out of range." Basically I need some way to index one list from 1-64, and the other 65-128, and then just randomly generate the order while ensuring that the index for list a and b are the same.