Exemple #1
0
#!/usr/bin/env python3

from page087_mask import Mask
from page088_masked_grid import MaskedGrid
from recursive_backtracker import RecursiveBacktracker
import sys

if len(sys.argv) != 2:
    raise Exception('Please specify a PNG image to use as a template')
mask = Mask.from_png(sys.argv[1])
grid = MaskedGrid(mask)
RecursiveBacktracker.on(grid)

filename = 'masked.png'
grid.write_png(filename, cell_size=5)
print('saved image to', filename)
Exemple #2
0
                if color:
                    xfw, xnw, xne, xfe, yn, yc, ys = coords_for_cell(cell)
                    points = [(xfw, yc), (xnw, yn), (xne, yn), (xfe, yc),
                              (xne, ys), (xnw, ys)]
                    draw.polygon(points, fill=color)

        for cell in self.each_cell():
            xfw, xnw, xne, xfe, yn, yc, ys = coords_for_cell(cell)

            if not cell.southwest:
                draw.line([xfw, yc, xnw, ys], WALL_COLOR, WALL_PIXELS)
            if not cell.northwest:
                draw.line([xfw, yc, xnw, yn], WALL_COLOR, WALL_PIXELS)
            if not cell.north:
                draw.line([xnw, yn, xne, yn], WALL_COLOR, WALL_PIXELS)

            if cell.has_boundary_with(cell.northeast):
                draw.line([xne, yn, xfe, yc], WALL_COLOR, WALL_PIXELS)
            if cell.has_boundary_with(cell.southeast):
                draw.line([xfe, yc, xne, ys], WALL_COLOR, WALL_PIXELS)
            if cell.has_boundary_with(cell.south):
                draw.line([xne, ys, xnw, ys], WALL_COLOR, WALL_PIXELS)

        img.save(name, 'PNG')


if __name__ == '__main__':
    maze = HexGrid(35, 35)
    RecursiveBacktracker.on(maze)
    maze.to_png(name='hex.png', mode='color')
Exemple #3
0
from recursive_backtracker import RecursiveBacktracker
from grid import Grid

grid = Grid(20,20)
RecursiveBacktracker.mutate(grid)

grid.to_string()
grid.to_svg()
Exemple #4
0
from recursive_backtracker import RecursiveBacktracker
from grid import Grid

grid = Grid(15,15)
RecursiveBacktracker.mutate(grid, True)

grid.to_string()
grid.to_svg()
#!/usr/bin/env python3

from grid import Grid
from recursive_backtracker import RecursiveBacktracker

grid = Grid(5, 5)

grid[(0, 0)].east.west = None
grid[(0, 0)].south.north = None
grid[(4, 4)].west.east = None
grid[(4, 4)].north.south = None

RecursiveBacktracker.on(grid, start_at=grid[(1, 1)])

print(grid)