Created
April 14, 2009 18:43
-
-
Save JakeWharton/95341 to your computer and use it in GitHub Desktop.
Python function to generate seven-segment number strings. Derived from Knio.
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
def seven_seg(x): | |
''' | |
_ _ _ _ _ _ _ _ | |
|_||_| ||_ |_ |_| _| _| || | | |
_||_| ||_| _| | _||_ ||_| | |
1111101101 = 1005 | |
1101110001 = 881 | |
1101111100 = 892 | |
1110011111 = 927 | |
0101000101 = 325 | |
1101101101 = 877 | |
1111111011 = 1019 | |
''' | |
s1=s2=s3='' | |
for i in x: | |
if i == '-': | |
s1 += ' ' | |
s2 += ' _ ' | |
s3 += ' ' | |
elif i == '.': | |
s1 += ' ' | |
s2 += ' ' | |
s3 += ' . ' | |
else: | |
r=int(i) | |
s1 += 1005>>r&1 and ' _ ' or ' ' | |
s2 += 881 >>r&1 and '|' or ' ' | |
s2 += 892 >>r&1 and '_' or ' ' | |
s2 += 927 >>r&1 and '|' or ' ' | |
s3 += 325 >>r&1 and '|' or ' ' | |
s3 += 877 >>r&1 and '_' or ' ' | |
s3 += 1019>>r&1 and '|' or ' ' | |
return '\n'.join([s1,s2,s3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment