Page 2 of 2

Re: Drawing the 'Negative' of a circle.

Posted: Sat Nov 19, 2022 8:48 pm
by pgimeno
darkfrei wrote: Fri Nov 18, 2022 9:44 pm It looks very nice! I cannot right now look how it works, can you please in short explain that?
Screenshot_20221118-224212.jpg
Sure, it's simple. The circle was created with GIMP. It has R, G and B components all 1.0 (255) everywhere. The alpha component contains the circle. This is the image superimposed on a chequered light/dark grey background to see the transparency:
Chequered-Hole.png
Chequered-Hole.png (34.79 KiB) Viewed 520 times
This circle is drawn in multiply mode on a canvas. The canvas has typically alpha = 1.0 everywhere, and any desired image (in this case a black image). When the R, G and B components (all 1) of the circle are multiplied by the corresponding values in the canvas, you don't change the canvas' colour; and when the alpha of the canvas (all 1) is multiplied by the circle, you get the circle's alpha. So you get an image with the RGB of the canvas, and the A of the circle.

In this case I'm drawing the canvas to the screen with a bit of transparency so that it darkens without totally blackening, producing a darkness effect.

What puzzles me is why the canvas does not cover the whole image in mobile. I create it with love.graphics.newCanvas() (no parameters) and draw it without position (hence defaulting to 0,0) so it should cover the whole drawing area.