Crates.io | hex_grid |
lib.rs | hex_grid |
version | 0.2.1 |
source | src |
created_at | 2018-01-01 23:17:42.428392 |
updated_at | 2019-10-28 21:29:55.655544 |
description | A library to easily work with 2d hex grids of arbitrary shapes |
homepage | |
repository | https://github.com/fuchsnj/hex_grid |
max_upload_size | |
id | 45154 |
size | 14,178 |
A library to easily work with 2d hex grids of arbitrary shapes. This library currently only supports "Pointy Top" hexagons.
Add this to your Cargo.toml
:
[dependencies]
hex_grid = "*"
and this to your crate root:
extern crate hex_grid;
use hex_grid::*;
use std::collections::HashMap;
struct CustomData{
//..whatever data you want associated with each tile
}
//empty grid
let mut grid: HashMap<Coordinate, CustomData> = HashMap::new();
//fill the grid with tiles in a hexagon shape of size 3
let coords = CENTER + Offset::fill_hex(3);
for coord in coords {
let data:CustomData = //...
grid.insert(coord, data);
}
//get the tile that is to the right 2 tiles from the center tile
let tile:Option<CustomData> = grid.get(CENTER + RIGHT*2);