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(q, r) ⇒ AxialHex
Get the hexagon at a given position (q, r).
-
#cset(q, r, color: nil, border: false, data: nil) ⇒ AxialHex
Create an hexagon at a given position (q, r).
-
#initialize(hex_ray: 16, element_to_color_hash: {}) ⇒ SquareGrid
constructor
Create an axial hexagon grid.
Methods included from GridToPic
#to_pic, #to_rmagick_image, #to_xy
Methods included from AsciiToGrid
Methods inherited from AxialGrid
#each, #h_surrounding_hexes, #hget, #hset, #set_element_to_color_hash, #to_json
Methods included from AsciiToGridFlat
#read_ascii_file_flat_topped_odd, #write_ascii_file_flat_topped_odd
Constructor Details
#initialize(hex_ray: 16, element_to_color_hash: {}) ⇒ SquareGrid
Create an axial hexagon grid
27 28 29 30 31 |
# File 'lib/hex/square_grid.rb', line 27 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(q, r) ⇒ AxialHex
Get the hexagon at a given position (q, r)
54 55 56 |
# File 'lib/hex/square_grid.rb', line 54 def cget( q, r ) hget( even_q_to_axial_hex( q, r ) ) end |
#cset(q, r, color: nil, border: false, data: nil) ⇒ AxialHex
Create an hexagon at a given position (q, r)
43 44 45 |
# File 'lib/hex/square_grid.rb', line 43 def cset( q, r, color: nil, border: false, data: nil ) hset( even_q_to_axial_hex( q, r, color: color, border: border, data: data ) ) end |