Bjornir90

Movie editor

Aug 5th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.91 KB | None | 0 0
  1. colors.white     1   0x1     0000000000000001
  2. colors.orange    2   0x2     0000000000000010
  3. colors.magenta   4   0x4     0000000000000100
  4. colors.lightBlue     8   0x8     0000000000001000
  5. colors.yellow    16  0x10    0000000000010000
  6. colors.lime  32  0x20    0000000000100000
  7. colors.pink  64  0x40    0000000001000000
  8. colors.gray  128     0x80    0000000010000000
  9. colors.lightGray     256     0x100   0000000100000000
  10. colors.cyan  512     0x200   0000001000000000
  11. colors.purple    1024    0x400   0000010000000000
  12. colors.blue  2048    0x800   0000100000000000
  13. colors.brown     4096    0x1000  0001000000000000
  14. colors.green     8192    0x2000  0010000000000000
  15. colors.red   16384   0x4000  0100000000000000
  16. colors.black
  17.  
  18. local Args = ...
  19.  
  20. local file = fs.open(Args, "r") or fs.open(Args..".rec", "r") or error("Cannot open the file "..Args", 0)
  21. local version = file.readLine()
  22. if version ~= "1.0" then
  23. term.clear()
  24. term.setTextColor(colors.red)
  25. term.setCursorPos(10, 5)
  26. print("[!] Warning : file version doesn't match editor version !\nTrying to do the job but if it doesn't work please check for update")
  27. term.setTextColor(colors.white)
  28. end
  29. local movie = textutils.unserialize(file.readLine())
  30. file.close()
  31. local currentFrame = 1
  32. local termX, termY = term.getSize()
  33. local exit = false
  34. local currentColor = colors.white
  35.  
  36.  
  37.  
  38. local function drawFrame(number)
  39. local frame = movie[number]
  40. for _, pixel in ipairs(frame) do
  41.  term.setCursorPos(pixel.x, pixel.y)
  42.  term.setTextColor(pixel.t)
  43.  term.setBackgroundColor(pixel.b)
  44.  term.write(pixel.c)
  45. end
  46. end
  47.  
  48. local function moveToFrame(number)
  49. currentFrame = number
  50. drawFrame(number)
  51. drawHUD()
  52. end
  53.  
  54.  
  55. local function drawHUD()
  56. paintutils.drawPixel(termX, 1, colors.lightBlue)
  57. paintutils.drawPixel(termX, 2, colors.blue)
  58. paintutils.drawPixel(termX, 3, colors.cyan)
  59. paintutils.drawPixel(termX-1, 1, colors.red)
  60. paintutils.drawPixel(termX-1, 2, colors.orange)
  61. paintutils.drawPixel(termX-1, 3, colors.purple)
  62. paintutils.drawPixel(termX-1, 4, colors.magenta)
  63. paintutils.drawPixel(termX-1, 5, colors.lime)
  64. paintutils.drawPixel(termX-1, 6, colors.green)
  65. paintutils.drawPixel(termX-1, 7, colors.pink)
  66. paintutils.drawPixel(termX, 4, colors.yellow)
  67. paintutils.drawPixel(termX, 5, colors.brown)
  68. paintutils.drawPixel(termX, 6, colors.white)
  69. paintutils.drawPixel(termX, 7, colors.black)
  70. paintutils.drawPixel(termX, 8, colors.lightGray)
  71. paintutils.drawPixel(termX-1, 8, colors.gray)
  72. term.setCursorPos(termX-4, termY)
  73. term.setColorBackground(colors.lightBlue)
  74. term.setTextColor(colors.blue)
  75. write("SAVE")
  76. term.setCursorPos(termX-9, termY)
  77. write(currentFrame)
  78. term.setColorBackground(colors.black)
  79. term.setTextColor(colors.white)
  80. end
  81.  
  82. local function saveMovie()
  83. local sMovie = textutils.serialize(movie)
  84. local file = fs.open(path, "w")
  85. file.write(version)
  86. file.write(sMovie)
  87. file.close()
  88. print("Successfully saved file")
  89. end
  90.  
  91. local function copyFrame(toCopy, number)
  92. for i = 1, number do
  93.  
  94. end
  95. d
  96.  
  97.  
  98.  
  99. while exit ~= true do
  100. drawFrame(currentFrame)
  101. drawHUD()
  102. local event, param, param1, param2 = os.pullEvent()
  103. if event == "key" then
  104.  if param == keys.left then
  105.   if currentFrame ~= 1 then
  106.    currentFrame = currentFrame - 1
  107.   else
  108.    currentFrame = #movie  --put to the last frame
  109.   end
  110.  elseif param == keys.right then
  111.   if currentFrame ~= #movie then
  112.    currentFrame = currentFrame + 1
  113.   else
  114.    currentFrame = 1  --put to the last frame
  115.   end
  116.  elseif param == keys.c then
  117.   paintutils.drawLine(15, 7, 18, 7, colors.lightGray)
  118.   term.setCursorPos(1, 7)
  119.   write("Number of copy :")
  120.   local copyNumber = tonumber(read())
  121.   copyFrame(currentFrame, copyNumber)
  122.  elseif param == keys.q then
  123.   break
  124.  end
  125. elseif event == "mouse_click" then
  126.  local x, y = param1, param2
  127.  if x = termX and y = 1 then
  128.   currentColor = colors.lightBlue
  129.  elseif x = termX and y = 2 then
  130.   currentColor = colors.blue
  131.  elseif x = termX and y = 3 then
  132.   currentColor = colors.cyan
  133.  elseif x = termX and y = 4 then
  134.   currentColor = colors.yellow
  135.  elseif x = termX and y = 5 then
  136.   currentColor = colors.brown
  137.  elseif x = termX and y = 6 then
  138.   currentColor = colors.white
  139.  elseif x = termX and y = 7 then
  140.   currentColor = colors.black
  141.  elseif x = termX and y = 8 then
  142.   currentColor = colors.lightGray
  143.  elseif x = termX-1 and y = 1 then
  144.   currentColor = colors.red
  145.  elseif x = termX-1 and y = 2 then
  146.   currentColor = colors.orange
  147.  elseif x = termX-1 and y = 3 then
  148.   currentColor = colors.purple
  149.  elseif x = termX-1 and y = 4 then
  150.   currentColor = colors.magenta
  151.  elseif x = termX-1 and y = 5 then
  152.   currentColor = colors.lime
  153.  elseif x = termX-1 and y = 6 then
  154.   currentColor = colors.green
  155.  elseif x = termX-1 and y = 7 then
  156.   currentColor = colors.pink
  157.  elseif x = termX-1 and y = 8 then
  158.   currentColor = colors.gray
  159.  elseif x >= termX-4 and y = termY then
  160.   saveMovie()
  161.  elseif x >= termX-9 and x <= termX-5 and y = termY then
  162.   paintutils.drawLine(11, 7, 15, 7, colors.lightGray)
  163.   term.setCursorPos(1, 7)
  164.   write("Frame n° :")
  165.   currentFrame = tonumber(read())
  166.  end
Add Comment
Please, Sign In to add comment