From a00dca3be1ebbbf872fdf3f9c2db4ba696e8388a Mon Sep 17 00:00:00 2001 From: hkc Date: Fri, 13 Sep 2024 06:01:15 +0300 Subject: [PATCH] Animation player Usage: anim-web [-m side] Example: anim-web -m top 137 https://kc.is.being.pet/f/ccpi/rivulet/frame%03d.cpi --- anim-web.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 anim-web.lua diff --git a/anim-web.lua b/anim-web.lua new file mode 100644 index 0000000..85c4f68 --- /dev/null +++ b/anim-web.lua @@ -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 +