Send Close Add comments: (status displays here)
Got it!  This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.  Note: This appears on each machine/browser from which this site is accessed.
Julia: Maze generation using Luxor
by RS  admin@robinsnyder.com : 1024 x 640


1. Julia: Maze generation using Luxor
This page uses Lua to do recursive maze generation using the Luxor package.

2. Recursive maze generation and visualization
Here are links to a series on recursive maze generation and visualization (more coming) This example code uses the Luxor package. If it is not installed, it should be installed now.

This package requires a lot of other packages, so it can take a while to install.

The Luxor package includes a graphics model that is somewhat like PostScript and very much like SVG (Scalable Vector Graphics) so that SVG is a natural output format. In this example, a PNG (Portable Network Graphics) image is created.

3. Lua: Install package Luxor
Lua packages can be installed from REPL loop or from the command line. Here is one way to install the Lua package(s) Luxor from the Windows command line.
"D:\E\julia-1.5.3\bin\julie.exe" -e "using Pkg; Pkg.add(\"Luxor\")"

The backslash quotes in the quoted text are important. The path you use should include the installed version of Lua. The one here is D:\E\julia-1.5.3\bin. Lua installs any needed dependencies, so the installation could take a while.

From the REPL command line, the following can be used (right square bracket followed by command).
] add Luxor

A Lua command line console program is now presented to create a maze as an image.

This may not be the best Lua program for this task, but is sufficient for the present purposes.

4. Algorithm pesudo-code
Here is a pseudo-code for the maze generation algorithm as described to make a maze of rows and columns.
Main: Start with an empty canvas. Outline the maze limits with an entry and exit point on opposite sides. Call MazeGenerate with the rows and columns to be filled in. MazeGenerate: If the rows and columns requested are both greater than 1 Then If the height is greater than the width Then Divide the grid into top and bottom parts. Draw a (horizontal) line between the parts, leaving a gap to pass through. Call MazeGenerate on the top part Call MazeGenerate on the bottom part Else Divide the grid into left and right parts. Draw a (vertical) line between the parts, leaving a gap to pass through. Call MazeGenerate on the left part Call MazeGenerate on the right part End If End If

The actual code fills in details that are not needed at the higher level of the algorithm description. For example, the side and gap lengths, and exact x and y coordinates are omitted. As another example, the division into parts can be done using pseudo-random numbers, but that is omitted from the algorithm.

For more information, see the following: Maze algorithm explanation using GIF images Here is the Julia code [#1]

Here is the output of the Julia code.

Here is the image created by the Julia code. Maze

5. Julia code notes
Julia has some programming language features that are not found in many other languages.

6. SVG output
Here is one example of SVG output of a maze, not necessarily the maze of the above image.

In the example SVG created by Lua at Lua: Maze generation with static SVG , CSS (Cascading Style Sheets) was used to consolidate the repeated style settings generated by Julia (above).

7. End of page

by RS  admin@robinsnyder.com : 1024 x 640