Animation player

Usage:
  anim-web [-m side] <n-frames> <url%d.cpi>
Example:
  anim-web -m top 137 https://kc.is.being.pet/f/ccpi/rivulet/frame%03d.cpi
This commit is contained in:
Casey 2024-09-13 06:01:15 +03:00
parent 38cce4226a
commit a00dca3be1
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 41 additions and 0 deletions

41
anim-web.lua Normal file
View File

@ -0,0 +1,41 @@
local ccpi = require("ccpi")
local args = { ... }
local terminal = term.current()
if args[1] == "-m" then
table.remove(args, 1)
print("Using monitor: " .. args[1])
terminal = peripheral.wrap(table.remove(args, 1))
end
local frames = {}
local n_frames = tonumber(args[1])
local base_path = args[2]
for i = 1, n_frames do
local url = string.format(base_path, i)
print("GET " .. url)
local req, err = http.get(url, nil, true)
if not req then
printError(err)
return
end
local img, err = ccpi.parse(req)
if not img then
printError(err)
return
else
print(img.w .. "x" .. img.h)
end
table.insert(frames, img)
req.close()
end
local frame_no = 0
while true do
local frame = frames[(frame_no % #frames) + 1]
ccpi.draw(frame, 1, 1, terminal)
os.sleep(0.0)
frame_no = frame_no + 1
end