Search⌘ K
AI Features

Getting Deep into Weaves and Insets

Explore how to design and render weave mazes by implementing inset coordinates and drawing walls with gaps between cells. Understand techniques to control corridors and walls in complex maze grids, improving your ability to generate visually distinct and functional mazes.

Let’s look at our new to_png method.

The to_png_without_inset method

Ruby 3.1.2
def to_png_without_inset(img, cell, mode, cell_size, wall, x, y)
x1, y1 = x, y
x2 = x1 + cell_size
y2 = y1 + cell_size
if mode == :backgrounds
color = background_color_for(cell)
img.rect(x, y, x2, y2, color, color) if color
else
img.line(x1, y1, x2, y1, wall) unless cell.north
img.line(x1, y1, x1, y2, wall) unless cell.west
img.line(x2, y1, x2, y2, wall) unless cell.linked?(cell.east)
img.line(x1, y2, x2, y2, wall) unless cell.linked?(cell.south)
end
end

This should be quite familiar—it’s almost the same as what was originally within the each_cell block from our old to_png method. It just computes the northwest and southeast corners of the cell and draws the corresponding walls.

Next, we’ll implement our formulas to find the coordinates of those ...