Snap-to-grid using the Math remainder block

182 views
Skip to first unread message

Scott Ferguson

unread,
Apr 17, 2014, 7:59:33 AM4/17/14
to app-inventor-de...@googlegroups.com


This formula uses the Math remainder block to do snap-to-grid.
It may be a bit more efficient than the previous one which used the Math quotient block.
I also find that it is easier to understand how it works.

As the checker piece moves between the 40-pixel-wide grid squares the remainder of currentX / 40 will vary from 0 to 39.
Subtracting that from the currentX will give the snap-to-grid location for the checker piece x value.
The process is repeated for the checker piece y value

For example, given that:

- a particular square starts at x = 80
- and each square on the checkerboard is 40 pixels wide
- checker piece currentX = 85

then:

x = currentX - remainder(currentX / 40) 
x = 85 - remainder(85 / 40)
x = 85 - 5
x = 80

SnapToGridRem.aia
Reply all
Reply to author
Forward
0 new messages