Skip to content

Latest commit

 

History

History
60 lines (41 loc) · 2.14 KB

README.md

File metadata and controls

60 lines (41 loc) · 2.14 KB

hexpy

The purpose of hexpy is a hobby project that eases working with hexagonal grids in python, focusing on readable code which should be easy to use.

hexpy logo

Note: This work has been heavily inspired by the beautiful work of redblobgames, who provide a fantastic post about ways to represent hexagonal grids with both illustrations and code examples.

Usage

Work in progress

  • Creation

  • Navigation

Since I personally found it quite challenging to wrap my head around navigating in hexagonal grids using the cube coordinate system, i wrote code and created visualizations that should make it somewhat easier.

For instance the clock- and angle-system by Hex Chogi featured in Hexagonal chess was the inspiration for the visualizations below.

Pointy Hexclock Regular Clock Flat Hexclock
Pointy Hexclock Regular Clock Flat Hexclock

These systems can be accessed once a layout has been defined (if a custom one is used it defaults to pointy).

>>> from hexpy import Hex

>>> Hex.pointy_layout(10)

>>> # Direct neighbor
>>> Hex.hexclock(1)
Hex(q=2, r=-1, s=-1)

>>> # Diagonal neighbor
>>> Hex.o_clock(2)
Hex(q=1, r=0, s=-1)

>>> # Also for instances:
>>> h = Hex(1, 0)
>>> h.hexclock