Excerpt from Cambridge Dictionary, a scratch card is as defined below.
a small card that you can buy to try to win a prize, with a thin layer that you rub off in order to see if you have winning numbers on it.
A scratch card which has 3 * 3 reward image list, the final reward for user will appears 3 times, as for other reward, they will appears 2 times or below.
Un-scratch | Scratched |
---|---|
touchstart
, touchmove
, touchend
Desktop: mousedown
, mousemove
, mouseup
destination-out
while drawing brush image on canvas.Here are some nice libraries to learn how to implement scratch card feature.
It's fine to use library if a scratch card contains single image to calculate show-up mechanism. However, if it contains a 3 * 3 grid images to calculate show-up mechanism (e.g. same image shows up 3 times), then I'd better customize it by myself.
I won't explain all the details to build a scratch card since there are already multiple articles and libraries to teach how to build a simple scratch card step by step.
Let's focus on the tricky part of the 3 * 3 grid images scratch card.
Scratch wrapper will be covered by foreground canvas, and background template can be customized.
If multiple image sources are required, it's good to use a promise to make sure an image before canvas initialization.
How to calculate whether each grid is opened
p.s. For the grid index calculation, it's almost the same with leetcode problem 36. Valid Sudoku but the grid is larger.
How to keep scratch trace:
Work
Scratch Card
Vue3