Download the PHP package stui/bestagons without Composer
On this page you can find all versions of the php package stui/bestagons. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stui/bestagons
More information about stui/bestagons
Files in stui/bestagons
Package bestagons
Short Description PHP Library for creating hexagonal maps
License GPL-3.0-or-later
Informations about the package bestagons
Bestagons is a PHP library for creating and managing hexagonal maps using axial and cube coordinates. It is based on the excellent hex grid logic and algorithms from Red Blob Games.
Installation
You can install the package via Composer:
Usage
The Hex Class
The Hex class represents a hexagon in a grid.
It can be represented using axial coordinates ($q$, $r$) or cube coordinates ($q$, $r$, $s$). Bestagon can handle both and in fact will always store cube coordinates internally.
Equality
Coordinate arithmetic
Distance and Neighbors
For help with directions, please see here.
For a quick reference, the directions - expressed in cardinal directions - are:
| Pointy Top | Flat Top | |
|---|---|---|
| 0 | East | South-East |
| 1 | North-East | North-East |
| 2 | North-West | North |
| 3 | West | North-West |
| 4 | South-West | South-West |
| 5 | South-East | South |
Fractional Hex and Rounding
Useful for operations like linear interpolation between two hexagons.
Maps
The Map class allows you to store and retrieve hexagons.
Rectangular Maps
A shape of map that generates a rectangular grid of hexagons.
The params define how far out the rectangle generates from the base point.
Credits
All logic and algorithms in this library are based on the work of Amit Patel at Red Blob Games.
If you want to understand the math behind hex grids, that is the place to go.
License
The GPL-3.0-or-later. Please see License File for more information.