1
0
mirror of https://github.com/LDDestroier/CC/ synced 2024-11-14 13:54:52 +00:00
ldd-CC/dvdlogo.lua

169 lines
4.1 KiB
Lua
Raw Normal View History

2020-02-08 22:24:25 +00:00
local mon = peripheral.find("monitor")
if mon then
mon.setTextScale(0.5)
term.redirect(mon)
end
2020-02-08 22:55:40 +00:00
-- adjusts walls of screen so that it will bounce further/closer to the boundries of the screen
local xMargin, yMargin = 0, 0
local redrawDelay = nil
2020-02-09 03:40:41 +00:00
local changeColors = true
2020-02-08 22:55:40 +00:00
2020-02-08 22:24:25 +00:00
local scr_x, scr_y = term.getSize()
local max, min = math.max, math.min
local floor, ceil = math.floor, math.ceil
2020-02-08 22:55:40 +00:00
if scr_x >= 60 and scr_y >= 25 then
redrawDelay = redrawDelay or 0.05
else
redrawDelay = redrawDelay or 0.1
end
local getSize = function(image)
2020-02-08 22:24:25 +00:00
local x, y = 0, #image[1]
for y = 1, #image[1] do
x = max(x, #image[1][y])
end
return x, y
end
local drawImage = function(image, x, y, terminal)
terminal = terminal or term.current()
local cx, cy = terminal.getCursorPos()
for iy = 0, #image[1] + 1 do
terminal.setCursorPos(x - 1, y + (iy - 1))
if image[1][iy] then
terminal.blit(
" " .. image[1][iy] .. " ",
"f" .. image[2][iy] .. "f",
"f" .. image[3][iy] .. "f"
)
else
terminal.clearLine()
end
end
terminal.setCursorPos(cx,cy)
end
2020-02-08 22:55:40 +00:00
local colorSwap = function(image, text, back)
local output = {{},{},{}}
for y = 1, #image[1] do
output[1][y] = image[1][y]
output[2][y] = image[2][y]:gsub(".", text)
output[3][y] = image[3][y]:gsub(".", back or text)
end
return output
end
2020-02-08 22:24:25 +00:00
local logo = {
xvel = (math.random(0, 1) * 2) - 1,
yvel = (math.random(0, 1) * 2) - 1,
x = floor(scr_x / 2),
y = floor(scr_y / 2),
2020-02-08 22:32:28 +00:00
img = {
{
2020-02-08 22:55:40 +00:00
" —ƒƒƒƒƒƒƒƒƒ” Ÿƒƒƒƒƒƒƒ€€",
" ‚ƒƒƒ€ˆƒƒ€€ ‡€€‡ƒƒƒƒ‹€‚",
" —€—€€€€€ ”€• Ÿ€Ÿ€€ •€•",
" €€€‡€— ‚€€‡€€‡ —€— Ÿ€",
"—€€ƒƒ€€‡ ”€€Ÿ €‚ƒ€Ÿ ",
"‚ƒƒƒƒƒ ‚€‡ ƒƒƒƒƒ ",
" ƒƒƒ‚ƒƒƒ ",
" ƒ€€€€€€Ÿ€€€€€€€‚ƒ ",
"•€€€€€€ˆ‘€€€€€€€€€Œ€€€€€€€• ",
" ƒ€€€€€€‚ƒƒƒƒƒ€€€€€€€Ÿƒ ",
" ƒƒƒƒƒƒƒƒ ",
2020-02-08 22:32:28 +00:00
}, {
2020-02-08 22:55:40 +00:00
"00ffffffffff000000fffffffffff",
"000000f0f00000000f000000000f0",
"0f00fff0000f000ff000ff0000f00",
"0f00fff0000000f00000f0000ff00",
"f00ff0000000f0000000f0fff0000",
"00000000000000000000000000000",
"000000fffffffffffffff00000000",
"0fff0000000000000000000fff000",
"f000000f0ffffffffff0000000000",
"000f000000ffffff0000000000000",
"00000000000000000000000000000",
2020-02-08 22:32:28 +00:00
}, {
2020-02-08 22:55:40 +00:00
"ff0000000000ffffff000000000ff",
"ffffff000ff00ffff000ffffff00f",
"f00ffff00ff00ff000fff00fff00f",
"f00fff00ffff00000fff00fff000f",
"0000000fffff000fffff000000fff",
"fffffffffffff0fffffffffffffff",
"ffffff000000000000000ffffffff",
"f000000000ffffff0000000000fff",
"00000000ffffffffff00000000fff",
"fff00000000000000000000ffffff",
"fffffffffffffffffffffffffffff",
2020-02-08 22:32:28 +00:00
}
}
2020-02-08 22:24:25 +00:00
}
local imgXsize, imgYsize = getSize(logo.img)
local xWall, yWall
2020-02-08 22:55:40 +00:00
local render = function(colorReplace)
if colorReplace then
drawImage(
colorSwap(logo.img, {["0"] = colorReplace}, {["0"] = colorReplace}),
floor(logo.x),
floor(logo.y)
)
else
drawImage(
logo.img,
floor(logo.x),
floor(logo.y)
)
end
2020-02-08 22:24:25 +00:00
end
local color = math.random(1, 15)
2020-02-08 22:24:25 +00:00
local tick = function()
scr_x, scr_y = term.getSize()
2020-02-08 22:55:40 +00:00
xWall = scr_x - imgXsize + 1 - xMargin
yWall = scr_y - imgYsize + 1 - yMargin
logo.x = min(max(logo.x + logo.xvel, 1 + xMargin), xWall)
logo.y = min(max(logo.y + logo.yvel, 1 + yMargin), yWall)
2020-02-08 22:24:25 +00:00
2020-02-08 22:55:40 +00:00
if floor(logo.x) == (1 + xMargin) or floor(logo.x) == xWall then
2020-02-08 22:24:25 +00:00
logo.xvel = -logo.xvel
color = math.random(1, 15)
2020-02-08 22:24:25 +00:00
end
2020-02-08 22:55:40 +00:00
if floor(logo.y) == (1 + yMargin) or floor(logo.y) == yWall then
2020-02-08 22:24:25 +00:00
logo.yvel = -logo.yvel
color = math.random(1, 15)
2020-02-08 22:24:25 +00:00
end
2020-02-09 03:40:41 +00:00
if changeColors then
render(string.sub("0123456789abcdef", color, color))
else
render()
end
2020-02-08 22:24:25 +00:00
end
term.setBackgroundColor(colors.black)
term.clear()
2020-02-08 22:55:40 +00:00
local evt
local tID = os.startTimer(redrawDelay)
2020-02-08 22:24:25 +00:00
while true do
2020-02-08 22:55:40 +00:00
evt = {os.pullEventRaw()}
if evt[1] == "timer" and evt[2] == tID then
tick()
tID = os.startTimer(redrawDelay)
elseif evt[1] == "terminate" then
render("8")
sleep(0.05)
render("7")
sleep(0.05)
term.clear()
break
end
2020-02-08 22:24:25 +00:00
end
2020-02-08 22:55:40 +00:00
return 0