I need to create a routine with around 100 rectangles in a fixed position (all in a horizontal line at a fixed distance). These rectangles should be clickable (e.g. they should change color when the participant clicks on them, but that part is not an issue).
I can use 100 polygon component inside the builder, but I guess that there is a better way to draw all 100 polygon using a code component. I tried looking around the forum and I think I should use DotStim, but I am not sure how.
Does anyone have an example on how to code a large amount of polygons being drawn?
#in the Begin Experiment Tab
def makeSquare(pos):
square = visual.ShapeStim(win=win, pos=pos, size=(0.015605, 0.21), fillColor=[1, 1, 1], lineColor=[-1, -1, -1], vertices='rectangle')
square.setAutoDraw(True)
return square
#in the Begin Routine Tab
for i in range (100):
x = (-0.7731975 + 0.015605*i)
makeSquare((x, -0.03445))
I have a couple of problems:
How do I clear the rectangles at the end of the routine?
I need to have the rectangles to appear over a background image, but they are always drawn under it, even if i move the code component below the image. Is there a way around this?
I need to identify each rectangle in a unique way, so I can write a piece of code for what happen when I click on them. How should I do this?