new to the scene. I've created a code for a Visual Search task with a randomized number of Distractors (1/5/9) and a Target that may or may not appear (50% chance).
The coordinates for the placements of both Distractors and Target are randomized, but naturally that on its own doesn't prevent overlap, and both Distractors and Target keep clashing with each other.
Is there any way to prevent it?
I've considered trying to add each new random set of positions to a list and somehow make sure the list doesn't allow duplicates/close numbers (if duplicate/close then randomize again), but no idea how to implement.
Code provided: (D = Distractor, T = Target):
for i in range(20):
ClosedD_num = random.choice([1, 5, 9])
ClosedD_list = []
for i in range(ClosedD_num):
x_pos = random.uniform(-0.5, 0.5)
y_pos = random.uniform(-0.5, 0.5)
ClosedD = visual.ImageStim(
win=window,
name='ClosedD',
image='images/closed_d.png', mask=None, anchor='center',
ori=randint(1, 360), pos=(x_pos, y_pos), size=(0.1, 0.1),
color=[1, 1, 1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-3.0)
ClosedD_list.append(ClosedD)
for ClosedD in ClosedD_list:
ClosedD.setAutoDraw(True)
r_pos = random.uniform(-0.5, 0.5)
s_pos = random.uniform(-0.5, 0.5)
ClosedT = visual.ImageStim(
win=window,
name='ClosedT',
image='images/closed_t.png', mask=None, anchor='center',
ori=randint(1, 360), pos=(r_pos, s_pos), size=(0.1, 0.1),
color=[1, 1, 1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-3.0)
ClosedT_present = random.choice([0, 1])
if ClosedT_present == 0:
ClosedT.setAutoDraw(False)
else:
ClosedT.setAutoDraw(True)
window.flip()
P.S can provide further information if needed