GML Getting the % of the drawn area of a surface

D

Dawn

Guest
Let's say

1) There's an empty (or white) area/surface.

2) Clicking on any point inside it will draw a circle (or any shape) of a certain size on it.

3) The screen shows (filled area/whole area)

So it's like a paint brush and the system need to get the % of the painted area. Through what method can I achieve this?
 

NightFrost

Member
You know the positions and other measurements, so you can calculate the size of the drawn area, and from there the percentage it takes of the entire area. A rectangle draw to (10, 10, 20 ,20) is 10x10 or 100 pixels, so on a 100x100 draw area that would be 100 / 10000 = 0.01 or 1%.
 

chamaeleon

Member
Let's say

1) There's an empty (or white) area/surface.

2) Clicking on any point inside it will draw a circle (or any shape) of a certain size on it.

3) The screen shows (filled area/whole area)

So it's like a paint brush and the system need to get the % of the painted area. Through what method can I achieve this?
Copy the surface to a buffer and iterate through it, counting the number of times a byte in a group of 4 (to account for RGBA/BGRA/whatever) is not zero (or whatever kind of threshold you intend to apply to a give pixel). No idea how inefficient it would be to run continuously (assuming you want to update the % every step, etc.) Percentage calculation should be trivial if you make that work.

Another option could be to use a shader to count for you (https://stackoverflow.com/questions/29352965/shader-for-counting-number-of-pixels, for inspiration).
 
Top