Loading

OpenSCAD Maze Generator

by dnewman, published

OpenSCAD Maze Generator by dnewman Jun 9, 2012
2 Share
Download All Files

Thing Apps Enabled

Order This Printed View All Apps

Contents

Liked By

View All

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

Makes

Thing Statistics

9603Views 3737Downloads Found in 2D Art

Summary

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.

More from 2D Art

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

Print through a distributed network of 3D printing enthusiasts from across the US, at a fraction of the cost of the competitors. We want to change the world for the better through technology, an...

App Info Launch App

Quickly Scale, Mirror or Cut your 3D Models

App Info Launch App

3D Print a wide range of designs with Treatstock. Easy to use tools to get the perfect result. The global 3D printing network that connects you with high-quality and fast working print services nea...

App Info Launch App

Hi, I am new to Python and OpenSCAD.

How to run this command?
% python maze.py maze.scad

I downloaded maze.py but modified the file. But I don't know how to change it to maze.scad.

You need to install Python on your computer. Then open a terminal window (command window) and issue the proper command to run Python on your operating system. The command shown in the Instructions section here is suitable for Linux and Mac OS X. If you are on Windows, you are on your own: you will need to determine how to install and run Python on Windows. I myself do not use Windows so I'm not in a position to help you with that platform.

Thanks.
Finally, I open maze.py in Python and then edit it.
Then, run it to generate the code.
Copy it and paste it in OpenSCAD.
Remove a few unnecessary commands and export it to STL file.
It works.

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 http://maze.pymaze.py -l200
-r16 -w200 -c16 -t10 maze3.scad
fine: python http://maze.pymaze.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 http://maze.pymaze.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

Top