Implementing a Hex Grid

Learn to implement a hex grid by introducing a new subclass in Ruby.

Introduction

When we take a surface and divide it up into different shapes, with no gaps between them and no overlaps, we get what is called a tessellation of the surface. Our standard grid is one such tessellation, where we’ve broken up a flat area, or plane, into smaller squares. Another way to say this is that we’ve tiled the plane with squares.

It turns out that squares aren’t the only shape that can do this for us. We’ll see how hexagons come together in a honeycomb pattern, and triangles form a girder-style lattice. We’ll use these new grids to turn out mazes like the following:

Get hands-on with 1200+ tech skills courses.