Created
September 9, 2012 22:24
-
-
Save tomoe-mami/3687674 to your computer and use it in GitHub Desktop.
eeeeeeeeklok
This file contains hidden or 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
#!/usr/bin/env lua | |
normal_cell_fmt = "%s" | |
active_cell_fmt = "<color=#ffffff style=glow>%s</>" | |
spacer = "<item size=20x10></>" | |
tm = {} | |
active = {} | |
letters = | |
{ | |
-- 1 2 3 4 5 6 7 8 9 10 11 | |
{ 'I', 'T', 'L', 'I', 'S', 'A', 'S', 'T', 'I', 'M', 'E' }, -- 1 | |
{ 'A', 'C', 'Q', 'U', 'A', 'R', 'T', 'E', 'R', 'D', 'C' }, -- 2 | |
{ 'T', 'W', 'E', 'N', 'T', 'Y', 'F', 'I', 'V', 'E', 'X' }, -- 3 | |
{ 'H', 'A', 'L', 'F', 'B', 'T', 'E', 'N', 'F', 'T', 'O' }, -- 4 | |
{ 'P', 'A', 'S', 'T', 'E', 'R', 'U', 'N', 'I', 'N', 'E' }, -- 5 | |
{ 'O', 'N', 'E', 'S', 'I', 'X', 'T', 'H', 'R', 'E', 'E' }, -- 6 | |
{ 'F', 'O', 'U', 'R', 'F', 'I', 'V', 'E', 'T', 'W', 'O' }, -- 7 | |
{ 'E', 'I', 'G', 'H', 'T', 'E', 'L', 'E', 'V', 'E', 'N' }, -- 8 | |
{ 'S', 'E', 'V', 'E', 'N', 'T', 'W', 'E', 'L', 'V', 'E' }, -- 9 | |
{ 'T', 'E', 'N', 'S', 'E', 'O', 'C', 'L', 'O', 'C', 'K' } -- 10 | |
} | |
wdays = { 'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT' } | |
map = | |
{ | |
-- {row, {col, col, col, ...}} | |
it_is = {1, {1, 2, 4, 5}}, | |
oclock = {10, {6, 7, 8, 9, 10, 11}}, | |
five = {3, {7, 8, 9, 10}}, | |
ten = {4, {6, 7, 8}}, | |
a_quarter = {2, {1, 3, 4, 5, 6, 7, 8, 9 }}, | |
twenty = {3, {1, 2, 3, 4, 5, 6}}, | |
to = {4, {10, 11}}, | |
past = {5, {1, 2, 3, 4}}, | |
half = {4, {1, 2, 3, 4}}, | |
[1] = {6, {1, 2, 3}}, | |
[2] = {7, {9, 10, 11}}, | |
[3] = {6, {7, 8, 9, 10, 11}}, | |
[4] = {7, {1, 2, 3, 4}}, | |
[5] = {7, {5, 6, 7, 8}}, | |
[6] = {6, {4, 5, 6}}, | |
[7] = {9, {1, 2, 3, 4, 5}}, | |
[8] = {8, {1, 2, 3, 4, 5}}, | |
[9] = {5, {8, 9, 10, 11}}, | |
[10] = {10, {1, 2, 3}}, | |
[11] = {8, {6, 7, 8, 9, 10, 11}}, | |
[12] = {9, {6, 7, 8, 9, 10, 11, 12}} | |
} | |
function enable_cell(name) | |
if map[name] then | |
local row = map[name][1] | |
if not active[row] then | |
active[row] = {} | |
end | |
for _,col in ipairs(map[name][2]) do | |
active[row][col] = true | |
end | |
end | |
end | |
function init_time() | |
tm = os.date("*t") | |
if tm.min < 5 then -- O CLOCK | |
enable_cell("oclock") | |
elseif tm.min >= 40 then -- TO | |
if tm.min >= 55 then | |
enable_cell("five") | |
elseif tm.min >= 50 then | |
enable_cell("ten") | |
elseif tm.min >= 45 then | |
enable_cell("a_quarter") | |
else | |
enable_cell("twenty") | |
end | |
enable_cell("to") | |
tm.hour = tm.hour + 1 | |
else -- PAST | |
if tm.min < 10 then | |
enable_cell("five") | |
elseif tm.min < 15 then | |
enable_cell("ten") | |
elseif tm.min < 20 then | |
enable_cell("a_quarter") | |
elseif tm.min < 30 then | |
enable_cell("twenty") | |
elseif tm.min < 40 then | |
enable_cell("half") | |
end | |
enable_cell("past") | |
end | |
local hour = tm.hour % 12 | |
if hour == 0 then hour = 12 end | |
enable_cell(hour) | |
enable_cell("it_is") | |
end | |
init_time() | |
io.stdout:write( | |
"<font='Droid Sans Mono' font_size=50 color=#111111 " .. | |
"style=shadow shadow_color=#cccccc30 glow_color=#268BD210 glow2_color=#268BD230 " .. | |
"align=center>") | |
for row_index,row_data in ipairs(letters) do | |
for col_index,character in ipairs(row_data) do | |
local fmt = "" | |
if active[row_index] and active[row_index][col_index] then | |
fmt = active_cell_fmt | |
else | |
fmt = normal_cell_fmt | |
end | |
io.stdout:write(string.format(fmt, character)) | |
if col_index == #row_data then | |
io.stdout:write("\n") | |
else | |
io.stdout:write(spacer) | |
end | |
end | |
end | |
io.stdout:write("<font_size=25><item absize=10x40></>") | |
for day_index, day_name in ipairs(wdays) do | |
local fmt = "" | |
if tm.wday == day_index then | |
fmt = active_cell_fmt | |
else | |
fmt = normal_cell_fmt | |
end | |
io.stdout:write(string.format(fmt, day_name)) | |
if day_index == #wdays then | |
io.stdout:write("\n") | |
else | |
io.stdout:write("<item size=34x10></>") | |
end | |
end | |
io.stdout:write("</>") | |
--[[ | |
[io.stdout:write("<font_size=12 font_weight=bold color=#000000>\n") | |
[ | |
[for i = 0,59 do | |
[ local ch = "-" | |
[ if i == 59 or (i % 10) == 0 then | |
[ ch = "|" | |
[ end | |
[ | |
[ local fmt = "" | |
[ if i == tm.sec then | |
[ fmt = active_cell_fmt | |
[ else | |
[ fmt = normal_cell_fmt | |
[ end | |
[ | |
[ io.stdout:write(string.format(fmt, ch)) | |
[end | |
[ | |
[io.stdout:write("</>") | |
]] | |
io.stdout:write("</>\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment