Hexagon coloring

 from Red Blob Games
09 Jan 2019

This stackoverflow question asks about coloring a hex grid[1]. You can subtract any two coordinates and then mod by 3 to get the color:

Note that % is not the mod operator in some languages. You'll need ((q-r)%3 + 3) % 3 to calculate mod 3. Further reading: mod and remainder are not the same[2].

Email me , or tweet @redblobgames, or comment: