document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import os
  2. import maze
  3.  
  4. display_prog = \'display\' # Command to execute to display images.
  5.  
  6. class Scene:
  7.     def __init__(self,name="svg",height=400,width=400):
  8.         self.name = name
  9.         self.items = []
  10.         self.height = height
  11.         self.width = width
  12.         return
  13.  
  14.     def add(self,item): self.items.append(item)
  15.  
  16.     def setDims(self, w, h):
  17.         self.width = w;
  18.         self.height = h;
  19.  
  20.     def strarray(self):
  21.         var = ["<?xml version=\\"1.0\\"?>\\n",
  22.                "<svg height=\\"%d\\" width=\\"%d\\" >\\n" % (self.height,self.width),
  23.                " <g style=\\"fill-opacity:1.0; stroke:black;\\n",
  24.                "  stroke-width:0.1;\\">\\n"]
  25.         for item in self.items: var += item.strarray()            
  26.         var += [" </g>\\n</svg>\\n"]
  27.         return var
  28.  
  29.     def write_svg(self,filename=None):
  30.         if filename:
  31.             self.svgname = filename
  32.         else:
  33.             self.svgname = self.name + ".svg"
  34.         file = open(self.svgname,\'w\')
  35.         file.writelines(self.strarray())
  36.         file.close()
  37.         return
  38.  
  39.     def display(self,prog=display_prog):
  40.         os.system("%s %s" % (prog,self.svgname))
  41.         return        
  42.  
  43. class Rectangle:
  44.     def __init__(self,origin,height,width,color):
  45.         self.origin = origin
  46.         self.height = height
  47.         self.width = width
  48.         self.color = color
  49.         return
  50.  
  51.     def strarray(self):
  52.         return ["  <rect x=\\"%d\\" y=\\"%d\\" height=\\"%d\\"\\n" %\\
  53.                 (self.origin[0],self.origin[1],self.height),
  54.                 "    width=\\"%d\\" style=\\"fill:%s;\\" />\\n" %\\
  55.                 (self.width,colorstr(self.color))]
  56.    
  57. def colorstr(rgb): return "#%x%x%x" % (rgb[0]/16,rgb[1]/16,rgb[2]/16)
  58.  
  59. def run():
  60.     os.system("cls")
  61.     scene = Scene(\'maze\')
  62.  
  63.     size = int(raw_input(\'enter maze image size(px): \'))
  64.     if size <= 0: sz = 800
  65.    
  66.     block = int(raw_input(\'enter block size(px): \'))
  67.     if block < 1 or block > size: block = 5
  68.  
  69.     maze.buildMaze(scene, size, block)
  70.     scene.write_svg()
  71.  
  72. if __name__ == \'__main__\':
  73.     print "This program generates a SVG maze."
  74.     run()
');