Add additional settings for openscad

This commit is contained in:
Starbeamrainbowlabs 2020-04-30 19:10:32 +01:00
parent 5711d7d1f7
commit 00922c6fd6
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
3 changed files with 40 additions and 14 deletions

View File

@ -1,3 +1,15 @@
# multimaze
A collection of maze generation programs
> A collection of maze generation programs
## `main.lua`
Ported back in 2015 (and sine adapted) from an algorithm of my own design that originally implemented in Python.
Now has a 3d mode!
To render a 3D maze as a .STL file, do this:
```bash
lua main.lua maze3d_openscad -w 91 -h 91 -d 71 -f 91x91x71.scad
openscad -o 91x91x71.stl 91x91x71.scad
```

View File

@ -12,7 +12,10 @@ local settings = {
height = 11,
depth = 7,
filename = "maze.scad"
filename = "maze.scad",
scale = 5,
inverted = true
}
for i=1,#arg do
@ -33,6 +36,11 @@ for i=1,#arg do
elseif string.match(arg[i], "--filename") or string.match(arg[i], "-f") then
i = i + 1
settings.filename = arg[i]
elseif string.match(arg[i], "--scale") then
i = i + 1
settings.scale = tonumber(arg[i])
elseif string.match(arg[i], "--no-invert") then
settings.inverted = false
end
end
@ -55,11 +63,13 @@ Modes:
maze3d_openscad Generates a 3d maze as an openscad file
Options:
-w --width Sets the width of the maze
-h --height Sets the height of the maze
-d --depth Sets the depth of the maze (only applicable to 3d mazes)
-s --seed Sets the seed
-f --filename Sets the output filename
-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]
]])
end
@ -94,10 +104,16 @@ local function maze3d_openscad()
settings.depth
)
local openscad_settings = {
scale = settings.scale,
inverted = settings.inverted
}
openscad.write3d(
world,
settings.width, settings.height, settings.depth,
settings.filename
settings.filename,
openscad_settings
)
print("Maze written to "..settings.filename)
end

View File

@ -1,8 +1,6 @@
local M = {}
function M.write3d(maze, width, height, depth, filename)
local scale = 5
local inverted = true
function M.write3d(maze, width, height, depth, filename, settings)
local out = io.open(filename, "w")
out:write("// Generated by multimaze (lua)\n")
out:write("// Hit the Render button (F6) to make the preview look better\n")
@ -13,9 +11,9 @@ function M.write3d(maze, width, height, depth, filename)
for z = 0, depth - 1, 1 do
for y = 0, height - 1, 1 do
for x = 0, width - 1, 1 do
if (maze[z][y][x] == "#" and not inverted) or
(maze[z][y][x] == " " and inverted) then
out:write("\ttranslate(["..x*scale..", "..y*scale..", "..z*scale.."]) cube(size = "..scale..");\n")
if (maze[z][y][x] == "#" and not settings.inverted) or
(maze[z][y][x] == " " and settings.inverted) then
out:write("\ttranslate(["..x*settings.scale..", "..y*settings.scale..", "..z*settings.scale.."]) cube(size = "..settings.scale..");\n")
end
end
end