 |

Submitted by , posted on 22 March 2005
|
 |
Image Description, by

Following a post on the comp.lang.functional newsgroup asking for a 2D maze
generator written in a functional style, I wrote this little 131-line OCaml
program to generate and render simple 2D mazes using OpenGL and also export
the result as PostScript.
The program stores the set of visited grid cells as a mapping from (x, y)
coordinates (of type "int * int") to booleans, implemented as a balanced
binary tree by the OCaml library. The grid is then traversed recursively from
the bottom left-hand cell (0, 0) by moving randomly to unvisited, on-board
neighbours left, right, up or down.
The maze is rendered while it is generated, as OpenGL points and lines. The
result is memoized in a display list for fast redisplay.
The complete source code, along with the compilation command, is available
on-line here:
http://www.ffconsultancy.com/free/maze/
Cheers,
Jon.
|
|