In my game, I want to layout squares along the edges of a monochrome image:
So I found this algorithm which should solve the issue. http://en.wikipedia.org/wiki/Marching_squares
It does not seem that hard to implement, I just think I do not understand exactly what Wiki is saying. I think I have to break the image up into cells where each cell represents 2x2 pixels on the image? Is that correct? I'm then lost by this instruction:
For each cell in the contouring grid:
1.Compose the 4 bits at the corners of the cell to build a binary index: walk around the cell in a clockwise direction appending the bit to the index, using bitwise OR and left-shift, from most significant bit at the top left, to least significant bit at the bottom left. The resulting 4-bit index can have 16 possible values in the range 0-15.
I'm not sure how to appending the bit.
Thanks
After you create the 2x2 cells, for each one you compute a number like this:
Edited formatting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With