Skip to content

Sample code for working with regular hexagon and triangle grids

License

Notifications You must be signed in to change notification settings

Francois-Rolland/gridstriangles

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid Co-ordinate Reference Calculations

This repo contains sample code for working with regular hexagon and triangle grids.

It's been written as clearly and compactly as possible, to serve as a tutorial and reference for how to work with these grids. There's many different co-ordinate systems for working with grids - this guide only covers the systems that are easiest to work with, and convert between.

Available Grids

Usage

The code here focuses on keeping the methods as readable as possible. In real life usage, I'd recommend using classes to represent a cell and the grid as a whole.

The code uses a three-coordinate system for referring to hexes and triangles. This is simplest for working with in memory, but it's not a good format for storage. You can use methods like hex_rect_index/hex_rect_deindex to convert from co-ordinates to/from a single integer that addresses the cells starting at 0 and counting upwards without gaps, allowing you to store cell values efficiently in a 1d array or file.

Note that some important grid methods, like path finding, are not included. These methods are the same for any type of grid, you can find good references elsewhere.

Ports

If you port this code to other languages, let me know and I'll keep a list here. You should document what date the porting was done as a simple versioning scheme.

About

Sample code for working with regular hexagon and triangle grids

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%