Advertisement
AlfonsoPEREZ

MAZE GENERATOR PYTHON TURTLE

Apr 27th, 2020
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 KB | None | 0 0
  1. import turtle
  2.  
  3. wn = turtle.Screen()
  4. wn.bgcolor("powderblue")    
  5. wn.title("Maze Generator")
  6. wn.setup(1300,700)
  7. wn.tracer(0)
  8.  
  9. pen=turtle.Turtle()
  10. pen.hideturtle()
  11. pen.up()
  12. pen.color("white")
  13. pen.goto(0, -250)
  14. pen.write("MAZE TESTING",False,"center",font=("Arial Narrow",20,"bold"))
  15.  
  16.  
  17. class Maze(turtle.Turtle):                
  18.     def __init__(self):
  19.         turtle.Turtle.__init__(self)
  20.         self.shape("square")            
  21.         self.color("white")            
  22.         self.penup()                  
  23.         self.speed(0)
  24.        
  25. def setup(grid):
  26.     global start_x, start_y, end_x, end_y
  27.     for y in range(len(grid)):                        
  28.         for x in range(len(grid[y])):                
  29.             character = grid[y][x]                  
  30.             screen_x = -588 + (x * 24)
  31.             screen_y = 288 - (y * 24)          
  32.  
  33.             if character == "+":                  
  34.                 maze.goto(screen_x, screen_y)    
  35.                 maze.stamp()                        
  36.                 walls.append((screen_x, screen_y))  
  37. maze = Maze()              
  38. walls = []
  39.  
  40. #MAIN PROGRAM
  41. grid = [
  42. "++++++++++++++++++++++++++++++++++++++++++++++",
  43. "+                                           c+",
  44. "+ ++++++++++++++++++++++++++++++++++++++++++ +",
  45. "+                                            +",
  46. "+ ++++++++++++++++++++++++++++++++++++++++++ +",
  47. "+ ++++++++++++++++++++++++++++++++++++++++++ +",
  48. "+                                            +",
  49. "+ ++++++++++++++++++++++++++++++++++++++++++ +",
  50. "+                                            +",
  51. "+ ++++++++++++++++++++++++++++++++++++++++++ +",
  52. "+ ++++++++++++++++++++++++++++++++++++++++++ +",
  53. "+                                            +",
  54. "+ ++++++++++++++++++++++++++++++++++++++++++ +",
  55. "+                                            +",
  56. "+ ++++++++++++++++++++++++++++++++++++++++++ +",
  57. "+                                            +",
  58. "+ ++++++++++++++++++++++++++++++++++++++++++ +",
  59. "+                                            +",
  60. "+o                                           +",
  61. "++++++++++++++++++++++++++++++++++++++++++++++",
  62. ]
  63.  
  64. setup(grid)
  65. wn.exitonclick()
  66. #MADE BY AVMP
  67. #https://www.youtube.com/channel/UCQor7IURWM-lGT-tmFbFSCw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement