This commit is contained in:
Julian Brammer 2024-06-13 21:22:29 +02:00
parent 35ed90dc51
commit d8c7168938
2 changed files with 95 additions and 2 deletions

View File

@ -120,7 +120,7 @@ end
function main()
print("Print with Chest? [yn]")
local withChest = confirmationDialog()
local withChest = confirmationDialog(read())
print("Filepath? (/brulijam/files/shape.svg)")
local filePath = read()
@ -135,7 +135,7 @@ function main()
print("One Layer would need " .. blockCounter .. " Blocks.")
print("Continue? [yn]")
local startPrinting = confirmationDialog()
local startPrinting = confirmationDialog(read())
if startPrinting then
printLayer(matrix, withChest)

View File

@ -0,0 +1,93 @@
-- 3D Drucker using https://minecraftshapes.com/
-- dimensions of the matrix
length = 64
basic = require("lib.basic")
-- pixel size from the generator, should be constant
steps = 18
-- see if the file exists
function file_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end
-- get all lines from a file, returns an empty
-- list/table if the file does not exist
function lines_from(file)
if not file_exists(file) then return {} end
local lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end
-- tests the functions above
local file = 'brulijam/files/shape-hex-64-20.svg'
local lines = lines_from(file)
-- print all line numbers and their contents
--for k,v in pairs(lines) do
-- print('line[' .. k .. ']', v)
--end
matrix = {}
for i = 1, length do
matrix[i] = {}
for j = 1, length do
matrix[i][j] = 0
end
end
for k,v in pairs(lines) do
print(k)
if string.match(v, "green") then
--print(k .. ": yay")
-- lines containing "green"
xStart = string.find(v, "x=\"")
xEnd = string.find(v, "\" y=")
yStart = string.find(v, "y=\"")
yEnd = string.find(v, "\" st")
xStr = string.sub(v, xStart+3, xEnd-1)
yStr = string.sub(v, yStart+3, yEnd-1)
x = tonumber(xStr) / steps
y = tonumber(yStr) / steps
print(x .. " " .. y)
matrix[x][y] = 1
end
end
function buildShape(matrix)
for i=1, #matrix do
for j=1, #matrix[i] do
--print(i .. "," .. j .. ": " .. matrix[i][j])
--sleep(1)
if matrix[i][j] == 1 then
turtle.placeDown()
end
turtle.forward()
end
for j=1, #matrix[i] do
turtle.back()
end
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end
end
buildShape(matrix)