2020-04-29 18:57:18 +00:00
|
|
|
local strings = require("./utils/strings")
|
|
|
|
local debug = require("./utils/print_r")
|
2020-05-03 13:49:20 +00:00
|
|
|
local calculations = require("./utils/calculations")
|
2020-04-29 18:57:18 +00:00
|
|
|
local maze2d = require("./maze")
|
|
|
|
local maze3d = require("./maze3d")
|
|
|
|
local openscad = require("./openscad")
|
|
|
|
|
|
|
|
local settings = {
|
|
|
|
mode = "help",
|
|
|
|
extras = {},
|
|
|
|
|
|
|
|
width = 11,
|
|
|
|
height = 11,
|
|
|
|
depth = 7,
|
|
|
|
|
2020-05-03 01:00:19 +00:00
|
|
|
seed = os.time(),
|
2020-04-30 18:10:32 +00:00
|
|
|
filename = "maze.scad",
|
|
|
|
|
|
|
|
scale = 5,
|
2020-05-03 13:23:25 +00:00
|
|
|
inverted = true,
|
|
|
|
|
|
|
|
path_length = 2,
|
2020-05-03 15:48:50 +00:00
|
|
|
path_width = 1,
|
|
|
|
path_depth = 1
|
2020-04-29 18:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i=1,#arg do
|
|
|
|
if not strings.starts_with(arg[i], "-") then
|
2020-05-03 13:23:25 +00:00
|
|
|
table.insert(settings.extras, arg[i])
|
|
|
|
elseif arg[i] == "--width" or arg[i] == "-w" then
|
2020-04-29 18:57:18 +00:00
|
|
|
i = i + 1
|
|
|
|
settings.width = tonumber(arg[i])
|
2020-05-03 13:23:25 +00:00
|
|
|
elseif arg[i] == "--height" or arg[i] == "-h" then
|
2020-04-29 18:57:18 +00:00
|
|
|
i = i + 1
|
|
|
|
settings.height = tonumber(arg[i])
|
2020-05-03 13:23:25 +00:00
|
|
|
elseif arg[i] == "--depth" or arg[i] == "-d" then
|
2020-04-29 18:57:18 +00:00
|
|
|
i = i + 1
|
|
|
|
settings.depth = tonumber(arg[i])
|
2020-05-03 13:23:25 +00:00
|
|
|
elseif arg[i] == "--seed" or arg[i] == "-s" then
|
2020-04-29 18:57:18 +00:00
|
|
|
i = i + 1
|
|
|
|
settings.seed = tonumber(arg[i])
|
2020-05-03 13:23:25 +00:00
|
|
|
elseif arg[i] == "--filename" or arg[i] == "-f" then
|
2020-04-29 18:57:18 +00:00
|
|
|
i = i + 1
|
|
|
|
settings.filename = arg[i]
|
2020-05-03 13:23:25 +00:00
|
|
|
elseif arg[i] == "--scale" then
|
2020-04-30 18:10:32 +00:00
|
|
|
i = i + 1
|
|
|
|
settings.scale = tonumber(arg[i])
|
2020-05-03 13:23:25 +00:00
|
|
|
elseif arg[i] == "--no-invert" then
|
2020-04-30 18:10:32 +00:00
|
|
|
settings.inverted = false
|
2020-05-03 13:23:25 +00:00
|
|
|
elseif arg[i] == "--path-length" then
|
|
|
|
i = i + 1
|
|
|
|
settings.path_length = tonumber(arg[i])
|
|
|
|
elseif arg[i] == "--path-width" then
|
|
|
|
i = i + 1
|
|
|
|
settings.path_width = tonumber(arg[i])
|
2020-05-03 15:48:50 +00:00
|
|
|
elseif arg[i] == "--path-depth" then
|
|
|
|
i = i + 1
|
|
|
|
settings.path_depth = tonumber(arg[i])
|
2020-04-29 18:57:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if #settings.extras > 0 then
|
|
|
|
settings.mode = table.remove(settings.extras, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function help()
|
|
|
|
print([[
|
|
|
|
multimaze: Multidimensional maze generator
|
|
|
|
By Starbeamrainbowlabs
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
lua main.lua {mode} [{options}]
|
|
|
|
|
|
|
|
Modes:
|
|
|
|
help Displays this message
|
|
|
|
maze Generates a 2d maze
|
|
|
|
maze3d Generates a 3d maze
|
|
|
|
maze3d_openscad Generates a 3d maze as an openscad file
|
|
|
|
|
|
|
|
Options:
|
2020-04-30 18:10:32 +00:00
|
|
|
-w --width {int} Sets the width of the maze
|
|
|
|
-h --height {int} Sets the height of the maze
|
|
|
|
-d --depth {int} Sets the depth of the maze [3d only]
|
|
|
|
-s --seed {string} Sets the seed
|
|
|
|
-f --filename {string} Sets the output filename
|
|
|
|
--no-invert Don't invert the output [openscad output only]
|
|
|
|
--scale {int} Sets the scale of the output [openscad output only]
|
2020-05-03 13:23:25 +00:00
|
|
|
--path-length {int} Sets the path length
|
|
|
|
--path-width {int} Sets the path width
|
2020-05-03 15:48:50 +00:00
|
|
|
--path-depth {int} Sets the path depth [3d only]
|
2020-04-29 18:57:18 +00:00
|
|
|
]])
|
|
|
|
end
|
|
|
|
|
|
|
|
local function maze_text()
|
|
|
|
local world, time = maze2d.generate_maze(
|
2020-05-03 01:00:19 +00:00
|
|
|
settings.seed,
|
2020-04-29 18:57:18 +00:00
|
|
|
settings.width,
|
2020-05-03 13:23:25 +00:00
|
|
|
settings.height,
|
|
|
|
settings.path_length,
|
|
|
|
settings.path_width
|
2020-04-29 18:57:18 +00:00
|
|
|
)
|
|
|
|
maze2d.printspace(world, settings.width, settings.height)
|
|
|
|
print("Generation completed in " .. time .. "ms.")
|
|
|
|
end
|
|
|
|
|
|
|
|
local function maze3d_text()
|
|
|
|
local world, time = maze3d.generate_maze(
|
2020-05-03 01:00:19 +00:00
|
|
|
settings.seed,
|
2020-04-29 18:57:18 +00:00
|
|
|
settings.width,
|
|
|
|
settings.height,
|
2020-05-03 15:48:50 +00:00
|
|
|
settings.depth,
|
|
|
|
settings.path_length,
|
|
|
|
settings.path_width,
|
|
|
|
settings.path_depth
|
2020-04-29 18:57:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
maze3d.printspace(world, settings.width, settings.height, settings.depth)
|
|
|
|
|
|
|
|
print("Generation completed in " .. time .. "ms.")
|
|
|
|
end
|
|
|
|
|
|
|
|
local function maze3d_openscad()
|
|
|
|
local world, time = maze3d.generate_maze(
|
2020-08-27 21:37:09 +00:00
|
|
|
settings.seed,
|
2020-04-29 18:57:18 +00:00
|
|
|
settings.width,
|
|
|
|
settings.height,
|
2020-05-03 15:48:50 +00:00
|
|
|
settings.depth,
|
|
|
|
settings.path_length,
|
|
|
|
settings.path_width,
|
|
|
|
settings.path_depth
|
2020-04-29 18:57:18 +00:00
|
|
|
)
|
|
|
|
|
2020-04-30 18:10:32 +00:00
|
|
|
local openscad_settings = {
|
|
|
|
scale = settings.scale,
|
|
|
|
inverted = settings.inverted
|
|
|
|
}
|
|
|
|
|
2020-04-29 18:57:18 +00:00
|
|
|
openscad.write3d(
|
|
|
|
world,
|
|
|
|
settings.width, settings.height, settings.depth,
|
2020-04-30 18:10:32 +00:00
|
|
|
settings.filename,
|
|
|
|
openscad_settings
|
2020-04-29 18:57:18 +00:00
|
|
|
)
|
|
|
|
print("Maze written to "..settings.filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
local mode_functions = {
|
|
|
|
["help"] = help,
|
|
|
|
["maze"] = maze_text,
|
|
|
|
["maze3d"] = maze3d_text,
|
|
|
|
["maze3d_openscad"] = maze3d_openscad
|
|
|
|
}
|
|
|
|
|
|
|
|
local selection = mode_functions[settings.mode]
|
|
|
|
if not selection then
|
|
|
|
print("Error: Unrecognised mode '"..settings.mode.."'")
|
|
|
|
selection = mode_functions["help"]
|
|
|
|
end
|
|
|
|
|
|
|
|
selection()
|