multimaze/openscad.lua

26 lines
794 B
Lua
Raw Normal View History

local M = {}
2020-04-30 18:10:32 +00:00
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")
out:write("// Uncomment to make the preview look transclucent\n")
out:write("// color(\"red\", 0.25)\n");
out:write("union() {\n")
for z = 0, depth - 1, 1 do
for y = 0, height - 1, 1 do
for x = 0, width - 1, 1 do
2020-04-30 18:10:32 +00:00
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
end
out:write("}\n")
out:close()
end
return M