multimaze/openscad.lua
Starbeamrainbowlabs c3768aca2e
Create CLI
....I forgot to commit, didn't I?
2020-04-29 19:57:18 +01:00

28 lines
845 B
Lua

local M = {}
function M.write3d(maze, width, height, depth, filename)
local scale = 5
local inverted = true
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")
out:write("// Uncomment to make the preview look transclucent")
out:write("// color(\"red\", 0.25)\n");
if inverted then out:write("difference() {\n\tcube(size=["..scale*width..", "..scale*height..", "..scale*depth.."])")
else out:write("union() {") end
out:write("\n")
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] == "#" then
out:write("\ttranslate(["..x*scale..", "..y*scale..", "..z*scale.."]) cube(size = "..scale..");\n")
end
end
end
end
out:write("}\n")
out:close()
end
return M