Displaying a Hex Grid
Learn to display a hex grid on the console in Ruby.
We'll cover the following
Displaying a hexagon grid using corner coordinates
To display a hex grid, we need to be able to compute the coordinates of each of its corners or vertices. We’ll see how to compute those coordinates relative to the center of each hexagon, as well as how to compute the overall dimensions of a hex grid, and then we’ll plug that all into a new to_png
implementation.
We’re going to assume that our grid is composed of regular hexagons (hexagons whose sides are all the same length). With that assumption, there is a small derivation involving equilateral triangles (triangles whose sides are all equal) that lets us get the measurements we need. In the context of this course, we’ll skip the derivation itself, but you are encouraged to try it yourself.
Essentially, what we want are lengths of
Get hands-on with 1400+ tech skills courses.