Alyssa

Video player

Jun 1st, 2015
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.41 KB | None | 0 0
  1. args = {...}
  2. vid = args[1]
  3. doUncompress = args[2]
  4. if doUncompress == "true" or doUncompress == "uncompress" or doUncrompess == "uncompressed" or doUncrompress == "-u" then
  5.     doUncompress = true
  6. else
  7.     doUncompress = true
  8. end
  9. bsl = "\\"
  10.  
  11. dpc = "%%"
  12. pce = "%^"
  13. pmc = "%$"
  14. pop = "%("
  15. pcp = "%)"
  16. ppd = "%."
  17. psb = "%["
  18. pcb = "%]"
  19. pst = "%*"
  20. pad = "%+"
  21. psu = "%-"
  22. pqm = "%?"
  23.  
  24. hex = {{"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"},{pcp,"!","@","#",pmc,dpc,pce,"&",pst,pop,"A","B","C","D","E","F"},{"q","w","r","t","y","u","i","o","p","s","g","h","j","k","l","z"},{"x","v","n","m","~","`",",","<",ppd,">","/",pqm,";",":","'",'"'},{pcb,"{",psb,"}","|",bsl,psu,"_","=",pad,"Q","W","R","T","Y","U"}}
  25. function unCompress(toUC)
  26.     if doUncompress then
  27.         for a = #hex, 2,-1 do
  28.             for b = 1, #hex[1] do
  29.             toUC = string.gsub(toUC, hex[a][b],hex[a-1][b]..hex[a-1][b])
  30.             end
  31.         end
  32.     end
  33.     return toUC
  34. end
  35. function openVideo(file)
  36.     print("Giving /videos/"..vid.."/"..file)
  37.     return fs.open("/videos/"..vid.."/"..file,"r")
  38. end
  39. function sep(str)
  40.     t = {}
  41.     while #str >= 1 do
  42.         pos = str:find("\n")
  43.         if pos then
  44.             t[#t+1] = str:sub(1,pos-1)
  45.             str = str:sub(pos+1,#str)
  46.         else
  47.             t[#t+1] = str:sub(1,#str)
  48.             str = ""
  49.         end
  50.     end
  51.     return t
  52. end
  53. function readLine()
  54.     linePos = linePos+1
  55.     if fileTable[linePos-1] then
  56.         return fileTable[linePos-1]
  57.     else
  58.         return nil
  59.     end
  60. end
  61. function openRead(file)
  62.     f = openVideo(file)
  63.     fd = f.readAll()
  64.     fd = unCompress(fd)
  65.     fileTable = sep(fd)
  66.     f.close()
  67.     linePos = 1
  68. end
  69. rf = openVideo("resolution")--openVideo("resolution")
  70. resX = tonumber(rf.readLine())
  71. resY = tonumber(rf.readLine())
  72. print("Videos is "..tostring(resX).."x"..tostring(resY))
  73. tf = openVideo("text")
  74. cont = true
  75. countera = 1
  76. counetrb = 1
  77. txt = {}
  78. function decode(doNorm,f)
  79.     rTable = {}
  80.     countera = 1
  81.     counterb = 1
  82.     tot = 1
  83.     cont = true
  84.     while cont do
  85.         if not doNorm then
  86.             cont = readLine()
  87.         else
  88.             cont = f.readLine()
  89.         end
  90.         if not rTable[countera] then
  91.             rTable[countera] = {}
  92.         end
  93.         if cont then
  94.             rTable[countera][counterb] = cont
  95.         end
  96.         counterb = counterb+1
  97.         if counterb > resY then
  98.             countera = countera+1
  99.             counterb = 1
  100.             tot = tot+1
  101.         end
  102.     end
  103.     if doNorm then
  104.         f.close()
  105.     end
  106.     return rTable, tot
  107. end
  108. txt, totalFrames = decode(true,tf)
  109. --fCol = openVideo("color")
  110. openRead("color")
  111. col = decode(fCol)
  112. openRead("bg")
  113. --fBG = openVideo("bg")
  114. bg = decode(fBG)
  115. cur = true
  116. frame = 1
  117. cFrame = {}
  118. start = os.time()
  119. sleepMode = "yield"
  120. while cur do
  121.     if sleepMode == "yield" then
  122.         bst = os.time()
  123.     else
  124.         sleep(0.05)
  125.     end
  126.     term.setCursorPos(1,1)
  127.     cFrame = {txt[frame],col[frame],bg[frame]}
  128.     cur = nil
  129.     if txt[frame] and txt[frame][1] then
  130.         cur = txt[frame][1]
  131.     end
  132.     if cur then
  133.         for a = 1, #cFrame[1] do
  134.             --print(cFrame[1][a])
  135.             --print(cFrame[2][a])
  136.             --print(cFrame[3][a])
  137.             if cFrame[1][a] and cFrame[2][a] and cFrame[3][a] then
  138.                 term.blit(cFrame[1][a],cFrame[2][a],cFrame[3][a])
  139.             end
  140.             write("\n")
  141.         end
  142.     end
  143.     frame = frame+1
  144.     if sleepMode == "yield" then
  145.         wait = true
  146.         while wait do
  147.             os.queueEvent("YIELD")
  148.             os.pullEvent("YIELD")
  149.             bet = os.time()
  150.             if bet ~= bst then
  151.                 wait = false
  152.             end
  153.         end
  154.     end
  155. end
  156. endTime = os.time()
  157. taken = endTime - start
  158. taken = taken*50
  159. print(tostring(totalFrames).." frames took "..tostring(taken).." seconds")
  160. print("That's "..tostring(totalFrames/taken).." FPS")
Advertisement
Add Comment
Please, Sign In to add comment