OpenSCAD Maze Generator

907
Downloads
1220
Views
Published on June 9, 2012

Description

Ever need a maze generated for OpenSCAD? If so, then this puppy is for you. It is a Python script which generates a random N x M maze and outputs a 3D description of it as an OpenSCAD program.

The number of maze cells as well as the maze's physical size can all be controlled with command line arguments when running the Python script. The Python code can even be modified to generated non-rectangular mazes. (Hint: just throw up non-removable walls in the initialized maze data.)

BTW, the Python code here is derived from the Eggbot Maze generator, Eggmazing, which is distributed with the Eggbot software and is an Inkscape extension. I wrote that extension for the Eggbot in the Fall of 2010 and want to again thank W. Craig Trader for the assistance he provided with that effort.

Enjoy!

9 June 2012: Corrected invalid commenting style in line 1 of OpenSCAD output
9 June 2012: Added warning when wall thickness (-t) is explicitly set to be thicker than one-half the cell's width or length.

Instructions

Download the maze.py Python script and run it,

% python maze.py maze.scad

where the last argument, maze.scad, is the name of the output file to generate. The output is an OpenSCAD program which you can then load into OpenSCAD and render. Use whatever file name suits your fancy. If no name is supplied, then the OpenSCAD program is written to standard output, stdout.

The command line arguments can be seen with the command

% python maze.py --help
Usage: maze.py [-cfhlrtw] [output-file]
-c, --columns
Number of maze columns running the maze width (default = 8)
-f, --floor
Physical thickness in millimeters of the maze floor (default = 2.000000)
-h, --height
Physical height in millimeters of the maze (default = 8.000000)
-l, --length
Physical length in millimeters of the maze (default = 30.000000)
-r, --rows
Number of maze rows running the maze height (default = 8)
-t, --thickness
Physical maze wall thickness in millimeters (default = 1.000000)
-w, --width
Physical width in millimeters of the maze (default = 30.000000)
output-file
Name of the output file to generated; if not specified then
output will be written to standard output

The two attached .stl files, maze-8x8.stl and maze-10x10.stl, were both generated with this script.
Tags
This Thing has no tags.
Report as inappropriate

You must be logged in to post a comment.

This is seriously cool! I'm generating mazes like crazy, and having a great time!

Two trivial bugs to report, though:
- The first line of the .scad file is commented with #, which doesn't compile (at least for me). Changing this to // works fine.
- I can't get the -t option to work. When I set it, the maze turns solid. Or am I doing something wrong?

solid: python maze.py -l200
-r16 -w200 -c16 -t10 maze3.scad
fine: python maze.py -l200 -r16 -w200 -c16 maze3.scad

So thanks again. This rocks!

FWIW, there's now a warning when you select a wall thickness which exceeds one-half the cell's length or width. I also changed the code to default the thickness to 0.2 times the smaller of the cell's length or width.

-t does work, but possibly not as intuitively as it should. A wall thickness of -t10 (10 mm) is TOO thick. I wrote the code to make the -l and -w dimensions be the absolute length and width of the object. So, the dimension of each cell *including* its walls will be length/column-count by width/row-count. Using your 200 x 200 mm design with 16 x 16 cells, that makes for 12.5 x 12.5 mm wide cells. Now put walls which are 10 mm thick into that cell and you get a solid fill (since you have a 10mm wall on the left and a 10 mm wall on the right -- they end up overlapping).

I think I'll change the code to make the wall thickness default to 1/10 of min(cell-width, cell-length). And print a warning if you make the thickness exceed 0.5 of min(cell-width, cell-length).

Thanks for the feed back and glad you enjoy the script. I couldn't believe how nice my samples print
ed -- the photos don't capture just how well these come out.

Dan

Whoops, too many different programming languages in the same day. Sorry about the wrong comment introducer. It's now fixed and a revised maze.py uploaded. (As you might tell, I put that in at the last moment and as an afterthought.) Thanks for reporting it.

I'll see what's up with -t next.

Dan

Remixes

Liked by

Give a Shout Out

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

More from dnewman

More from 2D Art