Advertisement
MeXaN1cK

PIXdraw

May 20th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. local shl = require("shell")
  2. local com = require("computer")
  3. local cmp = require("component")
  4. local uni = require("unicode")
  5. local trm = require("term")
  6. local gpu = cmp.gpu
  7. local args = shl.parse(...)
  8. local sym = {"▄", "▀", "█", " "}
  9. local b32 = require("bit32")
  10. local args = shl.parse(...)
  11.  
  12. local function BtoI(str)
  13.   local integer = 0
  14.   for i=1, string.len(str) do
  15.     integer = b32.lshift(integer, 8)  + string.byte(str, i)
  16.   end
  17.   return integer
  18. end
  19.  
  20. local function BtoS(str, len)
  21.   local out = ""
  22.   local TEMP
  23.   for i=1, #str do
  24.     TEMP = str:byte(i)
  25.     for j=6, 0, -2 do
  26.       out = out..sym[math.floor(TEMP / (2 ^ j)) + 1]
  27.       TEMP = TEMP % (2 ^ j)
  28.     end
  29.   end  
  30.   return out
  31. end
  32.  
  33. local function r(n)
  34.   IND = IND + n
  35.   return string.sub(STR, IND - n, IND - 1)
  36. end
  37.  
  38. local function getFile(str)
  39.   file = io.open(str, "rb")
  40.   STR = file:read("*a")
  41.   file:close()
  42.   IND = 1
  43.  
  44.   --[[ FONE ]]
  45.  
  46.   fone = {BtoI(r(1)), BtoI(r(1)), BtoI(r(3)), BtoI(r(3))}  
  47.  
  48.   --[[ CLR ]]
  49.  
  50.   clr = {}
  51.  
  52.   local lenStr = BtoI(r(2))
  53.   local STRING = BtoS(r(math.ceil(lenStr / 4)), lenStr)
  54.  
  55.   local function getStr(n) local temp = uni.sub(STRING, 1, n)
  56.     STRING = uni.sub(STRING, n+1)
  57.   return temp
  58.   end
  59.  
  60.   local lenCLR = BtoI(r(2))
  61.   for i=1, lenCLR do
  62.     local F = BtoI(r(3))
  63.     local lenCLR_F = BtoI(r(2))
  64.     clr[F] = {}
  65.     for j=1, lenCLR_F do
  66.       local B = BtoI(r(3))
  67.       local lenCLR_F_B = BtoI(r(2))
  68.       clr[F][B] = {}
  69.       for k=1, lenCLR_F_B do
  70.         local ind = #clr[F][B] + 1
  71.         local x = BtoI(r(1))
  72.         local y = BtoI(r(1))
  73.         local lstr = BtoI(r(1))
  74.         clr[F][B][ind] = {x, y, getStr(lstr)}
  75.       end
  76.     end
  77.   end
  78.  
  79.  
  80.  
  81. end
  82.  
  83. local function drawPIX(path)
  84.   timeFile = com.uptime()
  85.   getFile(path)
  86.   timeFile = com.uptime() - timeFile
  87.   gpu.setResolution(fone[1], fone[2])
  88.   timeDraw = com.uptime()
  89.   gpu.setForeground(fone[3])
  90.   gpu.setBackground(fone[4])
  91.   gpu.fill(1,1,fone[1],fone[2], "▄")
  92.   for i, _ in pairs(clr) do
  93.     gpu.setForeground(i)
  94.     for j, _ in pairs(clr[i]) do
  95.       gpu.setBackground(j)
  96.       for k, _ in pairs(clr[i][j]) do
  97.         gpu.set(clr[i][j][k][1], clr[i][j][k][2], clr[i][j][k][3])
  98.       end
  99.     end
  100.   end
  101.   timeDraw = com.uptime() - timeDraw
  102.   gpu.setForeground(0xffffff)
  103.   gpu.setBackground(0x000000)
  104. end
  105.  
  106. drawPIX(args[1])
  107. if args[2] ~= nil then
  108.   trm.setCursor(1, 1)
  109.   print("Время чтения файла: "..string.sub(tostring(timeFile), 1, 5))
  110.   print("Время отрисовки:    "..string.sub(tostring(timeDraw), 1, 5))
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement