Created
June 2, 2022 23:17
-
-
Save 10maurycy10/2907236fdfd44e5dff9e14aae7e687f1 to your computer and use it in GitHub Desktop.
ITA2 5-hole paper tape ascii art generator
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
#!/bin/python3 | |
import sys | |
# ITA2 | |
ITA2_FS="11011" | |
ITA2_LS="11111" | |
ITA2_LTR = { | |
"\0": "00000", | |
"\r": "01000", | |
"\n": "00010", | |
" ": "00100", | |
"Q": "10111", | |
"W": "10011", | |
"E": "00001", | |
"R": "01010", | |
"T": "10000", | |
"Y": "10101", | |
"U": "00111", | |
"I": "00110", | |
"O": "11000", | |
"P": "10110", | |
"A": "00011", | |
"S": "00101", | |
"D": "01001", | |
"F": "01101", | |
"G": "11010", | |
"H": "10100", | |
"J": "10111", | |
"K": "01111", | |
"L": "10010", | |
"Z": "10001", | |
"X": "11101", | |
"C": "01110", | |
"V": "11110", | |
"B": "11001", | |
"N": "01100", | |
"M": "11100", | |
} | |
ITA2_FIG = { | |
"\0": "00000", | |
"\r": "01000", | |
"\n": "00010", | |
" " : "00100", | |
"1" : "10111", | |
"2" : "10011", | |
"3" : "00001", | |
"4" : "01010", | |
"5" : "10000", | |
"6" : "10101", | |
"7" : "00111", | |
"8" : "00110", | |
"9" : "11000", | |
"0" : "10110", | |
"-" : "00011", | |
"'" : "00101", | |
"\05" : "01001", # WRU? | |
"!" : "01101", | |
"&" : "11010", | |
"£" : "10100", | |
"\07" : "01011", # Bell | |
"(" : "01111", | |
")" : "10010", | |
"+" : "10001", | |
"/" : "11101", | |
":" : "01110", | |
"=" : "11110", | |
"?" : "11001", | |
"," : "01100", | |
"." : "11100", | |
"\7f" : "11111", #NOTE this is also the "Shift to letters char" | |
} | |
print(" ______ ") | |
print("| o |") | |
def codepoint(binary): | |
c = ['O' if bit=='1' else ' ' for bit in binary] | |
print("|{}{}{}o{}{}|".format(c[0], c[1], c[2], c[3], c[4])) | |
# returns the next state for the encoding | |
def codechar(c, state): | |
if c == "\7f": | |
codepoint(ITA2_FIG[c]) | |
return "LTR" | |
elif state == "LTR" and c in ITA2_LTR: | |
codepoint(ITA2_LTR[c]) | |
return "LTR" | |
elif state == "LTR" and c in ITA2_FIG: | |
codepoint(ITA2_FS) | |
codepoint(ITA2_FIG[c]) | |
return "FIG" | |
elif state == "FIG" and c in ITA2_FIG: | |
codepoint(ITA2_FIG[c]) | |
return "FIG" | |
elif state == "FIG" and c in ITA2_LTR: | |
codepoint(ITA2_LS) | |
codepoint(ITA2_LTR[c]) | |
return "LTR" | |
else: | |
print("unkown char '" + c + "', not coded.") | |
def codestr(s, state): | |
for c in s: | |
state = codechar(c, state) | |
return state | |
# Ensure LTR state, mark end of tape | |
codepoint(ITA2_LS) | |
codepoint(ITA2_LS) | |
codepoint(ITA2_LS) | |
codepoint(ITA2_LS) | |
codepoint(ITA2_LS) | |
cstate = "LTR" | |
codestr(sys.stdin.read(), cstate) | |
codepoint(ITA2_LS) | |
codepoint(ITA2_LS) | |
codepoint(ITA2_LS) | |
codepoint(ITA2_LS) | |
codepoint(ITA2_LS) | |
print("|___o__|") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment