columna1

nfp Viewer

Jun 19th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. width = 0
  2. height = 0
  3. args = {...}
  4. file = args[1]
  5. w,h = term.getSize()
  6. f = fs.open(file,"r")
  7. --data = f.readAll()
  8. f.close()
  9. fi = fs.open(file,"r")
  10. lines = 0
  11. line = fi.readLine()
  12. width = #line
  13. while line do
  14.   line = fi.readLine()
  15.   lines = lines + 1
  16. end
  17. fi.close()
  18. height = lines
  19. --print(width)
  20. --print(height)
  21. mx = 0
  22. my = 0
  23. image = {}
  24.  
  25. color = {
  26. ["0"] = 1,
  27. ["1"] = 2,
  28. ["2"] = 4,
  29. ["3"] = 8,
  30. ["4"] = 16,
  31. ["5"] = 32,
  32. ["6"] = 64,
  33. ["7"] = 128,
  34. ["8"] = 256,
  35. ["9"] = 512,
  36. ["a"] = 1024,
  37. ["b"] = 2048,
  38. ["c"] = 4096,
  39. ["d"] = 8192,
  40. ["e"] = 16384,
  41. ["f"] = 32768,
  42. [" "] = 32768
  43. }
  44. print(width)
  45. print(height)
  46. sleep(1)
  47. fil = fs.open(file,"r")
  48. for y = 1,height do
  49.   line = fil.readLine()
  50.   image[y] = {}
  51.   os.queueEvent("randomEvent")
  52.   os.pullEvent()
  53.   print("did event "..y)
  54.   for x = 1,width do
  55.     --os.queueEvent("randomEvent")
  56.     --os.pullEvent()
  57.     if line then
  58.       line = line..""
  59.       image[y][x] = color[line:sub(x,x)]
  60.     else
  61.       print("uh oh no value at x: "..x.." y: "..y)
  62.     end
  63.   end
  64. end
  65. fil.close()
  66. function display()--xx,yy)
  67.     for xc = 1,w do
  68.       for yc = 1,h do
  69.         if xc <= width and yc <= height then
  70.           --print(image[xc+mx][yc+my])
  71.           num = image[yc+my][xc+mx]
  72.           --write(num)
  73.           if num then term.setBackgroundColor(image[yc+my][xc+mx]) else term.setBackgroundColor(colors.black) end--[yc+my]) end
  74.           term.setCursorPos(xc,yc)
  75.           write(" ")
  76.         end
  77.       end
  78.     end
  79. end
  80. term.clear()
  81. display(0,0)
  82. run = true
  83.  
  84. function go()
  85.   term.setBackgroundColor(colors.black)
  86.   term.clear()
  87.   display(mx,my)
  88. end
  89.  
  90. while run do
  91.   event,key = os.pullEvent("key")
  92.   if key == 200 and my >= 20 then
  93.     my = my - 20
  94.     go()
  95.   elseif key == 208 and my <= height - h - 20 then
  96.     my = my + 20
  97.     go()
  98.   elseif key == 203 and mx >= 20 then
  99.     mx = mx - 20
  100.     go()
  101.   elseif key == 205 and mx <= width - w - 20 then
  102.     mx = mx + 20
  103.     go()
  104.   elseif key == 28 then
  105.      run = false
  106.   end
  107. end
Advertisement
Add Comment
Please, Sign In to add comment