Posted 12 November 2012 - 10:21 AM
--drawing program
--use the arrows to navigate within layers
--use + or - to move up or down a layer (0-9)
--press any number to change the number written, this will be the inventory slot used. So if you draw a shape using 3s then the shape will be built using inventory block 3
--0 is used as the erase tool, as there is no 0 inventory slot
--press Rshift to 'fly' aka move without writing
--press space to clear the screen DOES NOT CLEAR THE MEMORY
--press enter to restore the drawing from memory
--press t to name the file
--press s to save the file (default name is 'savedraw')
--press l to load the file (you will have to press t and then type the file name to recall anything other than 'savedraw')
--press b to have the turtle build your drawing
layer = 1
fly = 1
x = 2
y = 2
savename = "savedraw"
buildframex =10
buildframey =10
buildframez =10
shape = {}
for a = 0, (buildframez*buildframex*buildframey) do
shape[a] = " "
end
current = 1
--!!!!!!! item counter inventory = {} to be built
local function back(a)
for back = 1, a do
turtle.back()
end
end
local function forward(:unsure:/>/>
for forward = 1, b do
turtle.forward()
end
end
local function save()
h = fs.open(savename,"w")
--h.write("{")
sendshape = textutils.serialize(shape)
h.write(sendshape)
--h.write(" }")
h.close()
end
local function load()
h = fs.open(savename,"r")
j = h.readAll()
shape = textutils.unserialize(j)
end
local function build()
for unpackLayer = 0, 9 do
for unpackX = 0, 9 do
for unpackY = 0, 9 do
tempB1 = unpackLayer*100
tempB2 = unpackX*10
tempB3 = unpackY
tempB = tempB1+tempB2+tempB3
if shape[tempB] ~= " " then
turtle.select(shape[tempB])
turtle.placeDown()
end
turtle.forward()
end
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
back(10)
end
turtle.turnRight()
back(10)
turtle.up()
turtle.turnLeft()
end
end
local function arrowmove()
term.setCursorPos(x + 2, y + 1)
if fly == 1 then
term.write(current)
end
reading = {term.getCursorPos()}
term.setCursorPos(5,12)
term.write("You are at x="..(reading[1]-2).." y="..(reading[2]).." ")
term.setCursorPos(x,y)
if fly == 1 then
temp1 = layer*100
temp2 = x*10
temp3 = y
temp = temp1+temp2+temp3
shape[temp] = current
end
end
local function draw()
term.clear()
while true do
local evt, key = os.pullEvent("key")
if key == 200 then
--up
y = (y - 1)%10
arrowmove()
elseif key == 203 then
--left
x = (x - 1)%10
arrowmove()
elseif key == 205 then
--right
x = (x + 1)%10
arrowmove()
elseif key == 208 then
--down
y = (y + 1)%10
arrowmove()
elseif key == 57 then
--space
term.clear()
elseif key == 28 then
--enter
term.clear()
for unpack1 = 0, 9 do
for unpack2 = 0, 9 do
term.setCursorPos(unpack1+2, unpack2+1)
tempE1 = layer*100
tempE2 = unpack1*10
tempE3 = unpack2
tempE = tempE1+tempE2+tempE3
term.write(shape[tempE])
end
end
elseif key == 54 then
--shift
fly = (fly + 1)%2
term.setCursorPos(5,11)
term.write("Flymode = "..fly.." ")
elseif key == 2 then
--1
current = 1
term.setCursorPos(1,11)
term.write("You have changed block to Inventory1")
elseif key == 3 then
--2
current = 2
term.setCursorPos(1,11)
term.write("You have changed block to Inventory2")
elseif key == 4 then
--3
current = 3
term.setCursorPos(1,11)
term.write("You have changed block to Inventory3")
elseif key == 5 then
--4
current = 4
term.setCursorPos(1,11)
term.write("You have changed block to Inventory4")
elseif key == 6 then
--5
current = 5
term.setCursorPos(1,11)
term.write("You have changed block to Inventory5")
elseif key == 7 then
--6
current = 6
term.setCursorPos(1,11)
term.write("You have changed block to Inventory6")
elseif key == 8 then
--7
current = 7
term.setCursorPos(1,11)
term.write("You have changed block to Inventory7")
elseif key == 9 then
--8
current = 8
term.setCursorPos(1,11)
term.write("You have changed block to Inventory8")
elseif key == 10 then
--9
current = 9
term.setCursorPos(1,11)
term.write("You have changed block to Inventory9")
elseif key == 11 then
--0
current = " "
term.setCursorPos(1,11)
term.write("You have changed block to Erase ")
elseif key == 48 then
--b
build()
elseif key == 31 then
--s
save()
elseif key == 20 then
--t
term.setCursorPos(1,12)
term.clearLine()
term.write("Name file...")
savename = io.read()
term.setCursorPos(1,11)
term.clearLine()
elseif key == 38 then
--l
load()
elseif key == 13 then
-- +
term.clear()
layer = layer + 1
if layer > 9 then
layer = 9
end
term.setCursorPos(5,12)
term.write("You have moved to layer "..layer)
elseif key == 12 then
-- -
term.clear()
layer = layer - 1
if layer < 0 then
layer = 0
end
term.setCursorPos(5,12)
term.write("You have moved to layer "..layer)
end
end
end
draw()
Turtle program which allows you to draw anything you want within a 10x10x10 space and save and load your drawings at will. Turtles will also, of course, build your designs