Clock is done
This commit is contained in:
parent
04d67e681c
commit
ef0bbbd6b0
55
lc
Executable file
55
lc
Executable file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from datetime import datetime
|
||||
import time
|
||||
|
||||
CHARS_PER_LINE = 30 # For sixty dots per line
|
||||
DOTS_PER_LINE = CHARS_PER_LINE * 2
|
||||
|
||||
DY_ONE = 0x01 # Top Left
|
||||
HR_ONE = 0x02 # Center Left
|
||||
MN_ONE = 0x04 # Bottom Left
|
||||
DY_TWO = 0x08 | DY_ONE # Top Left + Right
|
||||
HR_TWO = 0x10 | HR_ONE # Center Left + Right
|
||||
MN_TWO = 0x20 | MN_ONE # Bottom Left + Right
|
||||
|
||||
|
||||
def to_dots(unit, divisor):
|
||||
return unit / divisor * DOTS_PER_LINE
|
||||
|
||||
|
||||
def time_to_dots(time):
|
||||
return to_dots(time.hour, 24), to_dots(time.minute, 60), to_dots(time.second, 60)
|
||||
|
||||
|
||||
def construct_char_row(index, total_dots, flag_one, flag_two):
|
||||
current_dots = index * 2
|
||||
|
||||
if total_dots > current_dots:
|
||||
if total_dots - current_dots > 1: return flag_two
|
||||
else: return flag_one if total_dots % 2 == 1 else flag_two
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def construct_clock_char(index, dy_dots, hr_dots, mn_dots):
|
||||
char = 0x2800 # The codepoint for an empty Braille character
|
||||
|
||||
char |= construct_char_row(index, dy_dots, DY_ONE, DY_TWO)
|
||||
char |= construct_char_row(index, hr_dots, HR_ONE, HR_TWO)
|
||||
char |= construct_char_row(index, mn_dots, MN_ONE, MN_TWO)
|
||||
|
||||
return chr(char)
|
||||
|
||||
|
||||
def construct_clock(dy_dots, hr_dots, mn_dots):
|
||||
clock_str = ""
|
||||
|
||||
for i in range(CHARS_PER_LINE):
|
||||
clock_str += construct_clock_char(i, dy_dots, hr_dots, mn_dots)
|
||||
|
||||
return clock_str
|
||||
|
||||
|
||||
dy_dots, hr_dots, mn_dots = time_to_dots(datetime.now())
|
||||
print(f"{datetime.now().strftime('%H:%M:%S')}: {construct_clock(dy_dots, hr_dots, mn_dots)}")
|
Loading…
Reference in New Issue
Block a user