--no-invert → --toggle-invert, and add support thereto in maze_svg

This commit is contained in:
Starbeamrainbowlabs 2020-09-28 00:53:52 +01:00
parent d1c2b25bc5
commit 5d26acf992
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 37 additions and 10 deletions

View file

@ -23,7 +23,7 @@ local settings = {
seed = os.time(),
-- TODO: Add branching factor setting here & associated CLI argument
filename = "maze.scad",
filename = nil,
scale = 5,
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("-s --seed")..a.value(" {string}")..[[ Sets the seed
]]..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("-l --path-length")..a.value(" {int}")..[[ Sets the path length
]]..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
i = i + 1
settings.scale = tonumber(arg[i])
elseif arg[i] == "--no-invert" then
elseif arg[i] == "--toggle-invert" then
settings.inverted = false
elseif arg[i] == "--path-length" or arg[i] == "-l" then
i = i + 1
@ -145,7 +145,22 @@ local function maze_svg()
settings.path_length,
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
local function maze3d_text()
@ -175,6 +190,11 @@ local function maze3d_openscad()
settings.path_depth
)
if not settings.filename then
print(a.fred(a.hicol("Error: No outupt filename specified.")))
return false
end
local openscad_settings = {
scale = settings.scale,
inverted = settings.inverted

View file

@ -33,15 +33,22 @@ function M.printspace(space, w, h)
end
end
function M.make_svg(space, width, height, scale, fill)
local result = { svg.start(width * scale, height * scale) }
function M.make_svg(space, width, height, settings)
-- Settings: scale, colour, inverted
local result = { svg.start(width * settings.scale, height * settings.scale) }
for y = 0, height - 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(
x * scale, y * scale,
scale, scale,
fill
x * settings.scale, y * settings.scale,
settings.scale, settings.scale,
settings.colour
))
end
end