maze3d: implement path dimension customisations
This commit is contained in:
parent
bd73860768
commit
d077b17462
3 changed files with 106 additions and 62 deletions
26
main.lua
26
main.lua
|
@ -20,7 +20,8 @@ local settings = {
|
||||||
inverted = true,
|
inverted = true,
|
||||||
|
|
||||||
path_length = 2,
|
path_length = 2,
|
||||||
path_width = 1
|
path_width = 1,
|
||||||
|
path_depth = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
for i=1,#arg do
|
for i=1,#arg do
|
||||||
|
@ -52,6 +53,9 @@ for i=1,#arg do
|
||||||
elseif arg[i] == "--path-width" then
|
elseif arg[i] == "--path-width" then
|
||||||
i = i + 1
|
i = i + 1
|
||||||
settings.path_width = tonumber(arg[i])
|
settings.path_width = tonumber(arg[i])
|
||||||
|
elseif arg[i] == "--path-depth" then
|
||||||
|
i = i + 1
|
||||||
|
settings.path_depth = tonumber(arg[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,15 +63,6 @@ if #settings.extras > 0 then
|
||||||
settings.mode = table.remove(settings.extras, 1)
|
settings.mode = table.remove(settings.extras, 1)
|
||||||
end
|
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()
|
local function help()
|
||||||
print([[
|
print([[
|
||||||
multimaze: Multidimensional maze generator
|
multimaze: Multidimensional maze generator
|
||||||
|
@ -92,6 +87,7 @@ Options:
|
||||||
--scale {int} Sets the scale of the output [openscad output only]
|
--scale {int} Sets the scale of the output [openscad output only]
|
||||||
--path-length {int} Sets the path length
|
--path-length {int} Sets the path length
|
||||||
--path-width {int} Sets the path width
|
--path-width {int} Sets the path width
|
||||||
|
--path-depth {int} Sets the path depth [3d only]
|
||||||
]])
|
]])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -112,7 +108,10 @@ local function maze3d_text()
|
||||||
settings.seed,
|
settings.seed,
|
||||||
settings.width,
|
settings.width,
|
||||||
settings.height,
|
settings.height,
|
||||||
settings.depth
|
settings.depth,
|
||||||
|
settings.path_length,
|
||||||
|
settings.path_width,
|
||||||
|
settings.path_depth
|
||||||
)
|
)
|
||||||
|
|
||||||
maze3d.printspace(world, settings.width, settings.height, settings.depth)
|
maze3d.printspace(world, settings.width, settings.height, settings.depth)
|
||||||
|
@ -125,7 +124,10 @@ local function maze3d_openscad()
|
||||||
setting.seed,
|
setting.seed,
|
||||||
settings.width,
|
settings.width,
|
||||||
settings.height,
|
settings.height,
|
||||||
settings.depth
|
settings.depth,
|
||||||
|
settings.path_length,
|
||||||
|
settings.path_width,
|
||||||
|
settings.path_depth
|
||||||
)
|
)
|
||||||
|
|
||||||
local openscad_settings = {
|
local openscad_settings = {
|
||||||
|
|
1
maze.lua
1
maze.lua
|
@ -39,7 +39,6 @@ function M.generate_maze(seed, width, height, path_length, path_width)
|
||||||
if not path_length then path_length = 2 end
|
if not path_length then path_length = 2 end
|
||||||
if not path_width then path_width = 1 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
|
math.randomseed(seed) -- seed the random number generator with the system clock
|
||||||
|
|
||||||
width = width - 1
|
width = width - 1
|
||||||
|
|
139
maze3d.lua
139
maze3d.lua
|
@ -4,26 +4,26 @@
|
||||||
-- A test by @Starbeamrainbowlabs
|
-- A test by @Starbeamrainbowlabs
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
if arg[1] ~= nil then
|
-- if arg[1] ~= nil then
|
||||||
width = tonumber(arg[1])
|
-- width = tonumber(arg[1])
|
||||||
else
|
-- else
|
||||||
width = 35
|
-- width = 35
|
||||||
end
|
-- end
|
||||||
if arg[2] ~= nil then
|
-- if arg[2] ~= nil then
|
||||||
height = tonumber(arg[2])
|
-- height = tonumber(arg[2])
|
||||||
else
|
-- else
|
||||||
height = 15
|
-- height = 15
|
||||||
end
|
-- end
|
||||||
if arg[3] ~= nil then
|
-- if arg[3] ~= nil then
|
||||||
depth = tonumber(arg[3])
|
-- depth = tonumber(arg[3])
|
||||||
else
|
-- else
|
||||||
depth = 7
|
-- depth = 7
|
||||||
end
|
-- end
|
||||||
if arg[4] ~= nil then
|
-- if arg[4] ~= nil then
|
||||||
seed = tonumber(arg[4])
|
-- seed = tonumber(arg[4])
|
||||||
else
|
-- else
|
||||||
seed = os.time()
|
-- seed = os.time()
|
||||||
end
|
-- end
|
||||||
|
|
||||||
----------------------------------
|
----------------------------------
|
||||||
-- function to print out the world
|
-- function to print out the world
|
||||||
|
@ -43,15 +43,16 @@ end
|
||||||
|
|
||||||
-- Initialise the world
|
-- 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()
|
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)
|
print("Generating maze "..width.."x"..height.."x"..depth)
|
||||||
math.randomseed(seed) -- seed the random number generator with the system clock
|
math.randomseed(seed) -- seed the random number generator with the system clock
|
||||||
|
|
||||||
width = width - 1
|
|
||||||
height = height - 1
|
|
||||||
|
|
||||||
local world = {}
|
local world = {}
|
||||||
for z = 0, depth, 1 do
|
for z = 0, depth, 1 do
|
||||||
world[z] = {}
|
world[z] = {}
|
||||||
|
@ -74,22 +75,22 @@ function M.generate_maze(seed, width, height, depth)
|
||||||
--print("Nodes left: " .. #nodes)
|
--print("Nodes left: " .. #nodes)
|
||||||
|
|
||||||
local directions = "" -- the different directions we can move in
|
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 .. "-"
|
directions = directions .. "-"
|
||||||
end
|
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 .. "+"
|
directions = directions .. "+"
|
||||||
end
|
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"
|
directions = directions .. "u"
|
||||||
end
|
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"
|
directions = directions .. "d"
|
||||||
end
|
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"
|
directions = directions .. "l"
|
||||||
end
|
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"
|
directions = directions .. "r"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -104,29 +105,71 @@ function M.generate_maze(seed, width, height, depth)
|
||||||
|
|
||||||
|
|
||||||
if curdir == "+" then
|
if curdir == "+" then
|
||||||
world[cz + 1][cy][cx] = " "
|
for iz = cz,cz+path_length+(path_depth-1) do
|
||||||
world[cz + 2][cy][cx] = " "
|
for ix = cx,cx+(path_width-1) do
|
||||||
cz = cz + 2
|
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
|
elseif curdir == "-" then
|
||||||
world[cz - 1][cy][cx] = " "
|
for iz = cz,cz-path_length do
|
||||||
world[cz - 2][cy][cx] = " "
|
for ix = cx,cx+(path_width-1) do
|
||||||
cz = cz - 2
|
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
|
elseif curdir == "u" then
|
||||||
world[cz][cy - 1][cx] = " "
|
for iz = cz,cz+(path_depth-1) do
|
||||||
world[cz][cy - 2][cx] = " "
|
for ix = cx,cx+(path_width-1) do
|
||||||
cy = cy - 2
|
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
|
elseif curdir == "d" then
|
||||||
world[cz][cy + 1][cx] = " "
|
for iz = cz,cz+(path_depth-1) do
|
||||||
world[cz][cy + 2][cx] = " "
|
for ix = cx,cx+(path_width-1) do
|
||||||
cy = cy + 2
|
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
|
elseif curdir == "l" then
|
||||||
world[cz][cy][cx - 1] = " "
|
for iz = cz,cz+(path_depth-1) do
|
||||||
world[cz][cy][cx - 2] = " "
|
for iy = cy,cy+(path_width-1) do
|
||||||
cx = cx - 2
|
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
|
elseif curdir == "r" then
|
||||||
world[cz][cy][cx + 1] = " "
|
for iz = cz,cz+(path_depth-1) do
|
||||||
world[cz][cy][cx + 2] = " "
|
for iy = cy,cy+(path_width-1) do
|
||||||
cx = cx + 2
|
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
|
end
|
||||||
|
|
||||||
table.insert(nodes, { x = cx, y = cy, z = cz })
|
table.insert(nodes, { x = cx, y = cy, z = cz })
|
||||||
|
|
Loading…
Reference in a new issue