Advertisement
kumesana

draw

Sep 20th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. local args = {...}
  2.  
  3. local downHeight = 80
  4. local screen = peripheral.wrap(args[1])
  5. screen.setTextScale(0.5)
  6. screen.width, screen.height = screen.getSize()
  7. screen.width = screen.width-1
  8. screen.height = screen.height-1
  9.  
  10. local zc = string.byte("0")
  11. local ac = string.byte("a")
  12.  
  13. local cindex = {}
  14. cindex[zc] = colors.white
  15. cindex[zc+1] = colors.orange
  16. cindex[zc+2] = colors.magenta
  17. cindex[zc+3] = colors.lightBlue
  18. cindex[zc+4] = colors.yellow
  19. cindex[zc+5] = colors.lime
  20. cindex[zc+6] = colors.pink
  21. cindex[zc+7] = colors.gray
  22. cindex[zc+8] = colors.lightGray
  23. cindex[zc+9] = colors.cyan
  24. cindex[ac] = colors.purple
  25. cindex[ac+1] = colors.blue
  26. cindex[ac+2] = colors.brown
  27. cindex[ac+3] = colors.green
  28. cindex[ac+4] = colors.red
  29. cindex[ac+5] = colors.black
  30.  
  31. local file = fs.open("/disk/images/"..args[2], "r")
  32. local image = {}
  33. image.width = tonumber(file.readLine())
  34. image.height = tonumber(file.readLine())
  35. image.data = file.readLine()
  36. file.close()
  37.  
  38. function draw(sx, sy, iy)
  39.   for j = 0, image.height-iy-1 do
  40.     for i = 0, image.width-1 do
  41.       local pixel = string.byte(image.data, (j+iy)*image.width+i+1)
  42.       local color = cindex[pixel]
  43.       paintutils.drawPixel(i+sx+2, j+sy+2, color)
  44.     end
  45.   end
  46. end
  47.  
  48. local pane = #args >= 3 and args[3] or "down"
  49.  
  50. local sx = (screen.width-1-image.width)/2
  51. local sy = nil
  52. local iy = nil
  53.  
  54. if pane == "down" then
  55.   sy = 0
  56.   iy = image.height - downHeight
  57. else
  58.   sy = screen.height - image.height + downHeight
  59.   iy = 0
  60. end
  61.  
  62. term.redirect(screen)
  63. term.setBackgroundColor(colors.black)
  64. term.clear()
  65. term.setCursorPos(1, 1)
  66.  
  67. draw(sx, sy, iy)
  68.  
  69. term.restore()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement