Do any of you have any idea how to get the percentage fill of a canvas after drawing inside?
I would like to have a canvas of 50px x 50px for example, empty it will be at 0%, and the more I draw lines inside, the more the% will increase.
Thanks for your help !
Hopefully there are much more effective methods from other people but:
You could start from pixel 1 to the last pixel and check the pixel color. If it is white it is empty, if not then it is filled.
Yes I thought about it, but I can’t find the block that would allow me to determine if this or that pixel is filled.
And it may even be long, because if my canvas is 50x50 px …
But I keep the idea under the elbow, thank you!
Hi all !
I take the liberty of re-launching my question: how could I determine the percentage of fill of a canvas? And at the same time, display this percentage.
Thank you !
something like this (please excuse App Inventor blocks ):
I do not understand where to place the local variable initialization block …
I tried to edit and used another block as you can see in the picture:
And suddenly, it works, but it makes the Companion lag and then error and the companion closes.
Ah yes, I increased the size of the canvas, I found it small … So that must be why it is lagging, indeed! I will study it all, thank you again Tim !
If you make this happen when canvas dragged, it will lag a lot. Because a single drag runs the procedure many times.
If I understand correctly, I would then have to make a button, or when the dragging on the canvas is finished, and then trigger the procedure?
Yes, that would be better.
So, for the idea of the button, that’s perfect. I have a small amount of time but I imagine it’s normal the time it calculates the entire canvas area.
However, what I don’t understand is why I have 1% when the canvas is empty?
The text, I put it to 0.
I launch the app, click on the button, it calculates and it gives 1%.
I tried to change the number in the block (circled in the capture), putting 0, even if I filled the canvas it remains at 0%. I tried to put 5, and I got 3%.
How come ?
Do not know…
Testing canvases at 50x50 and 250x250 I get 0 (on AppInventor)
Try a Canvas.Clear, does that help ?
Or round the canvas width and height?
So, I tried with a 50x50 px, and I had 2% …
I tried to change the = sign for the color, instead of looking for a color other than white, I ask for a color equal to black, and it seems to work.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.