forked from hkc/cc-stuff
44 lines
1012 B
Lua
44 lines
1012 B
Lua
|
term.clear()
|
||
|
term.setCursorPos(1, 1)
|
||
|
term.setTextColor(colors.white)
|
||
|
|
||
|
local tw, th = term.getSize()
|
||
|
print(string.format("Terminal: %dx%d", tw, th))
|
||
|
local function printScale(c1, c2, p, fmt, ...)
|
||
|
local str = string.format(fmt, ...)
|
||
|
local w1 = math.ceil(p * tw)
|
||
|
local w2 = tw - w1
|
||
|
|
||
|
local bg = term.getBackgroundColor()
|
||
|
term.setBackgroundColor(c1)
|
||
|
term.write(str:sub(1, w1))
|
||
|
local rem = w1 - #str
|
||
|
if rem > 0 then
|
||
|
term.write(string.rep(" ", rem))
|
||
|
end
|
||
|
|
||
|
term.setBackgroundColor(c2)
|
||
|
term.write(str:sub(w1 + 1, w1 + w2))
|
||
|
|
||
|
rem = math.min(tw - #str, w2)
|
||
|
if rem > 0 then
|
||
|
term.write(string.rep(" ", rem))
|
||
|
end
|
||
|
|
||
|
term.setBackgroundColor(bg)
|
||
|
print()
|
||
|
end
|
||
|
|
||
|
|
||
|
term.setBackgroundColor(colors.black)
|
||
|
local t = 0
|
||
|
while true do
|
||
|
for i = 1, th do
|
||
|
local p = 0.5 + 0.5 * math.sin((i + t) * math.pi / 25)
|
||
|
term.setCursorPos(1, i)
|
||
|
printScale(colors.red, colors.gray, p, "%7.3f%%", p * 100)
|
||
|
end
|
||
|
os.sleep(0.05)
|
||
|
t = t + 1
|
||
|
end
|