1
0
Fork 0

Bigterm slideshow, etc

This commit is contained in:
Casey 2024-01-21 18:46:33 +03:00
parent 1e4fa997c0
commit 4922c5550f
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
3 changed files with 96 additions and 9 deletions

View File

@ -196,7 +196,19 @@ local BigTerm = {
}
return function(monitors, args)
local lib = {}
function lib.fromFile(conf)
local fp = assert(io.open(conf, "r"))
local conf = textutils.unserializeJSON(fp:read("a"))
fp:close()
local monitors = {}
for addr, pos in pairs(conf.monitors) do
local p = assert(peripheral.wrap(addr))
table.insert(monitors, { p = p, x = pos.x, y = pos.y })
end
return lib.new(monitors, { palette = conf.palette, scale = conf.scale })
end
function lib.new(monitors, args)
args = args or {}
local mon = setmetatable({
_monitors = monitors,
@ -215,3 +227,5 @@ return function(monitors, args)
mon._reset()
return mon
end
return lib

26
btccshow.lua Normal file
View File

@ -0,0 +1,26 @@
local args = { ... }
local ccpi = require("ccpi")
local bigterm = require("bigterm").fromFile("/bigterm.json")
local img, err = ccpi.load(args[1])
if not img then
printError(err)
return
end
local ys = {}
for y = 1, img.h do table.insert(ys, y) end
for i = 1, math.floor((#ys) / 2), 2 do
local a, b = i, (#ys - 1) - i + 1
ys[a], ys[b] = ys[b], ys[a]
end
for i, y in ipairs(ys) do
bigterm.setCursorPos(1, y)
bigterm.blit(img.lines[y].s, img.lines[y].fg, img.lines[y].bg)
end
for i = 1, 16 do
bigterm.setPaletteColor(bit.blshift(1, i - 1), img.palette[i])
end

47
btccslideshow.lua Normal file
View File

@ -0,0 +1,47 @@
local args = { ... }
local ccpi = require("ccpi")
local bigterm = require("bigterm")
local conf_path = "/bigterm.json"
if args[1] == "-c" then
table.remove(args, 1)
conf_path = table.remove(args, 1)
end
local screen = bigterm.fromFile(conf_path)
local time = 10
if args[1] == "-t" then
table.remove(args, 1)
time = tonumber(table.remove(args, 1))
end
local files = fs.list(args[1])
while true do
local img, err = ccpi.load(fs.combine(args[1], files[math.random(1, #files)]))
if not img then
printError(err)
return
else
local ys = {}
for y = 1, img.h do table.insert(ys, y) end
for i = 1, math.floor((#ys) / 2), 2 do
local a, b = i, (#ys - 1) - i + 1
ys[a], ys[b] = ys[b], ys[a]
end
for i, y in ipairs(ys) do
screen.setCursorPos(1, y)
screen.blit(img.lines[y].s, img.lines[y].fg, img.lines[y].bg)
if (i % 10) == 0 then
os.sleep(0)
end
end
for i = 1, 16 do
screen.setPaletteColor(bit.blshift(1, i - 1), img.palette[i])
end
end
os.sleep(time)
end