--no-invert → --toggle-invert, and add support thereto in maze_svg
This commit is contained in:
parent
d1c2b25bc5
commit
5d26acf992
2 changed files with 37 additions and 10 deletions
28
main.lua
28
main.lua
|
@ -23,7 +23,7 @@ local settings = {
|
||||||
|
|
||||||
seed = os.time(),
|
seed = os.time(),
|
||||||
-- TODO: Add branching factor setting here & associated CLI argument
|
-- TODO: Add branching factor setting here & associated CLI argument
|
||||||
filename = "maze.scad",
|
filename = nil,
|
||||||
|
|
||||||
scale = 5,
|
scale = 5,
|
||||||
inverted = true,
|
inverted = true,
|
||||||
|
@ -63,7 +63,7 @@ local function help()
|
||||||
]]..a.item("-d --depth")..a.value(" {int}")..[[ Sets the depth of the maze [3d only]
|
]]..a.item("-d --depth")..a.value(" {int}")..[[ Sets the depth of the maze [3d only]
|
||||||
]]..a.item("-s --seed")..a.value(" {string}")..[[ Sets the seed
|
]]..a.item("-s --seed")..a.value(" {string}")..[[ Sets the seed
|
||||||
]]..a.item("-f --filename")..a.value(" {string}")..[[ Sets the output filename
|
]]..a.item("-f --filename")..a.value(" {string}")..[[ Sets the output filename
|
||||||
]]..a.item("--no-invert")..[[ Don't invert the output [openscad output only]
|
]]..a.item("--toggle-invert")..[[ Toggle inversion of the output [maz_svg, maze3d_openscad only]
|
||||||
]]..a.item("-m --scale")..a.value(" {int}")..[[ Sets the scale of the output [maze_svg, openscad output only]
|
]]..a.item("-m --scale")..a.value(" {int}")..[[ Sets the scale of the output [maze_svg, openscad output only]
|
||||||
]]..a.item("-l --path-length")..a.value(" {int}")..[[ Sets the path length
|
]]..a.item("-l --path-length")..a.value(" {int}")..[[ Sets the path length
|
||||||
]]..a.item("-y --path-width")..a.value(" {int}")..[[ Sets the path width
|
]]..a.item("-y --path-width")..a.value(" {int}")..[[ Sets the path width
|
||||||
|
@ -103,7 +103,7 @@ for i=1,#arg do
|
||||||
elseif arg[i] == "--scale" or arg[i] == "-m" then
|
elseif arg[i] == "--scale" or arg[i] == "-m" then
|
||||||
i = i + 1
|
i = i + 1
|
||||||
settings.scale = tonumber(arg[i])
|
settings.scale = tonumber(arg[i])
|
||||||
elseif arg[i] == "--no-invert" then
|
elseif arg[i] == "--toggle-invert" then
|
||||||
settings.inverted = false
|
settings.inverted = false
|
||||||
elseif arg[i] == "--path-length" or arg[i] == "-l" then
|
elseif arg[i] == "--path-length" or arg[i] == "-l" then
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
@ -145,7 +145,22 @@ local function maze_svg()
|
||||||
settings.path_length,
|
settings.path_length,
|
||||||
settings.path_width
|
settings.path_width
|
||||||
)
|
)
|
||||||
print(maze2d.make_svg(world, settings.width, settings.height, settings.scale, settings.colour))
|
|
||||||
|
local svg_settings = {
|
||||||
|
scale = settings.scale,
|
||||||
|
colour = settings.colour,
|
||||||
|
inverted = settings.inverted
|
||||||
|
}
|
||||||
|
|
||||||
|
local svg = maze2d.make_svg(world, settings.width, settings.height, svg_settings)
|
||||||
|
if not settings.filename then
|
||||||
|
print(svg)
|
||||||
|
else
|
||||||
|
local out = io.open(settings.filename, "w")
|
||||||
|
out:write(svg)
|
||||||
|
out:close()
|
||||||
|
print("Generation completed in "..time.."ms.")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function maze3d_text()
|
local function maze3d_text()
|
||||||
|
@ -175,6 +190,11 @@ local function maze3d_openscad()
|
||||||
settings.path_depth
|
settings.path_depth
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not settings.filename then
|
||||||
|
print(a.fred(a.hicol("Error: No outupt filename specified.")))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local openscad_settings = {
|
local openscad_settings = {
|
||||||
scale = settings.scale,
|
scale = settings.scale,
|
||||||
inverted = settings.inverted
|
inverted = settings.inverted
|
||||||
|
|
19
maze.lua
19
maze.lua
|
@ -33,15 +33,22 @@ function M.printspace(space, w, h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.make_svg(space, width, height, scale, fill)
|
function M.make_svg(space, width, height, settings)
|
||||||
local result = { svg.start(width * scale, height * scale) }
|
-- Settings: scale, colour, inverted
|
||||||
|
local result = { svg.start(width * settings.scale, height * settings.scale) }
|
||||||
for y = 0, height - 1, 1 do
|
for y = 0, height - 1, 1 do
|
||||||
for x = 0, width - 1, 1 do
|
for x = 0, width - 1, 1 do
|
||||||
if space[y][x] == "#" then
|
local do_square = false
|
||||||
|
if settings.inverted then
|
||||||
|
if space[y][x] == "#" then do_square = true end
|
||||||
|
else
|
||||||
|
if space[y][x] == " " then do_square = true end
|
||||||
|
end
|
||||||
|
if do_square then
|
||||||
table.insert(result, svg.rect(
|
table.insert(result, svg.rect(
|
||||||
x * scale, y * scale,
|
x * settings.scale, y * settings.scale,
|
||||||
scale, scale,
|
settings.scale, settings.scale,
|
||||||
fill
|
settings.colour
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue