Created
January 29, 2018 17:07
-
-
Save samuelhnrq/30f5f20ccebf91dce032182fb4e77b12 to your computer and use it in GitHub Desktop.
Binary clock to stdout in python
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
# pylint:disable=C0111 | |
import time | |
BRAILLE_UNICODE_OFFSET = 0x2800 | |
# https://www.wikiwand.com/en/Braille_Patterns#/Identifying,_naming_and_ordering | |
# id of which braille balls that need to be ticked to represent nth dozen | |
UNITS = [ | |
0x0, | |
0x80, | |
0x20, | |
0x80 + 0x20, | |
0x10, | |
0x10 + 0x80, | |
0x10 + 0x20, | |
0x10 + 0x20 + 0x80, | |
0x8, | |
0x8 + 0x80 | |
] | |
# It is completly unecessary to add the codes together but I think it's harmless | |
# enough and self-documenting | |
# id of which braille balls that need to be ticked to represent nth unit | |
DOZENS = [ | |
0x0, | |
0x40, | |
0x4, | |
0x4 + 0x40, | |
0x2, | |
0x2 + 0x40, | |
0x2 + 0x4, | |
0x2 + 0x40 + 0x4, | |
0x1, | |
0x1 + 0x40 | |
] | |
DIGITS = [] | |
for x in range(0, 10): | |
for y in range(0, 10): | |
# the ids of the balls needed to represent unit and the dozens | |
# added together represent the unicode character code when | |
# added to the braille offset (code of the empty braille symbol) | |
DIGITS.append(chr(BRAILLE_UNICODE_OFFSET + DOZENS[x] + UNITS[y])) | |
def main(): | |
try: | |
while True: | |
time_tuple = time.localtime() | |
# hours, secs, minutes | |
time_tuple = time_tuple[3:6] | |
time_str = '' | |
for val in time_tuple: | |
time_str += DIGITS[val] + ' ' | |
time_str.strip() | |
print(time_str) | |
time.sleep(1) | |
except KeyboardInterrupt: | |
return | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment