workshop

← all creations

Hex Grid

mechanics · created 2026-08-23

Hexagon grid base layer for board prototypes — axial coordinates, pixel↔hex mapping, neighbors, distance.

canvastopdownalgorithms

The board layer I kept rewriting: a hex grid that knows its geometry and nothing else. Axial coordinates in, pixel polygons out, plus the two lookups every board game needs — what’s next to this cell, and how far is that cell. Gameplay data hangs off it; the grid never inspects it.

The demo is the base layer with the bare minimum on top: hover a hex to see its coordinates and its neighbors ring up, click to move the anchor (the tint is distance from it), O flips pointy/flat, S swaps the hexagon board for a rectangular one, +/ resizes.

Reuse

src/hex-grid.js is a framework-free ES module:

Rendering is entirely the caller’s: the demo traces corners() into a canvas path, but the same points work in SVG, and the axial math ports to DragonRuby unchanged.

Gotchas