scratchcardPercent.aia (260.6 KB)
It approximates percentage of the Canvas that is scratched updated every second based on a proven area estimation technique once commonly used in aerial mapping activities.
The Canvas Width is 800 pixels and the Canvas Height is 1132 pixels on the Samsung Tablet using Responsive Sizing. I did not test on smaller devices. Certainly the code may have to be adapted.
Attempt to count all the pixels, your device will probably crash (THAT IS 905,600 PIXELS for my tablet). Yes, I tried counting all the pixels using Blocks and got tired of waiting for the loop to conclude.
I counted every 50th row and column of pixels. That provides a pseudo random pixel sample of the total number of pixels in the Canvas. This small sample provides an estimate of the percent of image scratched.
The white area on the Canvas color is represented with an -1 .
I wrote an algorithm to count a sample of the white pixels using the Canvas.GePixelColor block. The algorithm works fine on my device. It may fail on other screen density devices. The sampling rate and value to determine 70% white pixels may have to be changed.
I tried several ways to sample. Originally I attempted to use all the points and make a total count of every pixel; impossible.
Next I attempted using a small sample of the total pixels in the Canvas. I sampled every 50 rows/columns where 736 counts represent a full white canvas (Canvas pixels are 100% white) A count of 515 represents about 30% remaining white sampling every 50 rows/columns (70% scratched). The aia example sampling samples every 50 rows/columns.
A larger sample (every 25 rows/columns) with 2944 counts points represent the near million actual pixels when the Canvas is 100% white. A count of 2061 represents about 30% remaining white pixels. Sampling every 25 column/rows using a Clock firing every second to monitor progress is slow but results in a slightly better estimate.
Sampling every 50 column/rows samples resolves the percentage fast and apparently is just as reasonable an estimate as denser sampling for most purposes. I believe the low resolution variant is about 95% accurate. The example code shows both examples. The example implements 50 columns/row. Keep in mind the diameter of a Canvas.Touched is 25 pixels in this example.
Image is from Wikipedia courtesy Kelvin Kay. Basic code is modification of code originally posted by Taifun in about 2014.
The estimation of percent screen scraped is my contribution. It is statistically correct and is based on the concept of a dot grid. Dot counts from an acetate overlay used to be the most widely used method of estimating area on aerial photographs. Dot grids allow calculation of area measurement by estimating. The concept is demonstrated in https://en.wikipedia.org/wiki/Dot_planimeter . Instead of counting the dots, I counted pixels and scaled the results for the size (area in pixels) of the Canvas. The results are pretty good if not precise.
What happens when you scratch about half the image? Something like this:
Regards and Merry Christmas, Wesołych Świąt, Feliz Navidad, God Jul, Joyeux Noel, Καλά Χριστούγεννα, Happy Christmas, Veseloho Rizdva, Prettige Kerstdagen, Frohe Weihnachten!, 성탄 축하 , Buon Natale, 聖誕快樂 , 圣诞快乐, Sretan Božić, C рождеством!, عيد ميلاد مجيد,
Steve

