Getting Deep into Weaves and Insets
Learn to display a weave maze on the terminal.
Let’s look at our new to_png method.
The to_png_without_inset method
Press + to interact
def to_png_without_inset(img, cell, mode, cell_size, wall, x, y)x1, y1 = x, yx2 = x1 + cell_sizey2 = y1 + cell_sizeif mode == :backgroundscolor = background_color_for(cell)img.rect(x, y, x2, y2, color, color) if colorelseimg.line(x1, y1, x2, y1, wall) unless cell.northimg.line(x1, y1, x1, y2, wall) unless cell.westimg.line(x2, y1, x2, y2, wall) unless cell.linked?(cell.east)img.line(x1, y2, x2, y2, wall) unless cell.linked?(cell.south)endend
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 dashed horizontal and ...
Ask