Last active
July 2, 2024 00:36
-
-
Save InternetUnexplorer/8ce983889653a16e62609c1884e57611 to your computer and use it in GitHub Desktop.
ComputerCraft program to display useful tips on a connected monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------ | |
-- Wisdom | |
------------------------------------------------ | |
local WISDOM = { | |
"If you do your best, whatever happens will be for the best.", | |
"Things that go away by themselves can come back by themselves.", | |
"Plaid shirts and striped pants rarely\nmake a positive fashion statement.", | |
"You should never dive into murky waters.", | |
"It's never too late to learn to play the piano.", | |
"You can hurt yourself if you run with scissors.", | |
"You should never look directly at the sun.", | |
"This is the last tip.", | |
} | |
local WISDOM_COLORS = { | |
0xFF0000, | |
0xFFBF00, | |
0xFFFF00, | |
0xBFFF00, | |
0x00FF00, | |
0x00FFBF, | |
0x00FFFF, | |
0x00BFFF, | |
} | |
local DAY_START = 06.00 -- 6:00 AM | |
local NIGHT_START = 19.50 -- 7:30 PM | |
------------------------------------------------ | |
local function printCentered(text, yOffset) | |
local width, height = term.getSize() | |
local row = math.floor(height / 2) + yOffset + 1 | |
for line in string.gmatch(text, "([^\n]+)") do | |
local column = math.ceil((width - string.len(line)) / 2) + 1 | |
term.setCursorPos(column, row) | |
term.write(line) | |
row = row + 1 | |
end | |
end | |
local function fadeColor(index, startColor, endColor) | |
local function lerp(a, b, c) | |
return a + (b - a) * c | |
end | |
local cR, cG, cB = colors.unpackRGB(startColor) | |
local tR, tG, tB = colors.unpackRGB(endColor) | |
for i = 0, 63 do | |
local c = i / 63 | |
term.setPaletteColor(index, lerp(cR, tR, c), lerp(cG, tG, c), lerp(cB, tB, c)) | |
sleep() | |
end | |
end | |
local function dayCycle() | |
local wisdom = WISDOM[os.day() % #WISDOM + 1] | |
local wisdomColor = WISDOM_COLORS[os.day() % #WISDOM_COLORS + 1] | |
term.clear() | |
term.setTextColor(0x1) | |
printCentered("Tip of the Day:", -2) | |
term.setTextColor(0x2) | |
printCentered(wisdom, 1) | |
fadeColor(0x1, 0x0, wisdomColor) | |
fadeColor(0x2, 0x0, wisdomColor) | |
os.setAlarm(NIGHT_START) | |
os.pullEvent("alarm") | |
fadeColor(0x1, wisdomColor, 0x0) | |
fadeColor(0x2, wisdomColor, 0x0) | |
end | |
local function nightCycle() | |
local width, height = term.getSize() | |
term.clear() | |
term.setCursorPos(1, 1) | |
-- Credit: RamiLego, dan200 | |
for x = 1, width do | |
for y = 1, height do | |
local starType = math.random(1, 30) | |
if starType == 14 then | |
term.setCursorPos(x, y) | |
term.setTextColor(0x100) | |
term.write(".") | |
elseif starType == 10 then | |
term.setCursorPos(x, y) | |
term.setTextColor(0x100) | |
term.write("*") | |
elseif starType == 16 then | |
term.setCursorPos(x, y) | |
term.setTextColor(0x80) | |
term.write(".") | |
elseif starType == 3 then | |
term.setCursorPos(x, y) | |
term.setTextColor(0x80) | |
term.write("*") | |
end | |
end | |
end | |
fadeColor(0x80, 0x0, 0x4C4C4C) | |
fadeColor(0x100, 0x0, 0x999999) | |
os.setAlarm(DAY_START) | |
os.pullEvent("alarm") | |
fadeColor(0x100, 0x999999, 0x0) | |
fadeColor(0x80, 0x4C4C4C, 0x0) | |
end | |
term.clear() | |
term.setCursorBlink(false) | |
for p = 0, 15 do | |
term.setPaletteColor(math.pow(2, p), 0x0) | |
end | |
while true do | |
if os.time() >= DAY_START and os.time() < NIGHT_START then | |
dayCycle() | |
else | |
nightCycle() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment