Last active
July 18, 2019 16:10
-
-
Save mustooch/909c63da9d9ef1df7a50ede3eaadacd1 to your computer and use it in GitHub Desktop.
Display current time with the hex color format in the background
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
function hex_time() | |
time = os.date("*t", os.time()) | |
return {time.hour, time.min, time.sec} | |
end | |
function hex2dec(n) | |
return tonumber("0x"..n) | |
end | |
function hex2love(t) | |
return { | |
hex2dec(t[1])/255, | |
hex2dec(t[2])/255, | |
hex2dec(t[3])/255 | |
} | |
end | |
function love.load() | |
hex_str = "" | |
love.window.setMode(512,512) | |
end | |
function love.update(dt) | |
time = hex_time() | |
hex_str = "#"..tostring(time[1])..tostring(time[2])..tostring(time[3]) | |
back = hex2love(time) | |
love.graphics.setBackgroundColor(back[1],back[2],back[3]) | |
end | |
function love.draw() | |
love.graphics.print(hex_str, 512/2-20, 512/2) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment