Let’s say you have an array of blocks that you want to draw to a canvas. Let’s also say you want to compute the (x,y) coordinates of a specific item in the array. There’s a formula for that:
All this does is count up to the index taking into account the fact you need to wrap blocks of a certain size.
If you don’t need a specific block size and are just using single pixels as a block size, then the formula becomes even simpler: