137 lines
2.7 KiB
Python
137 lines
2.7 KiB
Python
|
TEXT = """\
|
||
|
ESXISTXFÜNF\
|
||
|
ZEHNZWANZIG\
|
||
|
DREIVIERTEL\
|
||
|
VORGESTNACH\
|
||
|
HALBXELFÜNF\
|
||
|
EINSXLEZWEI\
|
||
|
DREIXTXVIER\
|
||
|
SECHSXXACHT\
|
||
|
SIEBENZWÖLF\
|
||
|
ZEHNEUNXUHR\
|
||
|
"""
|
||
|
|
||
|
SEGMENTS = {
|
||
|
'ES IST': [(0, 2), (3, 3)],
|
||
|
'FÜNF_PRE': [(7, 4)],
|
||
|
'FÜNFZEHN': [(7, 8)],
|
||
|
'ZEHN_PRE': [(11, 4)],
|
||
|
'ZWANZIG': [(15, 7)],
|
||
|
'DREIVIERTEL': [(22, 11)],
|
||
|
'VIERTEL': [(26, 7)],
|
||
|
'VOR': [(33, 3)],
|
||
|
'NACH': [(40, 4)],
|
||
|
'HALB': [(44, 4)],
|
||
|
'ELF': [(49, 3)],
|
||
|
'FÜNF_UHR': [(51, 4)],
|
||
|
'EINS': [(55, 4)],
|
||
|
'ZWEI': [(62, 4)],
|
||
|
'DREI': [(66, 4)],
|
||
|
'VIER': [(73, 4)],
|
||
|
'SECHS': [(77, 5)],
|
||
|
'ACHT': [(84, 4)],
|
||
|
'SIEBEN': [(88, 6)],
|
||
|
'ZWÖLF': [(94, 5)],
|
||
|
'ZEHN_UHR': [(99, 4)],
|
||
|
'NEUN': [(102, 4)],
|
||
|
'UHR': [(107, 3)],
|
||
|
'STELLE': [(38, 2), (49, 2), (60, 2)],
|
||
|
'GESTELLT': [(36, 4), (49, 2), (60, 1), (71, 1)],
|
||
|
}
|
||
|
|
||
|
HOURS = ['ZWÖLF', 'EINS', 'ZWEI', 'DREI', 'VIER', 'FÜNF_UHR', 'SECHS', 'SIEBEN', 'ACHT', 'NEUN', 'ZEHN_UHR', 'ELF' ]
|
||
|
PARTS = [['UHR'], ['FÜNF_PRE'], ['ZEHN_PRE'], ['VIERTEL'], ['ZWANZIG'], ['FÜNF_PRE', 'HALB'], ['HALB']]
|
||
|
|
||
|
active = [False] * len(TEXT)
|
||
|
|
||
|
def set(segment, val=True):
|
||
|
for word in segment:
|
||
|
idx, len = word
|
||
|
active[idx:idx+len] = [val for _ in range(len)]
|
||
|
|
||
|
def reset():
|
||
|
global active
|
||
|
set([(0, len(TEXT))], False)
|
||
|
set(SEGMENTS['ES IST'])
|
||
|
|
||
|
def settime(time):
|
||
|
reset()
|
||
|
|
||
|
hour = time.hour % 12
|
||
|
minute = 5 * round((time.minute + time.second/60) / 5)
|
||
|
before = False
|
||
|
|
||
|
if minute >= 25:
|
||
|
hour = (hour + 1) % 12
|
||
|
before = True
|
||
|
minute = (60-minute)
|
||
|
if minute == 35:
|
||
|
minute = 25
|
||
|
before = False
|
||
|
|
||
|
print(minute, 'vor' if before else 'nach', hour)
|
||
|
|
||
|
# 25 before 6 -> 5 after half 6
|
||
|
# 25 after 6 -> 5 before half 6
|
||
|
if minute == 25:
|
||
|
before = not before
|
||
|
|
||
|
if not minute in [0, 30]:
|
||
|
set(SEGMENTS['VOR' if before else 'NACH'])
|
||
|
|
||
|
set(SEGMENTS[HOURS[hour]])
|
||
|
|
||
|
for part in PARTS[minute//5]:
|
||
|
set(SEGMENTS[part])
|
||
|
|
||
|
|
||
|
def dump():
|
||
|
COLS = 11
|
||
|
RESET = '\033[0m'
|
||
|
WHITE = '\033[1;37m'
|
||
|
GRAY = '\033[0;30m'
|
||
|
for i, char in enumerate(TEXT):
|
||
|
col = i % COLS
|
||
|
row = i // COLS
|
||
|
if (col == 0):
|
||
|
print('\n ', end='')
|
||
|
color = (WHITE if active[i] else GRAY) if i==0 or active[i] != active[i-1] else ''
|
||
|
print(f' {color}{char} ', end='')
|
||
|
print(RESET+'\n')
|
||
|
|
||
|
|
||
|
def live():
|
||
|
import time
|
||
|
from datetime import datetime
|
||
|
while True:
|
||
|
print('\033c', end='')
|
||
|
|
||
|
now = datetime.now()
|
||
|
print(now)
|
||
|
|
||
|
settime(now)
|
||
|
dump()
|
||
|
|
||
|
time.sleep(1)
|
||
|
|
||
|
def demo():
|
||
|
import time
|
||
|
import datetime
|
||
|
t = datetime.datetime.now()
|
||
|
while True:
|
||
|
print('\033c', end='')
|
||
|
print(t)
|
||
|
|
||
|
settime(t)
|
||
|
dump()
|
||
|
|
||
|
time.sleep(1)
|
||
|
t += datetime.timedelta(minutes=1)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
import sys
|
||
|
if len(sys.argv) > 1 and sys.argv[1] == 'demo':
|
||
|
demo()
|
||
|
else:
|
||
|
live()
|