Advertisement
Redxone

ComputerCraft - AsciiUtils

Feb 14th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. --]] Ascii Utils, By Redxone [[--
  2.  
  3. -- ]] Drawing Utils
  4. function loadAscii(file)
  5.     if(fs.exists(file))then
  6.         f = fs.open(file,"r")
  7.         canv = textutils.unserialize(f.readAll())
  8.         f.close()
  9.         if(type(canv) == "table")then
  10.             return canv
  11.         else
  12.             error("Ascii -> LoadAscii[ERROR], Invalid file format. (Not an Ascii)")
  13.         end
  14.     else
  15.         error("Ascii -> LoadAscii[ERROR], No such file.")
  16.     end
  17. end
  18.  
  19. function drawAscii(art,x,y)
  20.     local w,h = term.getSize()
  21.     if(type(art) == "table")then
  22.         for yy = 0, h-1 do
  23.             for xx = 0, w-1 do
  24.                 if(art[yy][xx].char ~= "\127")then
  25.                     term.setCursorPos(xx+x,yy+y)
  26.                     term.setTextColor(tonumber(art[yy][xx].color))
  27.                     write(tostring(art[yy][xx].char))
  28.                 end
  29.             end
  30.         end
  31.  
  32.         term.setTextColor(colors.white)
  33.         term.setBackgroundColor(colors.black)
  34.  
  35.     else
  36.         error("Ascii -> drawAscii[ERROR], Invalid art format. (Not an Ascii)")
  37.     end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement