Created
May 28, 2016 16:56
-
-
Save DomNomNom/d85c53229e50f0552e207f5b31c9a160 to your computer and use it in GitHub Desktop.
Prints the current time in nice ascii art. Clean code using numpy
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
import numpy as np | |
charWidth = 3 | |
char2index = { c : i*charWidth for i,c in enumerate('0123456789: ')} | |
bigAlphabet = ''' | |
_ _ _ _ _ _ _ _ | | |
| | | _| _||_||_ |_ ||_||_| . | | |
|_| ||_ _| | _||_| ||_| | . | | |
'''[1:-1].split('\n') | |
bigAlphabet = np.array(list(map(list, bigAlphabet))) | |
def getDigit(letter): | |
index = char2index[letter] | |
return bigAlphabet[..., index:index+charWidth] | |
def makeBig(string): | |
assert all(letter in char2index for letter in string) | |
return np.hstack(map(getDigit, string)) | |
def printBig(arr): | |
print ('\n'.join(''.join(row) for row in arr)) | |
import datetime | |
now = datetime.datetime.now() | |
timeString = "{:02d}:{:02d}:{:02d}".format(now.hour, now.minute, now.second) | |
print (timeString) | |
printBig(makeBig(timeString)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment