This stackoverflow question asks about coloring a hex grid. 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.