Class: SquareGrid
- Includes:
- AsciiToGrid, GridToPic
- Defined in:
- lib/hex/square_grid.rb
Overview
This class represents a grid of hexagons stored in an axial coordinate system but manage the conversion to a square representation (what finally you want)
Instance Attribute Summary
Attributes inherited from AxialGrid
#half_height, #half_width, #hex_height, #hex_ray, #hex_width, #quarter_height
Instance Method Summary collapse
-
#cget(col, row) ⇒ AxialHex
Get the hexagon at a given position (col, row).
-
#cset(col, row, color: nil, border: false, data: nil) ⇒ AxialHex
Create an hexagon at a given position (col, row).
-
#initialize(hex_ray: 16, element_to_color_hash: {}) ⇒ SquareGrid
constructor
Create an axial hexagon grid.
Methods included from GridToPic
Methods included from AsciiToGrid
Methods inherited from AxialGrid
#each, #h_surrounding_hexes, #hex_at_xy, #hget, #hset, #set_element_to_color_hash, #to_xy
Constructor Details
#initialize(hex_ray: 16, element_to_color_hash: {}) ⇒ SquareGrid
Create an axial hexagon grid
26 27 28 29 30 |
# File 'lib/hex/square_grid.rb', line 26 def initialize( hex_ray: 16, element_to_color_hash: {} ) super( hex_ray: hex_ray ) @element_to_color_hash = element_to_color_hash set_hex_dimensions end |
Instance Method Details
#cget(col, row) ⇒ AxialHex
Get the hexagon at a given position (col, row)
53 54 55 |
# File 'lib/hex/square_grid.rb', line 53 def cget( col, row ) hget( even_q_to_axial_hex( col, row ) ) end |
#cset(col, row, color: nil, border: false, data: nil) ⇒ AxialHex
Create an hexagon at a given position (col, row)
42 43 44 |
# File 'lib/hex/square_grid.rb', line 42 def cset( col, row, color: nil, border: false, data: nil ) hset( even_q_to_axial_hex( col, row, color: color, border: border, data: data ) ) end |