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
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
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.
The global variable linesCount1 is used, in part to show how global variables can be used, when appropriate, as some languages require special handling or access mechanisms for global variables.
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.
5. Julia code notes
Julia has some programming language features that are not found in many other languages.
A function name that ends in the exclamation point "!" (or "bang") operator is, by convention, a function that modifies one or more actual parameters passed to it. If defined that way (e.g., in libraries), the exclamation point must be provided (e.g., in the Random.seed! function call).
A symbol is a name that is preceded by a color ":", such as ":stroke". Other languages might use enumerations, constants, variables, etc., for a similar purpose.
The modules used, such as Luxor, do not need to always be explicitly written, but have been in the above code for example purposes.
6. SVG output
7. End of page