Advertisement
incinirate

Print

Jun 12th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.12 KB | None | 0 0
  1. shell.run("clear")
  2. print("X,Y,and Z sizes:")
  3. write("X:");x=read()
  4. write("Y:");y=read()
  5. write("Z:");z=read()
  6.  
  7. help=true
  8.  
  9. x=tonumber(x)
  10. y=tonumber(y)
  11. z=tonumber(z)
  12.  
  13. layers={}
  14. layer=1
  15. for i=1,z do
  16.   layers[i]={}
  17.   for j=1,x do
  18.     layers[i][j]={}
  19.     for k=1,y do
  20.       layers[i][j][k]=" "
  21.     end
  22.   end
  23. end
  24.  
  25. function cnt()
  26.   local count=0
  27.   for i=1,z do
  28.     for j=1,x do
  29.       for k=1,y do
  30.         if layers[i][j][k]~=" " then
  31.           count=count+1
  32.         end
  33.       end
  34.     end
  35.   end
  36.   return count
  37. end
  38.  
  39. function draw()
  40.   shell.run("clear")
  41.   term.setTextColor(colors.gray)
  42.   term.setBackgroundColor(colors.black)
  43.   for i=1,y do
  44.     for j=1,x do
  45.       term.setCursorPos(j,i)
  46.       if layers[layer][j][i]==" " then
  47.         write("-")
  48.       else
  49.         term.setBackgroundColor(colors.red)
  50.         write(" ")
  51.         term.setBackgroundColor(colors.black)
  52.       end
  53.     end
  54.   end
  55.   term.setTextColor(colors.white)
  56.   scx,scy=term.getSize()
  57.   if help then
  58.     term.setCursorPos(1,scy-5)
  59.     print("Layer "..layer.."/"..z)
  60.     print(cnt().." Blocks Required")
  61.     print("Press ~ To Copy Previous Layer")
  62.     print("Press Tab To Clear This Layer")
  63.     print("Press Delete To Cancel Job")
  64.     write("Press Enter To Finish")
  65.   else
  66.     term.setCursorPos(1,scy-1)
  67.     print("Layer "..layer.."/"..z)
  68.     write(cnt().." Blocks Required")
  69.   end
  70.   term.setCursorPos(scx-10,scy)
  71.   if help then
  72.     term.setBackgroundColor(colors.lime)
  73.   else
  74.     term.setBackgroundColor(colors.red)
  75.   end
  76.   write("Toggle Help")
  77.   term.setBackgroundColor(colors.black)
  78. end
  79.  
  80. while true do
  81.   draw()
  82.   e,p1,p2,p3 = os.pullEvent()
  83.   if e=="key" then
  84.     key=p1
  85.     if key==28 then
  86.       break
  87.     elseif key==13 and layer<#layers then
  88.       layer=layer+1
  89.     elseif key==12 and layer>1 then
  90.       layer=layer-1
  91.     elseif key==41 and layer>1 then
  92.       for i=1,y do
  93.         for j=1,x do
  94.           layers[layer][j][i]=layers[layer-1][j][i]
  95.         end
  96.       end
  97.     elseif key==15 then
  98.       for i=1,y do
  99.         for j=1,x do
  100.           layers[layer][j][i]=" "
  101.         end
  102.       end
  103.     elseif key==211 then
  104.       shell.run("clear")
  105.       print("Thanks for using TurtlePrint")
  106.       error()
  107.     end
  108.   elseif e=="mouse_click" or e=="mouse_drag" then
  109.     mx=p2
  110.     my=p3
  111.     if mx<x+1 and my<y+1 then
  112.       if p1==1 then
  113.         layers[layer][mx][my]="|"
  114.       else
  115.         layers[layer][mx][my]=" "
  116.       end
  117.     elseif mx>scx-11 and my==scy then
  118.       help=not help
  119.     end
  120.   end
  121. end
  122. t=turtle
  123. slot=1
  124. function plc()
  125.   if t.getItemCount(slot) ==0 then
  126.     for i=1,16 do
  127.       if t.getItemCount(i)~=0 then
  128.         slot=i
  129.         t.select(i)
  130.         repeat sleep(0) until t.placeDown()
  131.         return
  132.       end
  133.     end
  134.     repeat
  135.       local chk=false
  136.       shell.run("clear")
  137.       print("Out of items, please imput more")
  138.       print("Press Enter When Done")
  139.       read()
  140.       for i=1,16 do
  141.         if t.getItemCount(i)~=0 then
  142.           chk=true
  143.           slot=i
  144.           t.select(i)
  145.         end
  146.       end
  147.     until  chk
  148.     print("Thanks!")
  149.   end
  150.   repeat sleep(0) until t.placeDown()
  151. end
  152. repeat sleep(0) until t.forward()
  153. bc=0
  154. bmc=cnt()
  155. for i=1,z do
  156.   shell.run("clear")
  157.   print("Layer "..i.." of "..z)
  158.   repeat sleep(0) until t.up()
  159.   for j=1,x do
  160.     for k=1,y do
  161.       if layers[i][j][y-k+1] ~= " " then
  162.         plc()
  163.         bc=bc+1
  164.         term.clearLine(2)
  165.         term.clearLine(3)
  166.         term.setCursorPos(1,2)
  167.         print(bc.." blocks placed out of "..bmc)
  168.         print("|"..string.rep("=",math.floor(bc/bmc*10))..string.rep(" ",10-(math.floor(bc/bmc*10))).."|")
  169.       end
  170.       if k~=y then repeat sleep(0) until t.forward() end
  171.     end
  172.     for k=1,y-1 do
  173.       repeat sleep(0) until t.back()
  174.     end
  175.     if j~=x then t.turnRight()
  176.     repeat sleep(0) until t.forward()
  177.     t.turnLeft() end
  178.   end
  179.   t.turnLeft()
  180.   for j=1,x-1 do
  181.     repeat sleep(0) until t.forward()
  182.   end
  183.   t.turnRight()
  184. end
  185. repeat sleep(0) until t.back()
  186. for i=1,z do
  187.   repeat sleep(0) until t.down()
  188. end
  189. shell.run("clear")
  190. print("Print Complete")
  191. print("Thanks for using TurtlePrint")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement