you can;t even IMAGINE what it is


internet-janitor
@internet-janitor

Want to make your own scratch-off puzzles and toys in Decker? See below!


The Scratch-off effect relies on a transparent Canvas widget with drawings on the card background underneath. Make a new Canvas, name it c and set it to transparent by selecting it and clicking Widgets -> Show Transparent.

Next, we need to fill it with the gray scratch-off goop. Make a button and give it a script like so:

on click do
 c.clear[]
 c.pattern:colors.lightgray
 c.fill[]
end

Finally, the script for the canvas itself:

i:image["%%IMG0AA8ADwgAAAAggAQAQiAIgAyiGRARQGOiLADERBmACIAzAA=="]

on click pos do
 drag[pos]
end

on drag pos do
 i.merge[me.copy[pos-i.size/2 i.size]]
 me.paste[i pos-i.size/2]
end

The image i is a small splattering of black pixels (pattern 0) on a transparent background (pattern 1). If you want your ticket to scratch off faster or slower, you can make a larger/denser or smaller/sparser mask image. Just draw something in Decker, copy it to the clipboard, and then paste it into your script to get the %%IMG... string!

The click[] handler of our canvas ensures that we'll scratch off material even if the user only makes a single tap. The drag[] handler grabs the pixels of a region of the canvas, uses image.merge[] to preserve pixels already on the canvas where the mask image was pattern 0 and set all other pixels to pattern 0, making them transparent.

What applications can you come up with for this trick?


You must log in to comment.