3D/2D Maze Generator (Blender/Python Script) for 3D Printers and Laser Cutters

by nimaid, published

3D/2D Maze Generator (Blender/Python Script) for 3D Printers and Laser Cutters by nimaid Mar 24, 2015


Use This Project

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag


Thing Statistics

7789Views 3105Downloads Found in Puzzles


EDIT 1 (3/24/15): Added dual extrusion support.

EDIT 2 (3/24/2015): Added option to have entrance and exits closed, also added setting to make 2D vector path instead of 3D mesh. Fixed minor redundancy in code.

EDIT 3 (3/25/15): Fixed minor settings conflict, added more comments for clarity.

So I've had a thing for maze generation for a while. While I wrote a few different games in HTML 5/Javascript and C, I wanted to make something that was actually physically real.

A search on Thingiverse led me to a Python script that generated an OpenSCAD description of a maze, but that seemed too round-about for me. Besides, I like the looks of the classic recursive-backtracker algorithm more than any other, and it's so deliciously simple to implement. Also, I really, really like generating mazes. :) So, I decided to write my own.

Initially, I wanted to implement it in OpenSCAD, but because it uses a functional language, determined that it was impossible. (Apparently I was totally wrong!) However, I finally got it working as a Python script within Blender.

This took about a year or so of very sparse tinkering. Initially, I was trying to use booleans to add and subtract cuboids (like OpenSCAD), but that proved problematic due to the finicky nature of normals and stuff. So, I wound up making the maze as a 2D mesh (vertex by vertex, face by face), then extruding it and adding the base later.

This is fully functional, but there are a few features I still want. I really want to be able to mark the start and end, but I'm not sure how I should do it. Leave a comment and give me your ideas!

For fun, the 20x20_humanSize.stl is a 20 X 20 maze that would be suitable for a human to walk around in. (62600 mm x 626000 mm total, or about 98.6 acres). Here are the settings: (thanks, Google!)

width = 20 #how many cells wide
length = 20 #how many cells long
cellThickness = 2500 #width of passages [mm]
wallThickness = 600 #width of walls [mm]
wallHeight = 2500 #height of walls [mm]
baseHeight = 300 #height of base [mm]

Good luck printing that at 1:1 scale.


To make your own maze, download Maze Generator.blend, open it in Blender, and read the instructions in the script in the upper left. When it's done, select it, then File>Export>Stl (.stl). Print and enjoy! No supports needed!

I would recommend the wall width to be a multiple of your nozzle diameter so you can print them solid using only shells. For example, if you have a nozzle that's 0.4 mm, you can print the walls solidly using 1 shell (which will make the walls 2 shells thick total) if they are 0.4*2 mm thick.

Alternatively, you can laser cut them! Support for this is limited ATM, but if you set the wallHeight = 0, it will make a path (really, 2 paths) instead of a mesh. Use the Blender SVG Exporter to get it as an SVG and make whatever you want out of it! Of course, it's not fit to laser cut right out of the box, you have to get creative with it! (If you use Inkscape, scale the paths by 125% before using them. Illustrator works as-is.)

The files for the laser cut ball maze are 15x15_ball_maze.ai and 15x15_ball_maze.svg. Instructions are inside the files.

If you make your own 3D or laser cut designs from this project, please credit me, and add it as a remix to this thing.

Instead of using the .blend file, you could also load the blender_maze_gen.py up in blender on your own, but there's not much reason to do this IMO. Just use the .blend file.

Currently, the entrance and exit look the same. The entrance is the hole that will face towards you when printed (or the one in the 3rd quadrant [-x, -y], for those who want to be specific). Comment to give me ideas for how to mark them, because I'm at a loss.

More from Puzzles

view more

All Apps

Auto-magically prepare your 3D models for 3D printing. A cloud based 3D models Preparing and Healing solution for 3D Printing, MakePrintable provides features for model repairing, wall thickness...

App Info Launch App

Kiri:Moto is an integrated cloud-based slicer and tool-path generator for 3D Printing, CAM / CNC and Laser cutting. *** 3D printing mode provides model slicing and GCode output using built-in...

App Info Launch App
KiriMoto Thing App

With 3D Slash, you can edit 3d models like a stonecutter. A unique interface: as fun as a building game! The perfect tool for non-designers and children to create in 3D.

App Info Launch App

Quickly Scale, Mirror or Cut your 3D Models

App Info Launch App

Thanks for this.
However, how do you download Maze Generator.blend ?

This is just what we were looking for. We want to use it to make an Arduino controlled maze with interchangeable maze plates. Thanks so much for putting this up.

The Bridgeville Delaware Teen Imagineering Club

Well it's possible to do maze creation in functional languages but its more of an interesting challenge than a practical approach.

Here is one example using the functional language haskell:
Multi-output maze generator ... by mwm ... http://www.thingiverse.com/thing:778556

I too generated some mazes with Haskell (still need to upload the sourcecode ...)
Maze-Games ... by mechadense ... http://www.thingiverse.com/thing:16240

OpenSCAD version 2015.03 with its support for recursion in functions is as far as I see kind of Turing complete.
Broken only by the rather limited maximally allowed recursion depth.
What makes writing an backtracking maze generation algorithm in OpenSCAD rather unfeasible / borderline impossible is I think
the lack of a library for that contains a suitable purely functional data-structure.

Multi-output maze generator
by mwm

Yeah, I saw that derivative that mwm made (it really is it's own thing though). That's really clever how it was done.

The main reason I did this solution is because I wanted an 'all-in-one' way to make mazes, from generation to rendering into an stl. OpenSCAD only gave the latter.

I've always enjoyed making mazes too.. There's something about them..

So I tried this a few times. Load the blend file. Didn't change anything. Just hit Run Script. The error is "Python script fail, look in the console for now."
Changed some settings.. no luck.
I see the script instructs it to delete whatever is already there, so I also deleted whatever existed in the viewing window. Same message every time, and I have no idea what's going on, so I don't want to mess with things too much.
Blender 2.68a
Is it me?

First of all, make sure you aren't in Edit Mode. (At the bottom of the 3D window make sure it says Object Mode).

I programmed this in the newest version of Python (3.4.x), so I would try updating that first if I were you.If that doesn't work, read below.

I am assuming your are running windows.In the top bar, please click "Window>Toggle System Console". Then copy everything in the window that pops up.If you are not running Windows, start Blender up from a terminal, run the script again, and copy the output in the terminal.

The script automatically deletes all objects that aren't hidden in the scene.

Updating to Blender 2.73a did the trick. It runs really nice.
And since this is Blender, I plan on manipulating the exported stl... maybe make a spherical maze or cube maze, or something...

Thinking about the entrance and exit problem. I assume it's just a fact that these things are easier to solve when entering the exit. If that's the case, and if programming the change were possible, I might put the target at middle of the maze, rather than on an edge.

I wouldn't begin a maze in the middle of it, but maybe that's just me..

Glad it works now. Make sure to upload whatever cool stuff you make as a remix! As a quick note, I was thinking about maybe expanding the recursive backtracker into 3D, making a 3D maze out of voxels...

The maze ending in the middle is a good idea! I might add an option to allow the user to choose between the edge or center goal.

However there's still the issue of marking the goal. For the open entrance/exit designs, I was thinking about embossing directional arrows, but for the closed edge (and now the option of the goal in the center), I need some good symbols that signify start and goal. Any ideas?

Google images search shows a few 3D mazes. They look very confusing from the outside. How about just poke a hole in the floor and continue on the other side? Or punch a few holes, so you're flipping it over more than once....

Some cave(wo)man invented the directional arrow, and the entire human race has been perfectly satisfied with it. I searched but found no other entrance / exit , in / out, symbol.
There is the open swinging door, but it needs a silhouette of a person walking... Or an arrow.

No ideas yet, but I certainly will upload as a remix when the time comes.