From d8c7168938b796daba4915b0d5092ab0a5679f6b Mon Sep 17 00:00:00 2001 From: brulijam Date: Thu, 13 Jun 2024 21:22:29 +0200 Subject: [PATCH] . --- src/brulijam/printerMakesBrrr.lua | 4 +- src/brulijam/shapeBuilder.lua | 93 +++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/brulijam/shapeBuilder.lua diff --git a/src/brulijam/printerMakesBrrr.lua b/src/brulijam/printerMakesBrrr.lua index 4054ecb..ff88e13 100644 --- a/src/brulijam/printerMakesBrrr.lua +++ b/src/brulijam/printerMakesBrrr.lua @@ -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) diff --git a/src/brulijam/shapeBuilder.lua b/src/brulijam/shapeBuilder.lua new file mode 100644 index 0000000..c467659 --- /dev/null +++ b/src/brulijam/shapeBuilder.lua @@ -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) +