ani_maze.html
001|
002| from sys import argv
003| from os import path
004| from maze import MazeObject, MazeGen1, MazeSolver, MazeImagePng
005| from animation import aspect_ratio
006|
007| BasePath = r'C:\CJS\prj\Python\ws\PIL'
008| AnimPath = r'C:\CJS\prj\pov\ws\xyz\ani'
009|
010| filename = path.join(BasePath, 'maze.png')
011|
012|
013| class MazeFile:
014| """Simple class to implement an incrementing filename."""
015| def __init__ (self, dnbr):
016| """New MazeFile instance. Needs a directory number."""
017| self.fname = path.join(BasePath,'ani','%d'%dnbr, 'maze_%04d.png')
018| self.fnbr = 0
019| def __str__ (self):
020| """String is current filename."""
021| return self.fname % self.fnbr
022| def __call__ (self, nav):
023| """MazeFile function."""
024|
025| fn = str(self)
026| self.fnbr += 1
027|
028| row = nav.curr_row
029| col = nav.curr_col
030| val = nav.mz.cell(row,col)
031| nav.mz.set_cell(row,col, MazeObject.MazeExit)
032|
033| im = MazeImagePng(nav.mz)
034| im.draw_maze()
035| im.save(fn)
036| print('wrote: %s' % fn)
037|
038| nav.mz.set_cell(row,col, val)
039|
040|
041| def ani_maze (rows=54, cols=96):
042| """Animate the generation and solving of a (randomly generated) Maze."""
043|
044| maze = MazeObject(rows, cols)
045|
046| gen = MazeGen1(maze)
047| gen.cb_builder = MazeFile(1)
048| gen.generate_maze()
049|
050| sol = MazeSolver(maze)
051| sol.cb_builder = MazeFile(2)
052| sol.solve_maze()
053|
054| img = MazeImagePng(maze)
055| img.draw_maze()
056| img.save(filename)
057|
058|
059|
060| def main (*args):
061|
062|
063| ani_maze()
064|
065|
066| if __name__ == '__main__':
067| print(argv[0])
068| print()
069| main(*argv[1:])
070| print()
071|
072|
073|
074| '''eof'''
075|