Create an event for a scratch card

Hello everyone,

I was inspired by the @Taifun app to create a scratch card.

How is it possible to create an event when 70% of the web is discovered?

Thank you all

Possibly that is not possible. What you could do is count the total pixels in the image ; then you know total pixels. Then count the number of white pixels (or whatever background color you use) continually by polling use a Clock . When whitepixels/totalpixels = 0.70 then do something. You might be able to adapt the code here> Scanner color pixel - #2 by Alpha2020 to perform the pixel color polling.

Others may have other ideas. The above suggestion is awkward and perhaps impractical so hope someone else posts another idea.

try this extension



I had seen this extension but it is not free.
Thank you.



yes the idea is not bad. I will test.
Thank you.


No, that's not possible. The image is the background of the canvas.

I was thinking more of a function saying: when 70% of the canvas is transparent (color code 255,255,255,0 created to make the effect transparent with the finger) then do such an event.

Maybe @Taifun could help me.


Are you sure Fred?

This seems to do what you want to do. :slight_smile Read the title bar.



wow how did you do it?
Am curious to see the blocks.

The algorithm is simple and it works with my tablet. I'll post something later today. Quite busy with other things at the moment. I need to clean up the code and I would like to see if I can get the algorithm to calculate percent white screen to work with any screen size.

I'm betting it will be a polygon algorithm, given the rectangular strokes in @SteveJG's sample image.

The example aia shows a simple way to determine/estimate the percent of a Canvas that is 'scratched' using Blocks. It runs on an Android 8.1 tablet.
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 . 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 рождеством!, عيد ميلاد مجيد,



For a problem like this, statistics trumps geometry.

I wonder how quickly the percentage would converge if the test dots were randomly placed on the fly?

1 Like

Hello @SteveJG,

So there I say bravo, bravo, bravo.
It's Christmas before its time.

Thank you I will test to adapt on my project.

Thanks again. You are awesome.

1 Like

You can try this

Press Button2 to create a list of pseudo random Canvas coordinates. I created 736 to be more or less congruent with the example total coordinates.

Press Button3 to estimate percentage (sorry, did not link to the Clock)

Stop wondering you can experiment Abraham. :slight_smile: I would initially vary (increase) the number of coordinate sets from 736 to larger and larger values and see where it breaks. :cry:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.