Skip to content

Generating, visualizing, playing around with mazes.

License

Notifications You must be signed in to change notification settings

Strophox/mazing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Mazing

Generating, visualising, playing around with mazes

A Mazing animation

What is this?

A hobby project to familiarize myself with Git.

But mazes are so amazing that, after writing code to build arbitrarily large ones, I naturally had to extend functionality to have them solved, printed, drawn and colored in by the computer, too.

In essence, mazing.py provides a handy Maze class to mess around with.

How to use it

To play around with implemented functionality, run playground.py directly to try stuff out on the command line.

I tried adding Google-style docstrings to everything, so help(...) might yield sensible information for usage of any script/module (c.f. code examples in last section).

What can it do?

Functionality includes but is not limited to

  • Randomly carving (so-called) 'perfect' mazes with a unique solution.
    • Common maze (graph) algorithms implemented [Growing tree, backtracker, (simplified) Prim's, Kruskal's, Wilson's, divide-and-conquer]
    • Mix of different methods ('x-divide-and-conquer')
  • Text art.
    • 7 different ways to print maze as text (including 3 w/ solution path)
  • Imaging.
    • Normal PNG
    • Solution path
    • Colored by distance from entrance (heatmap)
    • Colored by algorithm usage (for mixed maze generation)
  • Animation.
    • Use any of above imaging methods to visualize building of a maze
  • Computing information.
    • Solution path
    • Longest possible path through maze, and other interesting stats

Gallery

Text Art Examples

ASCII

Timeless maze art for any(?)(!) console.

ASCII 'frame'

+   +---+---+---+---+---+---+---+---+---+
|               |                       |
+   +---+   +   +---+---+---+   +---+   +
|   |   |   |       |           |       |
+   +   +   +---+   +   +---+---+   +---+
|       |   |           |               |
+   +---+   +   +---+---+---+---+---+   +
|   |       |   |   |           |   |   |
+   +   +---+   +   +   +---+   +   +   +
|   |       |       |   |       |   |   |
+   +---+   +---+---+   +   +---+   +   +
|   |   |           |   |           |   |
+   +   +---+---+   +   +---+---+---+   +
|   |       |       |               |   |
+   +   +   +   +---+---+---+---+   +   +
|   |   |   |   |           |       |   |
+   +   +   +   +   +   +   +   +---+   +
|   |   |   |       |   |   |   |   |   |
+   +---+   +---+---+   +---+   +   +   +
|                   |           |       |
+---+---+---+---+---+---+---+---+---+   +

'Minimalist' ASCII frame

, ______________________________,
| ,__ |___, |_, , , |___, |___, |
| | , , ,_| __| |_|_, | | __, | |
|_|_| | |__ __|__ | | , | , | , |
| |__ | |___, | ,_| __|___| |_| |
| ,___| | __|__ | | , | ____|_, |
| |__ |_| ________|_|_|___| __| |
| ____| ,_, __| , , |____ ,__ | |
|____ |_| | , |_| |__ , , |_____|
| |_, | ,___|_| |_| , |_|_| ____|
| ,_|__ | | ,__ | ,_|_| | |__ | |
| | | __, ,_| __|_| |_, , |__ , |
| , | , | |__ , |__ __| |__ , | |
| | ,_| |_| , | , __, ,_| __|_| |
| |_| |_| |_| | |_, | | |__ __|_|
| ,__ | , |___|_| |_| | , ,__ __|
|_|_____|___|_________|_|_|____ |

Unicode

Note

Certain special box/frame characters may not display/align correctly.

Show Unicode arts

'Frame'

β•· β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”
β”‚ β•΅ β•· β”Œβ”€β”€β”€β”¬β”€β•΄ └───╴ β•· β”Œβ”€β”€β”€β”€β”€β”˜ β•· β”‚
β”‚ β•Άβ”€β”Όβ”€β”˜ β•· └───────┐ β”œβ”€β”˜ β•· β•Άβ”€β”¬β”€β”˜ β”‚
β”œβ”€β•΄ β”‚ ╢─┼─────┬─╴ β”‚ β”‚ β”Œβ”€β”΄β”€β•΄ β”‚ β”Œβ”€β”€
β”‚ β•· └─╴ β”œβ”€β•΄ ╢── β•Άβ”€β”΄β”€β”˜ β”œβ”€β”¬β”€β”€β”€β”˜ β”‚ β”‚
β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”Œβ”€β” β””β”€β”€β”€β”¬β”€β”€β”€β”˜ β”‚ β•Άβ”€β”¬β”€β”˜ β”‚
β”‚ β”‚ β•Άβ”€β”€β”€β”˜ β”‚ └───┐ β”‚ ╢───┴─┐ β”‚ ╢──
β”‚ β”‚ ╢─┬─┬─┴─╴ β”Œβ”€β”˜ β”‚ β”Œβ”€β”€β”€β” β•΅ β”œβ”€β•΄ β”‚
β”‚ └─┐ β”‚ β”‚ β•· β•Άβ”€β”΄β”€β”¬β”€β”˜ └─┐ └─┐ β•΅ β•· β”‚
β”œβ”€β•΄ β”‚ β•΅ β”‚ └───┐ └───┐ β”œβ”€β•΄ β””β”€β”¬β”€β”˜ β”‚
β”‚ β•· β”‚ β•· β”‚ β”Œβ”€β•΄ β”œβ”€β”¬β”€β”¬β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€ β”Œβ”€β”€
β”‚ β”‚ └── β”‚ β”œβ”€β” β•΅ β”‚ β”‚ β•Άβ”€β”˜ └─┐ β•΅ β”‚ β”‚
β”‚ β”œβ”€β” β•΅ β•΅ β”‚ β”‚ ╢── β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”¬β”€β”˜ β”‚
β”‚ β”‚ β”‚ β”Œβ”€β•΄ β”‚ β”œβ”€β•΄ β”‚ β”Œβ”€β”€β”€β•΄ β•· β•΅ β”‚ β•· β”‚
β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”˜ β”‚ β”Œβ”€β”˜ └─┐ β•Άβ”€β”΄β”€β”¬β”€β”΄β”€β”˜ β”‚
β”‚ β•΅ β”‚ β””β”€β”˜ β”Œβ”€β”˜ └───╴ β”œβ”€β”€β”€β•΄ └─╴ β•· β”‚
β””β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β•΅

'Half-block'

β–ˆ β–€β–€β–ˆβ–€β–€β–€β–€β–€β–€β–€β–ˆβ–€β–€β–€β–ˆβ–€β–€β–€β–ˆβ–€β–€β–€β–ˆβ–€β–€β–€β–€β–€β–€β–€β–ˆ
β–ˆβ–€β–€ β–€β–€β–€ β–ˆβ–€β–€ β–€β–€β–€ β–ˆβ–€β–€ β–€ β–€β–€β–ˆβ–€β–€ β–ˆβ–€β–€ β–ˆ
β–ˆβ–€β–€β–€β–€ β–€β–€β–ˆβ–€β–€β–€β–€ β–€β–€β–ˆβ–€β–€ β–ˆβ–€β–€β–€β–ˆβ–€β–€ β–ˆβ–€β–€β–€β–ˆ
β–ˆβ–€β–€ β–ˆβ–€β–€ β–ˆβ–€β–€ β–ˆ β–€β–€β–€ β–€β–€β–€ β–€β–€β–€ β–€β–€β–€β–€β–€ β–ˆ
β–ˆβ–€β–€β–€β–€β–€β–€ β–ˆβ–€β–€β–€β–€β–€β–€β–€β–ˆ β–€β–€β–ˆβ–€β–€β–€β–€β–€β–€β–€β–ˆβ–€β–€β–€β–ˆ
β–ˆ β–€β–€β–ˆ β–€β–€β–ˆβ–€β–€ β–ˆβ–€β–€ β–ˆβ–€β–€ β–€β–€β–€ β–ˆβ–€β–€ β–€ β–€β–€β–ˆ
β–ˆβ–€β–€ β–ˆβ–€β–€β–€β–€β–€β–€ β–€β–€β–€β–€β–ˆβ–€β–€β–€β–ˆ β–€β–€β–ˆβ–€β–€β–€β–€ β–€β–€β–ˆ
β–ˆ β–€β–€β–€β–€β–€ β–ˆβ–€β–€ β–ˆ β–€β–€β–ˆβ–€β–€ β–€ β–€β–€β–ˆβ–€β–€ β–ˆβ–€β–€ β–ˆ
β–ˆβ–€β–€β–€β–€β–€β–€β–€β–€ β–€β–€β–ˆβ–€β–€β–€β–€β–€β–€β–€β–ˆβ–€β–€β–€β–ˆβ–€β–€β–€β–ˆβ–€β–€β–€β–ˆ
β–ˆβ–€β–€ β–ˆ β–€β–€β–ˆ β–€β–€β–€ β–€β–€β–ˆ β–€β–€β–€β–€β–€ β–€ β–€β–€β–€ β–€β–€β–ˆ
β–ˆβ–€β–€ β–€β–€β–€β–€β–ˆβ–€β–€β–€β–€β–€β–€ β–ˆβ–€β–€β–€β–€β–€β–€ β–ˆ β–€β–€β–€β–€β–€β–€β–ˆ
β–ˆβ–€β–€ β–ˆ β–€β–€β–ˆβ–€β–€ β–ˆ β–€β–€β–ˆβ–€β–€ β–ˆβ–€β–€ β–ˆβ–€β–€ β–ˆβ–€β–€ β–ˆ
β–ˆβ–€β–€ β–€β–€β–€β–€β–ˆβ–€β–€β–€β–ˆβ–€β–€β–€β–ˆβ–€β–€ β–ˆβ–€β–€β–€β–ˆβ–€β–€β–€β–ˆβ–€β–€β–€β–ˆ
β–ˆβ–€β–€ β–ˆ β–€β–€β–ˆβ–€β–€ β–€β–€β–€ β–ˆβ–€β–€ β–€ β–€β–€β–€ β–€β–€β–€β–€β–€ β–ˆ
β–ˆβ–€β–€β–€β–ˆ β–€β–€β–€β–€β–€ β–ˆβ–€β–€β–€β–ˆ β–€β–€β–€β–€β–€β–€β–ˆβ–€β–€β–€β–ˆβ–€β–€ β–ˆ
β–ˆβ–€β–€ β–€β–€β–€ β–ˆ β–€β–€β–€β–€β–€ β–ˆβ–€β–€ β–ˆβ–€β–€ β–ˆβ–€β–€ β–€β–€β–€ β–ˆ
β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€ β–€β–€β–€β–€β–€β–€β–€

'Quarter-block'

β–›β–€β–€β–€β–€β–€β–›β–€β–€β–€β–€β–€β–€β–›β–€β–€β–€β–€β–€β–€β–›β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–Œ
β–Œβ–˜β–Œβ–€β–€β–˜β–Œβ–€β–˜β–€β–Œβ–›β–˜β–Œβ–Œβ–˜β–›β–€β–˜β–Œβ–˜β–›β–˜β–›β–€β–˜β–Œβ–€β–Œβ–€β–˜β–˜β–Œ
β–›β–€β–Œβ–Œβ–Œβ–€β–€β–€β–€β–Œβ–˜β–˜β–Œβ–Œβ–€β–€β–˜β–€β–Œβ–€β–€β–˜β–Œβ–˜β–Œβ–Œβ–›β–˜β–€β–›β–˜β–Œβ–Œ
β–Œβ–Œβ–˜β–Œβ–€β–€β–Œβ–€β–˜β–€β–˜β–€β–˜β–›β–˜β–›β–˜β–Œβ–›β–˜β–›β–€β–›β–˜β–˜β–Œβ–˜β–€β–˜β–˜β–€β–˜β–Œ
β–Œβ–€β–Œβ–›β–˜β–Œβ–˜β–Œβ–€β–€β–˜β–€β–€β–Œβ–€β–Œβ–›β–˜β–Œβ–˜β–˜β–˜β–˜β–Œβ–€β–Œβ–˜β–Œβ–€β–€β–€β–Œβ–Œ
β–Œβ–˜β–˜β–Œβ–Œβ–€β–˜β–Œβ–˜β–›β–˜β–Œβ–Œβ–€β–˜β–˜β–Œβ–˜β–€β–Œβ–›β–˜β–›β–˜β–Œβ–€β–›β–€β–˜β–Œβ–˜β–˜β–Œ
β–Œβ–›β–€β–˜β–Œβ–€β–˜β–Œβ–˜β–Œβ–˜β–˜β–˜β–€β–›β–˜β–˜β–€β–Œβ–˜β–Œβ–Œβ–˜β–€β–Œβ–Œβ–˜β–Œβ–€β–€β–˜β–€β–Œ
β–Œβ–˜β–›β–€β–€β–€β–›β–˜β–€β–›β–˜β–Œβ–€β–˜β–˜β–€β–Œβ–˜β–€β–›β–˜β–›β–€β–˜β–˜β–›β–€β–€β–Œβ–˜β–Œβ–˜β–Œ
β–›β–€β–˜β–˜β–Œβ–˜β–Œβ–˜β–Œβ–Œβ–Œβ–›β–€β–˜β–˜β–Œβ–€β–€β–Œβ–Œβ–˜β–˜β–€β–€β–€β–Œβ–€β–˜β–˜β–Œβ–€β–€β–Œ
β–Œβ–€β–€β–Œβ–€β–Œβ–€β–›β–˜β–˜β–Œβ–˜β–Œβ–€β–€β–€β–˜β–Œβ–˜β–Œβ–€β–€β–€β–˜β–Œβ–€β–˜β–Œβ–€β–€β–€β–Œβ–Œ
β–Œβ–€β–˜β–€β–˜β–Œβ–˜β–Œβ–›β–€β–Œβ–Œβ–€β–›β–˜β–›β–€β–€β–˜β–Œβ–˜β–›β–€β–˜β–Œβ–€β–›β–˜β–Œβ–Œβ–˜β–Œβ–Œ
β–›β–€β–Œβ–›β–˜β–Œβ–€β–˜β–˜β–˜β–˜β–Œβ–Œβ–˜β–Œβ–˜β–˜β–›β–˜β–€β–€β–Œβ–€β–›β–€β–Œβ–Œβ–€β–Œβ–Œβ–€β–˜β–Œ
β–Œβ–Œβ–Œβ–Œβ–˜β–€β–€β–€β–€β–Œβ–Œβ–˜β–˜β–€β–˜β–›β–˜β–˜β–›β–€β–˜β–€β–˜β–Œβ–˜β–Œβ–€β–˜β–Œβ–˜β–Œβ–Œβ–Œ
β–Œβ–Œβ–Œβ–Œβ–€β–˜β–Œβ–˜β–˜β–˜β–€β–˜β–€β–Œβ–€β–Œβ–Œβ–˜β–Œβ–›β–€β–Œβ–€β–Œβ–˜β–Œβ–€β–˜β–Œβ–€β–˜β–˜β–Œ
β–Œβ–˜β–˜β–€β–Œβ–˜β–˜β–Œβ–€β–˜β–˜β–›β–˜β–˜β–˜β–˜β–Œβ–€β–˜β–Œβ–Œβ–Œβ–˜β–€β–˜β–›β–˜β–€β–€β–€β–˜β–Œβ–Œ
β–Œβ–€β–€β–˜β–˜β–€β–€β–€β–€β–˜β–€β–˜β–˜β–˜β–€β–€β–˜β–Œβ–€β–˜β–Œβ–˜β–Œβ–€β–˜β–Œβ–˜β–€β–€β–€β–˜β–˜β–Œ
β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–˜

'Pipes'

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  β”Œβ”  β”Œβ”  β”‚β”‚  β”Œβ”€β”€β”€β”€β”  β”Œβ”  β”‚β”‚  β”Œβ”  β”Œβ”  β”Œβ”  β”Œβ”  β”‚
β”‚  β”‚β”‚  β”‚β”‚  β””β”˜  β”‚β”Œβ”€β”€β”€β”˜  β”‚β”‚  β””β”˜  β”‚β”‚  β”‚β”‚  β”‚β”‚  β”‚β”‚  β”‚
β”‚  β”‚β”‚  β”‚β”‚  β”Œβ”  β”‚β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”‚β”‚  β”‚β”‚  β”‚β”‚  β”‚
β”‚  β””β”˜  β”‚β”‚  β”‚β”‚  β””β”˜  β””β”€β”€β”€β”€β”˜  β”‚β”Œβ”€β”€β”€β”˜  β”‚β”‚  β””β”˜  β””β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”‚β”‚  β”Œβ”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”˜β”‚  β”Œβ”€β”€β”€β”˜β””β”€β”€β”€β”  β”Œβ”€β”€β”€β”˜
β”‚  β”‚β”Œβ”€β”€β”€β”˜  β”‚β”‚  β””β”˜  β”‚β”Œβ”€β”€β”€β”€β”€β”€β”β”‚  └───────┐│  └───┐
β”‚  β”‚β”‚  β”Œβ”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”˜β”‚  β”Œβ”  β”‚β”‚  β”Œβ”€β”€β”€β”€β”  β”‚β”‚  β”Œβ”  β”‚
β”‚  β””β”˜  β”‚β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚  β”‚β”‚  β””β”˜  β””β”€β”€β”€β”€β”˜  β”‚β”‚  β””β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”Œβ”  β”Œβ”  β”‚β”‚  β”‚β”‚  β”Œβ”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”˜β”‚  β”Œβ”€β”€β”€β”˜
β”‚  └───┐│  β”‚β”‚  β”‚β”‚  β”‚β”‚  β”‚β”‚  β””β”€β”€β”€β”€β”˜  └───┐│  └───┐
β”‚  β”Œβ”  β”‚β”‚  β”‚β”‚  β”‚β”‚  β”‚β”‚  β”‚β”‚  β”Œβ”  β”Œβ”  β”Œβ”  β”‚β”‚  β”Œβ”  β”‚
β”‚  β””β”˜  β”‚β”‚  β””β”˜  β””β”˜  β””β”˜  β”‚β”‚  β””β”˜  β”‚β”‚  β”‚β”‚  β””β”˜  β”‚β”‚  β”‚
β”‚  β”Œβ”€β”€β”€β”˜β””β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”  β”‚β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”‚β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”‚
β”‚  β”‚β”Œβ”€β”€β”€β”€β”€β”€β”β”‚  β”‚β”Œβ”€β”€β”€β”˜  β”‚β”‚  └───┐│  β””β”˜  β”‚β”Œβ”€β”€β”€β”˜  β”‚
β”‚  β”‚β”‚  β”Œβ”  β”‚β”‚  β”‚β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”Œβ”  β”‚β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”Œβ”  β”‚
β”‚  β”‚β”‚  β””β”˜  β”‚β”‚  β””β”˜  β”‚β”Œβ”€β”€β”€β”˜  β”‚β”‚  β””β”˜  └───┐│  β”‚β”‚  β”‚
β”‚  β”‚β”‚  β”Œβ”  β”‚β”‚  β”Œβ”  β”‚β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”Œβ”€β”€β”€β”€β”  β”‚β”‚  β”‚β”‚  β”‚
β”‚  β””β”˜  β”‚β”‚  β”‚β”‚  β””β”˜  β”‚β”‚  β”‚β”Œβ”€β”€β”€β”˜  β”‚β”Œβ”€β”€β”€β”˜  β”‚β”‚  β””β”˜  β”‚
└───┐  β”‚β”‚  β”‚β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”‚β”‚  β”Œβ”  β”‚β”‚  β”Œβ”€β”€β”€β”˜β”‚  β”Œβ”  β”‚
β”Œβ”€β”€β”€β”˜  β””β”˜  β”‚β”‚  └───┐│  β””β”˜  β””β”˜  β””β”˜  β””β”€β”€β”€β”€β”˜  β”‚β”‚  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”  │└───┐  β”‚β”‚  β”Œβ”  β”Œβ”  β”Œβ”  β”Œβ”  β”Œβ”€β”€β”€β”˜β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”˜  β””β”˜  β”‚β”‚  β””β”˜  β””β”˜  β”‚β”‚  β””β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Images

One Example

This 20Γ—20 maze was generated by a randomized-DFS carving method, which usually leads to long, winding tunnels compared to other methods.

Test Maze

Solution of above maze

Maze Solution

Distance heatmap of maze

Maze Heatmap

Bigger Examples

Solution of a 128Γ—128 randomized-Kruskal maze.

Kruskal Solution

'Great Wave off Kanagawa'

Kanagawa

1920Γ—1080 maze wallpaper variation (see others here)

Wallpaper

'Magma' colormap.

Magma

Animations

Comparing Algorithms

Backtracker

Backtracker Animation

Growing-Tree

Growing-Tree Animation

Prim

Prim Animation

Kruskal

Kruskal Animation

Divide and Conquer

Divide and Conquer Animation

Mixing Algorithms

'x-divide-and-conquer' (better name pending) is a variation on normal divide-and-conquer where any recursive call may decide to let an arbitrary algorithm finish the remaining subsection. This allows mazes to be correctly and seamlessly built using independent perfect maze algorithms. (*Note that actual implementation includes a clear-area subalgorithms, because having empty rooms in the maze is fun)

Mixed Divide-and-Conquer
xdivision animation xdivision endresult

Code Examples

Generate a simple maze and print it to console (Unicode & ASCII).
from mazing import Maze

# Blank, new maze
my_maze = Maze(16,16)

# Randomize maze
my_maze.backtracker()

# Use a Unicode string function
print(my_maze.str_frame())

# Use an ASCII string function
print(my_maze.str_frame_ascii())
Generate a large maze and save a normal image and a solution.
from mazing import Maze

# Blank, new maze
my_maze = Maze(100,100)

# Randomize maze
my_maze.growing_tree()

# Generate normal image, then save it
img = my_maze.generate_image()
img.save(img.filename)

# Generate solution image, then save it
imgsol = my_maze.generate_solutionimage()
imgsol.save(imgsol.filename)
Generate an animation of how `backtracker` works.
from mazing import Maze

# Generate animation frames
(frames, _resulting_maze) = Maze.generate_animation(16,16, Maze.backtracker)

# Save frames as .gif animation
frames[0].save(
    frames[0].filename,
    save_all=True,
    append_images=frames[1:],
    duration=30,
)
Make a very large maze to be used as HD desktop wallpaper.
from mazing import Maze
import colortools as ct

# Blank, new maze
my_maze = Maze(1920,1080) # (<!- Python be slow)

# Randomize maze
my_maze.backtracker()

# Precomputes distances
my_maze.compute_distances()

# Generate image
imgdst = my_maze.generate_colorimage(
    gradient_colors=ct.COLORMAPS['acton'][::-1], # (Makes bright -> dark)
    raster=my_maze.generate_raster(
        wall_air_ratio=(0,1), # (No walls, Only air)
        show_distances=True # (Color in distances)
    )
)

# Save image
imgdst.save(imgdst.filename)
Generate an interesting maze, then slowly escalate customization when saving images.
from mazing import Maze
import colortools as ct

my_maze = Maze(256,256)
my_maze.xdivision()

# 1) Solution image
imgsol = my_maze.generate_solutionimage()
imgsol.save(imgsol.filename)

# 2) Normal image, altered colors
img = my_maze.generate_image(
    wall_air_colors=(ct.COLORS['sepia'],ct.COLORS['vellum']),
)
img.save(img.filename)

# 3) Algorithms map, raster adapted
imgalg = my_maze.generate_algorithmimage(
    raster=my_maze.generate_raster(
        decolumnated=True,
        wall_air_ratio=(1,2),
        show_algorithms=True,
    ),
)
imgalg.save(imgalg.filename)

# 4) Branch distances, colors and raster adapted
my_maze.compute_branchdistances()
imgdst = my_maze.generate_colorimage(
    gradient_colors=ct.COLORMAPS['redyellowblue'][::-1], # makes bright -> dark
    raster=my_maze.generate_raster(
        decolumnated=True,
        wall_air_ratio=(1,2),
        show_distances=True,
    ),
)
imgdst.save(imgdst.filename)

More About

Don't you have exams to write?

Messing with mazes is tons of fun, and their graph algorithms are interesting (lots of different 'flavors' of mazes), also ASCII art is cool, and, then I uh, kinda got lost learning about different color spaces and what makes good color gradients for scientific graphs too, and, and Python decorators kept me occupied (& did you know that yield from is a valid syntax struct in Python?), so anyway uh....

Repository File Summaries

Purposes of each file;

  • mazing.py - Main maze functionality (see above)

  • playground - Sandbox functionality to try mazing.

  • benchmark.py - Personal mini-benchmark script.

  • colortools.py - Homebrewn color module.

    • Common/useful color constants
    • Interpolation functions
    • Color gradient presets
    • Conversion between color spaces
  • benchtools.py - Minimal timing decorators.

    • timed to time a function by its name
    • explicit timed_titled for lambdas
  • prototype_gridrunner.py - Unfinished top-down maze navigator implemented using curses. I don't intend on continuing work on it.

    • Should correctly display and appropriately scroll large mazes.
    • Navigate the maze on-screen using arrow keys or w, a, s, d.
    • Use shift in combination with the latter to jump to next wall.
    Console Screenshot

    Screenshot

Resources

About

Generating, visualizing, playing around with mazes.

Topics

Resources

License

Stars

Watchers

Forks

Languages