Advertisement
Jummit

Computercraft Video Player

Sep 25th, 2018
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. local indexes = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f"}
  2. local palette = {}
  3. local monitor = peripheral.wrap("right")
  4. local w, h = monitor.getSize()
  5. local buffer = window.create(monitor, 1, 1, w, h, true)
  6.  
  7. function makePalette()
  8.   local colorNum = 1
  9.   local monitor = peripheral.wrap("right")
  10.   for colorName, colorId in pairs(colors) do
  11.     if type(colorId)=="number" then
  12.       buffer.setPaletteColor(colors[colorName], colorNum/16, colorNum/16, colorNum/16)
  13.       --buffer.setPaletteColor(colors[colorName], 0, 0, 0)
  14.       palette[indexes[colorNum]] = colorId
  15.       print(indexes[colorNum].." is now "..colorName.." with color "..colorNum*20)
  16.       colorNum = colorNum+1
  17.     end
  18.   end
  19. end
  20.  
  21. function drawImage(file, width, height)
  22.   buffer.setVisible(false)
  23.   for x = 1, width do
  24.     for y = 1, height do
  25.       paintutils.drawPixel(x, y, palette[file.read()])
  26.     end
  27.   end
  28.   buffer.setVisible(true)
  29. end
  30.  
  31. function playMovie(path)
  32.   local file = fs.open(path, "r")
  33.   local dimensions = ""
  34.   local width, height
  35.   while true do
  36.     local char = file.read()
  37.     dimensions = dimensions..char
  38.     if char == ":" then break end
  39.   end
  40.   width = tonumber(dimensions:match("%d*[%x]"))
  41.   height = tonumber(dimensions:match("([%x]%d*)[%:]"))
  42.   term.native().write(width.." "..height)
  43.   while true do
  44.     drawImage(file, width, height)
  45.     sleep(0.1)
  46.   end
  47. end
  48.  
  49. term.redirect(buffer)
  50. monitor.setTextScale(0.5)
  51. makePalette()
  52. playMovie("movie")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement