Exemplo n.º 1
0
def generic_maze(**kwargs):
    supershape = kwargs.pop('supershape', None)
    grid = pmz.PolyGrid(supershape=supershape)
    if 'complexity' not in kwargs:
        kwargs['complexity'] = .5  # speed things up when possible
    grid.create_rectangle(**kwargs)
    return pmz.Maze(grid)
Exemplo n.º 2
0
 def test_image_returns_None_for_empty_grid(self):
     # make and confirm an empty grid
     empty_grid = pmz.PolyGrid()
     self.assertEqual(len(tuple(empty_grid.shapes())), 0)
     # confirm image is None
     maze = pmz.Maze(empty_grid)
     self.assertIsNone(maze.image())
Exemplo n.º 3
0
def image_maze():
    image = PIL.Image.open(os.path.join(_image_directory, 'globe_source.png'))
    supershape_name, supershape = next(_supershapes_cycle)
    grid = pmz.PolyGrid(supershape=supershape)
    grid.create_from_image(image, complexity=100)
    maze = pmz.Maze(grid)
    filename = os.path.join(_image_directory,
                            'Globe ({}).png'.format(supershape_name))
    maze.image().save(filename, format='PNG')
    print('Saved {}'.format(filename))
Exemplo n.º 4
0
def unicode_string_maze():
    s = u'迷\\n路'  # note literal \n is interpreted as newline
    supershape_name, supershape = next(_supershapes_cycle)
    grid = pmz.PolyGrid(supershape=supershape)
    grid.create_string(s, complexity=20)
    maze = pmz.Maze(grid)
    filename = os.path.join(_image_directory,
                            'Unicode String ({}).png'.format(supershape_name))
    maze.image().save(filename, format='PNG')
    print('Saved {}'.format(filename))
Exemplo n.º 5
0
def ascii_string_maze():
    s = 'Mazes.'
    supershape_name, supershape = next(_supershapes_cycle)
    grid = pmz.PolyGrid(supershape=supershape)
    grid.create_string(s, height=50)
    maze = pmz.Maze(grid)
    filename = os.path.join(_image_directory,
                            'ASCII String ({}).png'.format(supershape_name))
    maze.image().save(filename, format='PNG')
    print('Saved {}'.format(filename))
Exemplo n.º 6
0
def custom_rectangle_mazes():
    aspect_close_to_golden_rectangle = 0.625
    for complexity in (1, 1.5, 2, 4):
        supershape_name, supershape = next(_supershapes_cycle)
        grid = pmz.PolyGrid(supershape=supershape)
        grid.create_rectangle(complexity=complexity,
                              aspect=aspect_close_to_golden_rectangle)
        maze = pmz.Maze(grid)
        filename = os.path.join(
            _image_directory, 'Rectangle (Complexity {}) ({}).png'
            ''.format(complexity, supershape_name))
        maze.image().save(filename, format='PNG')
        print('Saved {}'.format(filename))
Exemplo n.º 7
0
 def test_mazify_grid_eliminates_isolated_shapes(self):
     grid = pmz.PolyGrid()
     neighbor_1_index = (1, 1)  # any index
     isolated_index = (30, 30)  # no way these are connected
     # create the neighbors and the isolated shape
     grid.create(isolated_index)
     neighbor_1 = grid.create(neighbor_1_index)
     neighbor_2_index, _ = tuple(neighbor_1.neighbors())[0]
     neighbor_2 = grid.create(neighbor_2_index)
     # mazify and confirm the isolated shape has been removed
     pmz.Maze(grid)
     final_shapes = tuple(grid.shapes())
     final_shapes_spec = (neighbor_1, neighbor_2)
     _assertCountEqual(self, final_shapes, final_shapes_spec)
Exemplo n.º 8
0
def make_maze(complexity):
    grid = pmz.PolyGrid(supershape=preloaded_shape)
    grid.create_rectangle(complexity=complexity)
    pmz.Maze(grid)