Drawing in code dumbbell and illusory contours shapes

Hello all. Could someone please help me on the issue of drawing dumbbell shaped stimuli in code and stimuli that follow the same dumbbell structure but instead create a Kanitza type illusory contour (see image). I would like to be able to vary all parameters of the stimuli, the distance between the circles, the bar in between, color, orientation, size, etc. I’ve ended up generating the stimuli as a vector graphics and import them via visual.ImageStim, but in this manner the designs are not very flexible and each time I want to change a parameter, I need a new set of graphics designed separately and pngs. Also I would like to be able to draw in code a single notched circle as shown in the second image. Any ideas on how to draw these shapes? Thank you!

Screen Shot 2022-02-11 at 14.28.55
Screen Shot 2022-02-11 at 14.35.15

While I could create the vertices for an arbitrary dumbbell in code, it’s not possible to create the illusory figure as a single polygon so I’d recommend putting a white or black rectangle in front of one or two circles.

Edit. Of course the illusionary figure is possible if the background is drawn instead of the two figures.

Thank you for taking the time. I considered the idea rectangle over disks to get to the same outcome, and I succeeded in putting it programmatically, but the stimulus dimensionally has to be measured as a “whole” object rather that 3 separate ones (one.draw() rather than three.draw()), because it has to be randomly positioned on the screen each win.flip() as a single object. Regarding the vertices, I would be very grateful if you could share the code with me. The idea with the background drawing is interesting, I will give it a try.

Positioning as one object is fine if you set the coordinates of the centre in code and then position the object using those coordinates with appropriate offsets.

Hello. Finally I managed to program a random stimuli generator that uses external png images as input to randomly generate pattern consisted of single floating inducers, but also of a pair of inducers that form illusory contours. So each element here actually is a png picture generated offline and imported into code with ImageStim module. I’m getting closer to the design I want, however, one last challenge is to code some sort of a “checker” that checks for the positions image elements and if it each overlaps some other element (or breaks the some sort of a minimum distance rule), should be able find a new random location before it draws. I’m attaching and example. In this particular generated pattern, the three illusory contours (seeded from an offline designed png image) are showing correctly, without any overlap, however, the one in the red overlaps with another single inducer element.

I know theoretically, that I need to find the center position of each element and then it’s radius maybe, and then set some code that will check the distance from the center of another element and recalculate position if collides before it draws the stimulus, but since I’m fairly new in using PsychoPy programmatically, seem little advanced to me at the moment. Could anyone help me out with the code part that check for the randomly selected position of one element image and then redraws the new one with another location in case they overlap?

Screen Shot 2022-02-13 at 18.11.49

The way I solve this problem is to create a list of coordinates of a grid on the screen, with each point jittered enough to break up the grid pattern but not enough for adjacent elements to be able to overlap. Then I shuffle the coordinates and use the first N values.