maze3d: implement path dimension customisations

This commit is contained in:
Starbeamrainbowlabs 2020-05-03 16:48:50 +01:00
parent bd73860768
commit d077b17462
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
3 changed files with 106 additions and 62 deletions

View File

@ -20,7 +20,8 @@ local settings = {
inverted = true,
path_length = 2,
path_width = 1
path_width = 1,
path_depth = 1
}
for i=1,#arg do
@ -52,6 +53,9 @@ for i=1,#arg do
elseif arg[i] == "--path-width" then
i = i + 1
settings.path_width = tonumber(arg[i])
elseif arg[i] == "--path-depth" then
i = i + 1
settings.path_depth = tonumber(arg[i])
end
end
@ -59,15 +63,6 @@ if #settings.extras > 0 then
settings.mode = table.remove(settings.extras, 1)
end
-- local new_width = calculations.normalise_dimension(settings.width, settings.path_length, settings.path_width)
-- print("[normalise] width "..settings.width.." → "..new_width)
-- settings.width = new_width
--
-- local new_height = calculations.normalise_dimension(settings.height, settings.path_length, settings.path_width)
-- print("[normalise] height "..settings.height.." → "..new_height)
-- settings.height = new_height
local function help()
print([[
multimaze: Multidimensional maze generator
@ -92,6 +87,7 @@ Options:
--scale {int} Sets the scale of the output [openscad output only]
--path-length {int} Sets the path length
--path-width {int} Sets the path width
--path-depth {int} Sets the path depth [3d only]
]])
end
@ -112,7 +108,10 @@ local function maze3d_text()
settings.seed,
settings.width,
settings.height,
settings.depth
settings.depth,
settings.path_length,
settings.path_width,
settings.path_depth
)
maze3d.printspace(world, settings.width, settings.height, settings.depth)
@ -125,7 +124,10 @@ local function maze3d_openscad()
setting.seed,
settings.width,
settings.height,
settings.depth
settings.depth,
settings.path_length,
settings.path_width,
settings.path_depth
)
local openscad_settings = {

View File

@ -38,8 +38,7 @@ function M.generate_maze(seed, width, height, path_length, path_width)
if not path_length then path_length = 2 end
if not path_width then path_width = 1 end
-- minetest.log("action", "width: "..width..", height: "..height)
math.randomseed(seed) -- seed the random number generator with the system clock
width = width - 1

View File

@ -4,26 +4,26 @@
-- A test by @Starbeamrainbowlabs
local M = {}
if arg[1] ~= nil then
width = tonumber(arg[1])
else
width = 35
end
if arg[2] ~= nil then
height = tonumber(arg[2])
else
height = 15
end
if arg[3] ~= nil then
depth = tonumber(arg[3])
else
depth = 7
end
if arg[4] ~= nil then
seed = tonumber(arg[4])
else
seed = os.time()
end
-- if arg[1] ~= nil then
-- width = tonumber(arg[1])
-- else
-- width = 35
-- end
-- if arg[2] ~= nil then
-- height = tonumber(arg[2])
-- else
-- height = 15
-- end
-- if arg[3] ~= nil then
-- depth = tonumber(arg[3])
-- else
-- depth = 7
-- end
-- if arg[4] ~= nil then
-- seed = tonumber(arg[4])
-- else
-- seed = os.time()
-- end
----------------------------------
-- function to print out the world
@ -43,15 +43,16 @@ end
-- Initialise the world
function M.generate_maze(seed, width, height, depth)
function M.generate_maze(seed, width, height, depth, path_length, path_width, path_depth)
start_time = os.clock()
if not path_length then path_length = 2 end
if not path_width then path_width = 1 end
if not path_depth then path_depth = 1 end
print("Generating maze "..width.."x"..height.."x"..depth)
math.randomseed(seed) -- seed the random number generator with the system clock
width = width - 1
height = height - 1
local world = {}
for z = 0, depth, 1 do
world[z] = {}
@ -74,22 +75,22 @@ function M.generate_maze(seed, width, height, depth)
--print("Nodes left: " .. #nodes)
local directions = "" -- the different directions we can move in
if cz - 2 > 0 and world[cz - 2][cy][cx] == "#" then
if cz - path_length > 0 and world[cz - path_length][cy][cx] == "#" then
directions = directions .. "-"
end
if cz + 2 < depth and world[cz + 2][cy][cx] == "#" then
if cz + path_length < depth-path_depth and world[cz + path_length][cy][cx] == "#" then
directions = directions .. "+"
end
if cy - 2 > 0 and world[cz][cy - 2][cx] == "#" then
if cy - path_length > 0 and world[cz][cy - path_length][cx] == "#" then
directions = directions .. "u"
end
if cy + 2 < height and world[cz][cy + 2][cx] == "#" then
if cy + path_length < height-path_width and world[cz][cy + path_length][cx] == "#" then
directions = directions .. "d"
end
if cx - 2 > 0 and world[cz][cy][cx - 2] == "#" then
if cx - path_length > 0 and world[cz][cy][cx - path_length] == "#" then
directions = directions .. "l"
end
if cx + 2 < width and world[cz][cy][cx + 2] == "#" then
if cx + path_length < width-path_width and world[cz][cy][cx + path_length] == "#" then
directions = directions .. "r"
end
@ -104,29 +105,71 @@ function M.generate_maze(seed, width, height, depth)
if curdir == "+" then
world[cz + 1][cy][cx] = " "
world[cz + 2][cy][cx] = " "
cz = cz + 2
for iz = cz,cz+path_length+(path_depth-1) do
for ix = cx,cx+(path_width-1) do
for iy = cy,cy+(path_width-1) do
world[iz][iy][ix] = " "
end
end
end
-- world[cz + 1][cy][cx] = " "
-- world[cz + 2][cy][cx] = " "
cz = cz + path_length
elseif curdir == "-" then
world[cz - 1][cy][cx] = " "
world[cz - 2][cy][cx] = " "
cz = cz - 2
for iz = cz,cz-path_length do
for ix = cx,cx+(path_width-1) do
for iy = cy,cy+(path_width-1) do
world[iz][iy][ix] = " "
end
end
end
-- world[cz - 1][cy][cx] = " "
-- world[cz - 2][cy][cx] = " "
cz = cz - path_length
elseif curdir == "u" then
world[cz][cy - 1][cx] = " "
world[cz][cy - 2][cx] = " "
cy = cy - 2
for iz = cz,cz+(path_depth-1) do
for ix = cx,cx+(path_width-1) do
for iy = cy-path_length,cy do
world[iz][iy][ix] = " "
end
end
end
-- world[cz][cy - 1][cx] = " "
-- world[cz][cy - 2][cx] = " "
cy = cy - path_length
elseif curdir == "d" then
world[cz][cy + 1][cx] = " "
world[cz][cy + 2][cx] = " "
cy = cy + 2
for iz = cz,cz+(path_depth-1) do
for ix = cx,cx+(path_width-1) do
for iy = cy,cy+path_length+(path_width-1) do
world[iz][iy][ix] = " "
end
end
end
-- world[cz][cy + 1][cx] = " "
-- world[cz][cy + 2][cx] = " "
cy = cy + path_length
elseif curdir == "l" then
world[cz][cy][cx - 1] = " "
world[cz][cy][cx - 2] = " "
cx = cx - 2
for iz = cz,cz+(path_depth-1) do
for iy = cy,cy+(path_width-1) do
for ix = cx-path_length,cx do
world[iz][iy][ix] = " "
end
end
end
-- world[cz][cy][cx - 1] = " "
-- world[cz][cy][cx - 2] = " "
cx = cx - path_length
elseif curdir == "r" then
world[cz][cy][cx + 1] = " "
world[cz][cy][cx + 2] = " "
cx = cx + 2
for iz = cz,cz+(path_depth-1) do
for iy = cy,cy+(path_width-1) do
for ix = cx,cx+path_length+(path_width-1) do
world[iz][iy][ix] = " "
end
end
end
-- world[cz][cy][cx + 1] = " "
-- world[cz][cy][cx + 2] = " "
cx = cx + path_length
end
table.insert(nodes, { x = cx, y = cy, z = cz })