Python Code Example
import numpy from numpy.random import random_integers as rand import matplotlib.pyplot as pyplot def maze(width=81, height=51, complexity=.75, density=.75): # Only odd shapes shape = ((height // 2) * 2 + 1, (width // 2) * 2 + 1) # Adjust complexity and density relative to maze size complexity = int(complexity * (5 * (shape + shape))) density = int(density * (shape // 2 * shape // 2)) # Build actual maze Z = numpy.zeros(shape, dtype=bool) # Fill borders Z = Z = 1 Z = Z = 1 # Make isles for i in range(density): x, y = rand(0, shape // 2) * 2, rand(0, shape // 2) * 2 Z = 1 for j in range(complexity): neighbours = if x > 1: neighbours.append((y, x - 2)) if x < shape - 2: neighbours.append((y, x + 2)) if y > 1: neighbours.append((y - 2, x)) if y < shape - 2: neighbours.append((y + 2, x)) if len(neighbours): y_,x_ = neighbours if Z == 0: Z = 1 Z = 1 x, y = x_, y_ return Z pyplot.figure(figsize=(10, 5)) pyplot.imshow(maze(80, 40), cmap=pyplot.cm.binary, interpolation='nearest') pyplot.xticks, pyplot.yticks pyplot.showRead more about this topic: Maze Generation Algorithm
Famous quotes containing the word code:
“...I had grown up in a world that was dominated by immature age. Not by vigorous immaturity, but by immaturity that was old and tired and prudent, that loved ritual and rubric, and was utterly wanting in curiosity about the new and the strange. Its era has passed away, and the world it made has crumbled around us. Its finest creation, a code of manners, has been ridiculed and discarded.”
—Ellen Glasgow (18731945)
Related Phrases
Related Words