Draw within a cricle

Hi,

I was wondering is there any way to draw within an circle? I want to draw multiple shapes at random positions within the green area. Is there any good way to do this?

Hi! One way would be to use a mask. You could draw that donut in white color with black background onto an FBO, get the texture, and use it to set the mask of another FBO in which you draw your shapes.

If you don’t want to clip your drawings, but instead want to calculate the positions of objects so they land in that green area, if you know the radius of your objects it’s quite simple: you can position your objects using polar coordinates, specifying a random angle around the center point and a distance to that point. The distance should be larger than the inner edge, and smaller than the outer edge, and take into account the radius of the object you’re adding so it’s not partially out of the green area.

Ah yes, thank you!