Skip to content

grant/hexgrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hexgrid

A hexagonal grid layout. This prototype is flexible abstraction layer for hexagaonal grids.

npm install hexgrid --save

Uses axial/trapezoidal coordinate space with pointy-top hexagons

  • Increasing x goes right
  • Increasing y goes bottom right

Examples

// Init the hexgrid
var Hexgrid = require('hexgrid');
var grid = new Hexgrid({
  size: 20
});

// Add a hexagon cell
var firstCellPoint = new Point(1, 2);
var firstCell = new Hexcell(firstCellPoint);
grid.add(firstCell);

Methods

Hexgrid.add(hexcell)

Adds a cell to the grid

Hexgrid.remove(point2d)

Removes a grid cell at point2d

Hexgrid.get(point2d)

Gets a hexcell at point2d

Hexgrid.getXY(point2d)

Gets the calculated x and y (based on the hexagonal grid) of a point

Hexgrid.isEmpty(point2d)

Returns true if there is no hexcell at point2d

Hexgrid.getHexcells()

Returns an array of all hexcells

About

A hexagonal grid

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published