Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get bvx6Tipk blit
- -- Plays animations.
- -- After loading a GIF and processing it, saves the result so as to take
- -- less disk space and reduce load times for subsequent playbacks.
- local timePerImage = 30
- local function loadAPI(API, paste)
- if not _G[API] then
- if not (fs.exists(API) or fs.exists(shell.resolve(API))) then
- shell.run("pastebin get " .. paste .. " " .. API)
- os.loadAPI(shell.resolve(API))
- else os.loadAPI(fs.exists(API) and API or shell.resolve(API)) end
- end
- end
- loadAPI("bbpack", "cUYTGbpb")
- loadAPI("GIF", "5uk9uRjC")
- loadAPI("blittle", "ujchRSnU")
- local GIFlist, BLTlist = fs.list(shell.resolve("")), {}
- for i = #GIFlist, 1, -1 do
- local ext = GIFlist[i]:sub(-4):lower()
- if ext == ".blt" then
- BLTlist[#BLTlist + 1] = table.remove(GIFlist, i)
- elseif ext ~= ".gif" then
- table.remove(GIFlist, i)
- end
- end
- local mon = peripheral.find("monitor") or term
- if mon.setTextScale then mon.setTextScale(0.5) end
- local MonSizeX, MonSizeY = mon.getSize()
- MonSizeX, MonSizeY = MonSizeX * 2, MonSizeY * 3
- parallel.waitForAll(
- function()
- if #BLTlist == 0 then os.pullEvent("madeBLT") end
- while true do
- local img = blittle.load(shell.resolve(BLTlist[math.random(#BLTlist)]))
- if img.pal and GIF.applyPalette then GIF.applyPalette(img, mon) end
- mon.clear()
- local x, y = math.floor((MonSizeX / 2 - img[1].width) / 2) + 1, math.floor((MonSizeY / 3 - img[1].height) / 2) + 1
- if #img == 1 then img[1].delay = timePerImage end
- repeat
- local frameTimer, nextTimer, curFrame = os.startTimer(0), os.startTimer(timePerImage), 1
- while true do
- local event, par1 = os.pullEvent()
- if event == "timer" then
- if par1 == frameTimer then
- local frame = img[curFrame]
- blittle.draw(type(frame[1]) == "number" and img[frame[1]] or frame, x, y, mon)
- frameTimer = os.startTimer(img[curFrame].delay)
- if curFrame == #img then
- if not nextTimer then break end
- curFrame = 1
- else curFrame = curFrame + 1 end
- elseif par1 == nextTimer then
- nextTimer = false
- end
- elseif event == "char" or event == "mouse_click" or event == "monitor_touch" then
- break
- end
- end
- until #BLTlist > 1
- end
- end,
- function()
- for i = 1, #GIFlist do
- local file = GIFlist[i]
- write(file)
- local ok, img = pcall(GIF.loadGIF, shell.resolve(file), term.setPaletteColour and true)
- if ok then
- if MonSizeX < img.width or MonSizeY < img.height then
- if MonSizeX < math.floor(MonSizeY / img.height * img.width) then
- img = GIF.resizeGIF(img, MonSizeX)
- else
- img = GIF.resizeGIF(img, nil, MonSizeY)
- end
- end
- img = blittle.shrinkGIF(img)
- print(" - writing...")
- fs.delete(shell.resolve(file))
- file = file:sub(1, -5) .. ".blt"
- blittle.save(img, shell.resolve(file))
- os.queueEvent("madeBLT")
- BLTlist[#BLTlist + 1] = file
- else
- printError(img)
- end
- end
- print("All GIFs processed.")
- GIFlist = nil
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement