Advertisement
Guest User

Mimage

a guest
Apr 24th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. function draw(startX,startY,image,term)
  2.     local Colors = {
  3.         ["0"] = 1,
  4.         ["1"] = 2,
  5.         ["2"] = 4,
  6.         ["3"] = 8,
  7.         ["4"] = 16,
  8.         ["5"] = 32,
  9.         ["6"] = 64,
  10.         ["7"] = 128,
  11.         ["8"] = 256,
  12.         ["9"] = 512,
  13.         ["a"] = 1024,
  14.         ["b"] = 2048,
  15.         ["c"] = 4096,
  16.         ["d"] = 8192,
  17.         ["e"] = 16384,
  18.         ["f"] = 32768
  19.     }
  20.     local Pixels = {}
  21.  
  22.     local function convert(mode,color)
  23.         if mode == "from cc" then
  24.             for key,value in pairs(Colors) do
  25.                 if color == value then
  26.                     return key
  27.                 end
  28.             end
  29.         else
  30.             if color == "#" then
  31.                 return "0"
  32.             else
  33.                 return Colors[color]
  34.             end
  35.         end
  36.     end
  37.  
  38.     local function load(path)
  39.         local file = fs.open(path,"r")
  40.         local lineCounter = 1
  41.         while true do
  42.             local line = file.readLine()
  43.             Pixels[lineCounter]={}
  44.             if line ~= nil then
  45.                 for i=1,#line,3 do
  46.                     Pixels[lineCounter][(i+2)/3]={}
  47.                     Pixels[lineCounter][(i+2)/3]["symbol"] = string.sub(line,i,i)
  48.                     Pixels[lineCounter][(i+2)/3]["textColor"] = convert("to cc",string.sub(line,i+1,i+1))
  49.                     Pixels[lineCounter][(i+2)/3]["backColor"] = convert("to cc",string.sub(line,i+2,i+2))
  50.                 end
  51.                 lineCounter = lineCounter + 1
  52.             else
  53.                 break
  54.             end
  55.         end
  56.         file.close()
  57.     end
  58.  
  59.     load(image)
  60.  
  61.     for y=1,#Pixels do
  62.         for x=1,#Pixels[y] do
  63.             if Pixels[y][x]["symbol"] ~= "#" then
  64.                 term.setTextColor(Pixels[y][x]["textColor"])
  65.                 term.setBackgroundColor(Pixels[y][x]["backColor"])
  66.                 term.setCursorPos(startX+x-1,startY+y-1)
  67.                 term.write(Pixels[y][x]["symbol"])
  68.             end
  69.         end
  70.     end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement