Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- write
- -- Builds the letters from the input text
- -- Written by HarvDad, June 2014
- version = "write: Rev 0.1"
- instructions = "Place stack(s) of material starting in first slot."
- usage = "write <text>"
- args = {...}
- nArgs = #args
- text = ""
- letters = {
- {"A", "====== ", " = =", " = =", " = =", "====== "},
- {"B", "=======", "= = =", "= = =", "= =", " == == "},
- {"C", " ===== ", "= =", "= =", "= =", " = = "},
- {"D", "=======", "= =", "= =", "= =", " ===== "},
- {"E", "=======", "= = =", "= = =", "= = =", "= ="},
- {"F", "=======", " = =", " = =", " = =", " ="},
- {"G", " ===== ", "= =", "= = =", "= = =", " === ="},
- {"H", "=======", " = ", " = ", " = ", "======="},
- {"I", " ", "= =", "=======", "= =", " "},
- {"J", " == ", "= ", "= ", "= ", " ======"},
- {"K", "=======", " = ", " = = ", " = = ", "= ="},
- {"L", "=======", "= ", "= ", "= ", "= "},
- {"M", "=======", " = ", " = ", " = ", "======="},
- {"N", "=======", " = ", " = ", " = ", "======="},
- {"O", " ===== ", "= =", "= =", "= =", " ===== "},
- {"P", "=======", " = =", " = =", " = =", " == "},
- {"Q", " ===== ", "= =", "= = =", "== =", "====== "},
- {"R", "=======", " = =", " == =", " = = =", "= == "},
- {"S", "= == ", "= = =", "= = =", "= = =", " == ="},
- {"T", " =", " =", "=======", " =", " ="},
- {"U", " ======", "= ", "= ", "= ", " ======"},
- {"V", " =====", " = ", "= ", " = ", " ====="},
- {"W", "=======", " = ", " == ", " = ", "======="},
- {"X", "== ==", " = = ", " = ", " = = ", "== =="},
- {"Y", " ===", " = ", "=== ", " = ", " ==="},
- {"Z", "== =", "= = =", "= = =", "= = =", "= =="},
- {"?", " = ", " =", "= == =", " = =", " == "},
- {"!", " ", " ", "= =====", " ", " "},
- {" ", " ", " ", " ", " ", " "},
- }
- materialSlot = 1
- x = 0
- y = 0
- z = 0
- face = 0
- -- The following 'face' directions are relative to the starting position of the turtle in this program
- north = 0
- west = 1
- south = 2
- east = 3
- goForward = 0
- goBackward = 1
- direction = goForward
- currentSlot = 1
- function setFace(f)
- if f == 0 then
- if face == 0 then return end
- if face == 1 then right() return end
- if face == 2 then right() right() return end
- if face == 3 then left() return end
- end
- if f == 1 then
- if face == 0 then left() return end
- if face == 1 then return end
- if face == 2 then right() return end
- if face == 3 then right() right() return end
- end
- if f == 2 then
- if face == 0 then left() left() return end
- if face == 1 then left() return end
- if face == 2 then return end
- if face == 3 then right() return end
- end
- if f == 3 then
- if face == 0 then right() return end
- if face == 1 then left() left() return end
- if face == 2 then left() return end
- if face == 3 then return end
- end
- end
- function left()
- if face == 0 then face = 1 turtle.turnLeft() return end
- if face == 1 then face = 2 turtle.turnLeft() return end
- if face == 2 then face = 3 turtle.turnLeft() return end
- if face == 3 then face = 0 turtle.turnLeft() return end
- print("function left\(\): Bad face value: ", face)
- end
- function right()
- if face == 0 then face = 3 turtle.turnRight() return end
- if face == 1 then face = 0 turtle.turnRight() return end
- if face == 2 then face = 1 turtle.turnRight() return end
- if face == 3 then face = 2 turtle.turnRight() return end
- print("function right\(\): Bad face value: ", face)
- end
- function up()
- while turtle.detectUp() do -- This loop added in case of falling sand or whatever
- turtle.digUp()
- end
- turtle.up()
- y = y+1
- end
- function rise(nBlocks)
- local i
- for i=1,nBlocks do
- up()
- end
- end
- function down()
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.down()
- y = y-1
- end
- function moveForward(nBlocks)
- for i = 1, nBlocks do
- turtle.forward()
- if face == north then
- z = z + 1
- elseif face == south then
- z = z - 1
- elseif face == east then
- x = x + 1
- elseif face == west then
- x = x - 1
- end
- end
- end
- function moveBackward(nBlocks)
- for i = 1, nBlocks do
- turtle.back()
- if face == north then
- z = z - 1
- elseif face == south then
- z = z + 1
- elseif face == east then
- x = x - 1
- elseif face == west then
- x = x + 1
- end
- end
- end
- function home(targetY)
- -- print("home:face ", face, ", x = ", x, ", z = ", z)
- if x < 0 then
- setFace(east)
- while x < 0 do
- moveForward(1)
- end
- else
- if x > 0 then
- setFace(west)
- while x > 0 do
- moveForward(1)
- end
- end
- end
- if z < 0 then
- setFace(north)
- while z < 0 do
- moveForward(1)
- end
- else
- if z > 0 then
- setFace(south)
- while z > 0 do
- moveForward(1)
- end
- end
- end
- if y > 0 then
- while y > 0 do
- down()
- end
- end
- setFace(0)
- end
- function ensureMaterial()
- if turtle.getItemCount(materialSlot) < 3 then
- organizeMaterial()
- end
- if turtle.getItemCount(materialSlot) < 3 then
- print("No more material")
- return false
- end
- return true
- end
- function organizeMaterial()
- local i
- materialCount = turtle.getItemCount(materialSlot)
- if materialCount < 3 then
- -- print("Attempting to refill slot ", materialSlot)
- for i=2,16 do
- turtle.select(i)
- if turtle.compareTo(materialSlot) then
- turtle.transferTo(materialSlot)
- end
- end
- end
- turtle.select(materialSlot)
- end
- function getLetter(letter)
- letter = string.upper(letter)
- for i=1,#letters do
- if letters[i][1] == letter then
- return letters[i]
- end
- end
- print("Cannot find entry for \'", letter, "\'")
- return nil
- end
- function hitTheDeck()
- --print("hitTheDeck: y = ", y)
- while y > 0 do
- down()
- -- print(" Down")
- end
- -- print(" y ends at ", y)
- goingUp = true
- end
- goingUp = true
- function buildLetter(letter)
- letterData = getLetter(letter)
- turtle.select(1)
- if letter == " " then
- right()
- moveForward(7)
- left()
- return
- end
- --[[
- if letterData ~= nil then
- for i=1,#letterData do
- print(" ", letterData[i])
- end
- end
- --]]
- if letterData == nil then
- print("Cannot build \'", letter, "\'")
- return
- end
- for i=2,#letterData do
- column = letterData[i]
- height = string.len(column)
- if goingUp then
- for j=1,height do
- char = string.sub(column, j, j)
- if char ~= " " then
- ensureMaterial()
- turtle.select(materialSlot)
- turtle.place()
- end
- if j < height then
- up()
- end
- end
- else
- for j=height,1,-1 do
- char = string.sub(column, j, j)
- if char ~= " " then
- ensureMaterial()
- turtle.select(materialSlot)
- turtle.place()
- end
- if j > 1 then
- down()
- end
- end
- end
- if goingUp then
- goingUp = false
- else
- goingUp = true
- end
- right()
- moveForward(1)
- left()
- end
- end
- if nArgs == 0 then
- print(version)
- print(instructions)
- print(usage)
- return
- end
- text = ""
- for i=1,nArgs do
- text = text .. " " .. args[i]
- end
- text = string.sub(text, 2)
- for i=1,string.len(text) do
- buildLetter(string.sub(text,i,i))
- right()
- moveForward(1)
- -- hitTheDeck()
- moveForward(1)
- left()
- end
- home(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement