Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. local image = false
  2.  
  3. function ParseNFT(lines)
  4. local pixels = {}
  5. for y, line in ipairs(lines) do
  6. local bgNext, fgNext = false, false
  7. local currBG, currFG = nil,nil
  8. local writePosition = 1
  9. for x = 1, #line do
  10. if not pixels[writePosition] then
  11. pixels[writePosition] = {}
  12. end
  13.  
  14. local nextChar = string.sub(line, x, x)
  15. if nextChar:byte() == 30 then
  16. bgNext = true
  17. elseif nextChar:byte() == 31 then
  18. fgNext = true
  19. elseif bgNext then
  20. currBG = getColourOf(nextChar)
  21. if currBG == nil then
  22. currBG = colours.transparent
  23. end
  24. bgNext = false
  25. elseif fgNext then
  26. currFG = getColourOf(nextChar)
  27. fgNext = false
  28. else
  29. if nextChar ~= " " and currFG == nil then
  30. currFG = colours.white
  31. end
  32. pixels[writePosition][y] = {BackgroundColour = currBG, TextColour = currFG, Character = nextChar}
  33. writePosition = writePosition + 1
  34. end
  35. end
  36. end
  37. return pixels
  38. end
  39.  
  40. function loadImage(imgfile)
  41.  
  42. local file = fs.open(imgfile,"r")
  43. local _layers = textutils.unserialise(file.readAll())
  44. file.close()
  45.  
  46. local layers = {}
  47.  
  48. for i, l in ipairs(_layers) do
  49.  
  50. local daPixels = ParseNFT(l.Pixels)
  51. print(daPixels[1][1].BackgroundColour)
  52.  
  53. end
  54.  
  55. end
  56.  
  57.  
  58.  
  59. loadImage("tests/kate")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement