diff --git a/src/brulijam/3D-Drucker.lua b/src/brulijam/3D-Drucker.lua deleted file mode 100644 index 0797486..0000000 --- a/src/brulijam/3D-Drucker.lua +++ /dev/null @@ -1,93 +0,0 @@ --- 3D Drucker using https://minecraftshapes.com/ - --- dimensions of the matrix -length = 6 - - - - -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/shape0.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) - diff --git a/src/brulijam/files/shape-hex-64-20.svg b/src/brulijam/files/shape-hex-64-20.svg new file mode 100644 index 0000000..a56125a --- /dev/null +++ b/src/brulijam/files/shape-hex-64-20.svg @@ -0,0 +1,559 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + 20 + 22 + 24 + 26 + 28 + 30 + 32 + 34 + 36 + 38 + 40 + 42 + 44 + 46 + 48 + 50 + 52 + 54 + 56 + 58 + 60 + 62 + 2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + 20 + 22 + 24 + 26 + 28 + 30 + 32 + 34 + 36 + 38 + 40 + 42 + 44 + 46 + 48 + 50 + 52 + 54 + 56 + 58 + 60 + + + MinecraftShapes.com + \ No newline at end of file diff --git a/src/brulijam/printerMakesBrrr.lua b/src/brulijam/printerMakesBrrr.lua new file mode 100644 index 0000000..3be7765 --- /dev/null +++ b/src/brulijam/printerMakesBrrr.lua @@ -0,0 +1,127 @@ +-- 3D Drucker using https://minecraftshapes.com/ +------------------------------------------------- + + +basic = require("lib.basic") + +local function createMatrix(filePath, dim) + --create empty matrix + matrix = {} + for i = 1, dim do + matrix[i] = {} + for j = 1, dim do + matrix[i][j] = 0 + end + end + + --read shape svg + local lines = {} + for line in io.lines(filePath) do + lines[#lines + 1] = line + end + + --write 1 to each square that is set in the file + 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) / 18 + y = tonumber(yStr) / 18 + + print(x .. " " .. y) + matrix[x][y] = 1 + end + end + + return matrix +end + +local function printLayer(matrix, withChest) + for i=1, #matrix do + for j=1, #matrix[i] do + --print(i .. "," .. j .. ": " .. matrix[i][j]) + --sleep(1) + turtle.forward() + if matrix[i][j] == 1 then + turtle.placeDown() + end + end + for j=1, #matrix[i] do + turtle.back() + end + turtle.turnRight() + turtle.forward() + turtle.turnLeft() + end +end + +local function countBlocks(matrix) + local counter = 0 + for i=1, #matrix do + for j=1, #matrix[i] do + if matrix[i][j] == 1 then + counter = counter + 1 + end + end + end + return counter +end + +local function confirmationDialog(input) + if input == "y" or input == "yes" then + return true + elseif input == "n" or input == "no" then + return false + else + print("confirmationDialogError") + return "Error" +end + +local function itemInInventory() + for i=1, 16 do + turtle.select(i) + itemCount = turtle.getItemCount() + if itemCount > 0 then + return true + else + return false + end + end +end + +function main() + print("Print with Chest? [yn]") + local withChest = confirmationDialog(read()) + + print("Filepath? (/brulijam/files/shape.svg)") + local filePath = read() + + print("Dimension of the shape?") + local dim = read() + + matrix = createMatrix(filePath, dim) + + blockCounter = countBlocks(matrix) + + print("One Layer would need " .. blockCounter .. " Blocks.") + print(Continue? [yn]) + + + + + + local startPrinting = confirmationDialog(read()) + + if startPrinting then + printLayer(matrix, withChest) + end +end \ No newline at end of file diff --git a/src/brulijam/sync.lua b/src/brulijam/sync.lua index fe83472..a360e1f 100644 --- a/src/brulijam/sync.lua +++ b/src/brulijam/sync.lua @@ -22,9 +22,7 @@ local copyList = { [14] = "/brulijam/log-receiver.lua", [15] = "/startup.lua", [16] = "/brulijam/shapebuilder.lua", - [17] = "/brulijam/shape0.svg", - [18] = "/brulijam/shape1.svg", - [19] = "/brulijam/shape2.svg", + [17] = "/brulijam/files/shape-hex-64-20.svg", }