Skip to main content

Hexagonal Map

http://www.redblobgames.com/grids/hexagons/

Hexagonal grids are used in some games but aren’t quite as straightforward or common as square grids. I’ve been collecting hex grid resources for nearly 20 years, and wrote this guide to the most elegant approaches that lead to the simplest code, largely based on the guides by Charles Fu and Clark Verbrugge. I’ll describe the various ways to make hex grids (I’ve counted 74 so far!), the relationships between them, as well as some common algorithms. Many parts of this page are interactive; choosing a type of grid will update diagrams, code, and text to match.
  1. Angles, size, spacing, drawing
  2. Coordinate systems
  3. Coordinate conversions
  4. Neighbors
  5. Distances
  6. Line drawing
  7. Range
  8. Rotation
  9. Rings
  10. Field of view
  11. Hex to pixel
  12. Rounding to nearest hex
  13. Pixel to hex
  14. Map storage
  15. Wraparound maps
  16. Pathfinding
  17. More reading
The code samples on this page are written in pseudo-code; they’re meant to be easy to read and understand so that you can write your own implementation.

Comments

Popular posts from this blog

Logic Analyzer with STM32 Boards

https://sysprogs.com/w/how-we-turned-8-popular-stm32-boards-into-powerful-logic-analyzers/ How We Turned 8 Popular STM32 Boards into Powerful Logic Analyzers March 23, 2017 Ivan Shcherbakov The idea of making a “soft logic analyzer” that will run on top of popular prototyping boards has been crossing my mind since we first got acquainted with the STM32 Discovery and Nucleo boards. The STM32 GPIO is blazingly fast and the built-in DMA controller looks powerful enough to handle high bandwidths. So having that in mind, we spent several months perfecting both software and firmware side and here is what we got in the end. Capturing the signals The main challenge when using a microcontroller like STM32 as a core of a logic analyzer is dealing with sampling irregularities. Unlike FPGA-based analyzers, the microcontroller has to share the same resources to load instructions from memory, read/write th...

Why Those Who Overcame Poverty Have Less Sympathy for the Poor

https://www.psychologytoday.com/us/blog/psychology-money-and-happiness/202207/why-those-who-overcame-poverty-have-less-sympathy-the/amp The surprising science behind our attitudes toward those in poverty. Posted July 19, 2022 Reviewed by Ekua Hagan Key points People often use shortcuts, such as vivid stories of someone they personally know, to decide how to judge others living in scarcity. One study found that those who "became rich" had less sympathy for those currently experiencing poverty than those who were "born rich." Steve Jobs is an example of a wealthy public figure who came from humble beginnings and was notoriously un-philanthropic. We all love an inspiring success story where the protagonist overcomes adversity, defeats any and all obstacles that stand in the...