Update dvdlogo.lua

This commit is contained in:
LDDestroier 2020-02-08 17:55:40 -05:00 committed by GitHub
parent 5092d45b25
commit 82d3e236a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 91 additions and 44 deletions

View File

@ -4,11 +4,22 @@ if mon then
term.redirect(mon)
end
-- 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
local scr_x, scr_y = term.getSize()
local max, min = math.max, math.min
local floor, ceil = math.floor, math.ceil
getSize = function(image)
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)
local x, y = 0, #image[1]
for y = 1, #image[1] do
x = max(x, #image[1][y])
@ -34,6 +45,16 @@ local drawImage = function(image, x, y, terminal)
terminal.setCursorPos(cx,cy)
end
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
local logo = {
xvel = (math.random(0, 1) * 2) - 1,
yvel = (math.random(0, 1) * 2) - 1,
@ -41,41 +62,41 @@ local logo = {
y = floor(scr_y / 2),
img = {
{
" €€€€€€€€€€ Ÿ€€€€€€‚‹ ",
" Ÿ ‚€” •€Š ‡€€‡€ ‹€‚",
" €€ •€• €€Ÿ€Ÿ •€• €€",
"•€• Ÿ‡€Ÿ •€‚€€‡ €€ €…",
"€€€€€Ÿ‡ €€Ÿ •€€€€€ ",
" •‡ ",
" ‡ƒƒƒ€€€€€€‚ƒƒƒ‹ ",
"‡€€€€€€ƒƒƒƒƒ‹€€€€€€‚‹ ",
"€€€€€€ƒ Ÿ‡€€€€€€Ÿ ",
" ‚ƒ€€€€€€€€€€€€€€Ÿƒ ",
" ‚ƒƒƒƒƒƒ ",
" —ƒƒƒƒƒƒƒƒƒ” Ÿƒƒƒƒƒƒƒ€€",
" ‚ƒƒƒ€ˆƒƒ€€ ‡€€‡ƒƒƒƒ‹€‚",
" —€—€€€€€ ”€• Ÿ€Ÿ€€ •€•",
" €€€‡€— ‚€€‡€€‡ —€— Ÿ€",
"—€€ƒƒ€€‡ ”€€Ÿ €‚ƒ€Ÿ ",
"‚ƒƒƒƒƒ ‚€‡ ƒƒƒƒƒ ",
" ƒƒƒ‚ƒƒƒ ",
" ƒ€€€€€€Ÿ€€€€€€€‚ƒ ",
"•€€€€€€ˆ‘€€€€€€€€€Œ€€€€€€€• ",
" ƒ€€€€€€‚ƒƒƒƒƒ€€€€€€€Ÿƒ ",
" ƒƒƒƒƒƒƒƒ ",
}, {
" 00000000000 ff000000ff ",
" ff0 0f00 f0f f000fff 00f",
" 00 f00 000ff000 f00 00",
"f00 ff00 f0f000 00 ff00",
" 0000 f0000000 ",
" f0 ",
" fffffff000000fffffff ",
"ff000000000000000f000000ff ",
"f000000fff ffff0000000 ",
" 0000f0000000000000000000 ",
" 00000000 ",
"00ffffffffff000000fffffffffff",
"000000f0f00000000f000000000f0",
"0f00fff0000f000ff000ff0000f00",
"0f00fff0000000f00000f0000ff00",
"f00ff0000000f0000000f0fff0000",
"00000000000000000000000000000",
"000000fffffffffffffff00000000",
"0fff0000000000000000000fff000",
"f000000f0ffffffffff0000000000",
"000f000000ffffff0000000000000",
"00000000000000000000000000000",
}, {
" 0000000000f 0000000000 ",
" 00f f00f 000 000ff00 f00",
" 00 00f 00f000ff 00f 00",
"00f 000f 00000f 00 000f",
"00000ff 00ff 000000ff ",
" 0f ",
" 00000000000000000000 ",
"00000000fffffffff000000000 ",
"0000000000 0000000000f ",
" ffff000000000000000fffff ",
" ffffffff ",
"ff0000000000ffffff000000000ff",
"ffffff000ff00ffff000ffffff00f",
"f00ffff00ff00ff000fff00fff00f",
"f00fff00ffff00000fff00fff000f",
"0000000fffff000fffff000000fff",
"fffffffffffff0fffffffffffffff",
"ffffff000000000000000ffffffff",
"f000000000ffffff0000000000fff",
"00000000ffffffffff00000000fff",
"fff00000000000000000000ffffff",
"fffffffffffffffffffffffffffff",
}
}
}
@ -83,21 +104,33 @@ local logo = {
local imgXsize, imgYsize = getSize(logo.img)
local xWall, yWall
local render = function()
drawImage(logo.img, floor(logo.x), floor(logo.y))
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
end
local tick = function()
scr_x, scr_y = term.getSize()
xWall = scr_x - imgXsize + 1
yWall = scr_y - imgYsize + 1
logo.x = min(max(logo.x + logo.xvel, 1), xWall)
logo.y = min(max(logo.y + logo.yvel, 1), yWall)
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)
if floor(logo.x) == 1 or floor(logo.x) == xWall then
if floor(logo.x) == (1 + xMargin) or floor(logo.x) == xWall then
logo.xvel = -logo.xvel
end
if floor(logo.y) == 1 or floor(logo.y) == yWall then
if floor(logo.y) == (1 + yMargin) or floor(logo.y) == yWall then
logo.yvel = -logo.yvel
end
render()
@ -106,7 +139,21 @@ end
term.setBackgroundColor(colors.black)
term.clear()
local evt
local tID = os.startTimer(redrawDelay)
while true do
tick()
sleep(0.05)
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
end
return 0