Skip to main content


Example on how to implement a pixel-to-hexagon-map-location algorithm.

John Eriksson
Using hexagon based maps is not as easy as using square maps. Mostly because it takes more effort to translate pixel locations (like mouse clicks) to map locations. When I search this issue on the net I found a really nice article explaining a technique to solve this matter with mathematics. But I wanted to have a pixel-perfect pixel-to-map algorithm so I used the article as a base and implemented a way to solve this.

Based on the assumption that if I needed this then probably someone else need it I wrote this little example to show how a pixel-to-hexagon-map can be implemented in python/pygame.

Example Instructions

When you move around the mouse pointer the application will translate the mouse location to a hexagon map location and show this with a yellow hexagon.

Press space to toggle the display of the help grid square. You can use this to get a better understanding of the source code.



Home Page


HexagonExample 1.0 — 27 Apr, 2006 account Comments

  • Mee Master 2013-07-26 14:02

    The way shown here is not good enough, since it is based on predefined matrix of hexes. I found a better method, which is more universal and works for every hex tile size. Mail me if you wish an example

    Divided By Zer0 2019-04-11 16:50

    If you're still around, I could also use an example, since the original source is down

    Samuel 2020-07-01 14:51

    Hi, can you send me a example? sboorbou at hotmail.

    mhillis 2013-10-08 13:08

    can you send me the example?

    Pushpen 2013-08-31 12:15

    Hi, Can you send me an example? My email address is pushpen.paul.ndp at gmail dot com

  • user012 2014-11-19 14:46

    The source code link is broken. Can someone help me?? Plz