# Looking for a square-to-hex pixel coords algorithm

So as the headline suggests, I am looking for an algorithm/algorithms used for square-to-hex and hex-to-square pixel coordinates convertion.

I have an image which looks kinda "interpolated", meaning some pixels are of one colour, while some have a slightly different shade etc. So pixel colour kinda stores offset or whatever. If you're interested, it's here

It has to do with pathfinding, the logical part of map is made of hexmap while the visual part of map is made of squares. Here, size of the square = 1 pixel, same hex size is equal to 1 pixel.

So basically I will be trying to convert an image with hex pixel coords to image with square pixel coords and vise versa.

I'm sorry if this was answered already somewhere, I couldn't find it anywhere.

P.S. I reverse engineered the image, so in binary it was only X and Y coords stored plus a third byte value which I took as a greyscale colour (later compared with another image and it matched)

Image:

• I'm having difficulty understanding your question. Could you elaborate please? You have an image which you also linked, which is square (regardless of its contents) and you are trying to turn that into a hexagonal shape? Is that what the question is about? I'm not sure I understand what "size of the square = 1 pixel, same hex size is equal to 1 pixel" means. Could you describe what's the end goal? What do you want your game to look like at the end, and why did you pick this process? – TomTsagk Jul 29 '18 at 14:49
• @TomTsagk yes im sorry for being unclear. So that image is hex-to-pixel image. It means it originated as square to pixel image and then square coordantes were converted into hex coordinates and then hex coordinates were put into image - hence hex-to-pixel. So a a result of putting hexes to pixel we have different pixels have various colours ranged from 1 to 64 (in greyscale), so I thought it might be some kind of alpha or weight – Mr Jox Jul 29 '18 at 16:33
• I'm unable to view this image on mobile. Can you embed it in the question itself rather than linking to Imgur? – DMGregory Jul 29 '18 at 17:42
• @DMGregory done – Mr Jox Jul 29 '18 at 17:53