Generating Shapes on top of Shapes using Mouse

Hello! I am currently struggling to figure out how to make this idea work, and I would love any input/feedback you all have.

So far, I have hard coded a bunch of potential positions these shapes can appear in. I am able to create a loop where rectangles appear in all locations by saying:

for p in all_pos:
    rect.pos = p; rect.draw(); win.flip()

This works totally fine and creates the following image on my screen:

I want my future participants to be able to click on a rectangle and a Gabor to appear within it. This is the part I am struggling with. All of the code is currently in a loop (e.g., for i in range(0, trials)), including this generation of rectangles. Currently, after the rectangle code, I have:

if mouse.isPressedIn(rect): 
    gabor.pos = rect.pos; gabor.draw(); keys = kb.waitKeys(keyList = ['return']); win.flip()

I have the waitkeys there to let the participants click on as many rectangles as they want. The issue I am running into is either the window flips too fast if the Gabors/mouse code is in the loop, or the Gabors don’t generate if it’s outside the loop.

Any input would be greatly appreciated! Thank you for your help!

Right now the Gabor only appears as long as the mouse is held down in the rectangle. If you want the Gabor to persist, you want a list of booleans tied to each rect that flips when the mouse is clicked in that rectangle, and the boolean is part of a loop that determines whether to draw the Gabor patch before the flip.

More generally, for something like this the way I like to do it is create an array at the start of your code which has all of the Rect objects in it, and then just cycle through that array in your flip loop, drawing each one, and calling flip only after going through the whole array. With a structure like that it’s very easy to create a second array of booleans or gabor patches and toggle whether they are drawn or not.

1 Like