Last active
August 29, 2015 13:59
-
-
Save zheplusplus/10950658 to your computer and use it in GitHub Desktop.
つかさンス ASCII Art Font
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
import sys | |
import json | |
FIXED_WIDTH = len('_________') | |
FIXED_HEIGHT = 6 | |
def map_characters(string, typo_group): | |
return { | |
string[col]: [typo_group[row][col * (1 + FIXED_WIDTH): | |
col * (1 + FIXED_WIDTH) + FIXED_WIDTH] | |
for row in range(FIXED_HEIGHT)] | |
for col in range(len(typo_group[0]) / FIXED_WIDTH) | |
} | |
def build(): | |
r = dict() | |
r.update(map_characters('01234', ( | |
r''' _______ ________ _______ ________ ____ ____ ''', | |
r'''/ \ / | / \ / | | | | | ''', | |
r'''| | |_ | |_ | |-- | | |_| | ''', | |
r'''| 0 | | | / / | | | | ''', | |
r'''| | | | | /__ |-- | |_____ | ''', | |
r'''\_______/ |_____| |_______| \_______| |__| ''', | |
))) | |
r.update(map_characters('56789', ( | |
r'''________ ________ _________ _______ ________ ''', | |
r'''| | / | | | / \ | \ ''', | |
r'''| -- | ---| |___ | | O | | O | ''', | |
r'''| \ | | | | | | | | ''', | |
r'''|-- | | O | | | | O | |--- | ''', | |
r'''|_______/ \_______| |____| \_______/ |_______/ ''', | |
))) | |
r.update(map_characters('ABCDEFG', ( | |
r''' _______ ________ ________ ________ _________ _________ ________ ''', | |
r'''/ \ | \ / | | \ | | | | | | ''', | |
r'''| | | -- | | | | | | --| | --| | ----| ''', | |
r'''| - | | - | -- | D | | | | | | | | ''', | |
r'''| _ | | -- | | | | | | --| | -- | -- | ''', | |
r'''|__| |__| |_______/ \_______| |_______/ |_______| |_____| |_______| ''', | |
))) | |
r.update(map_characters('HIJKLMN', ( | |
r'''___ ___ _________ _______ _________ _______ _________ ____ ____ ''', | |
r'''| |_| | |_ _| | | | | | | | | | | \| | ''', | |
r'''| | | | | | | / | | | | | | | ''', | |
r'''| | | | _/ | | \ | |_ | | | | ''', | |
r'''| _ | _| |_ | | | | | | | | | | | | | ''', | |
r'''|__| |__| |_______| |_______/ |___|___| |_______| |__|__|_| |__|\___| ''', | |
))) | |
r.update(map_characters('OPQRST', ( | |
r''' _______ ________ _______ ________ ________ _________ ''', | |
r'''/ \ | | / \ | \ | | | | ''', | |
r'''| | | - | | | | - | | ---| |_ _| ''', | |
r'''| O | | _| | + | | / | | | | ''', | |
r'''| | | | | \ | _ \ |--- | | | ''', | |
r'''\_______/ |_____| \_____\_/ |__| \__| |_______| |___| ''', | |
))) | |
r.update(map_characters('UVWXYZ', ( | |
r'''_________ _________ _________ ____ ____ ____ ____ _________ ''', | |
r'''| | | | | | | | | | | | | | | | | | ''', | |
r'''| | | | | | | | | | | | | | |--- | ''', | |
r'''| | | | | | - - \ / | | ''', | |
r'''| | \ / | | | | | | | ---| ''', | |
r'''|_______| \___/ |_______| |___|___| |___| |_______| ''', | |
))) | |
r.update(map_characters('~`!@#%^', ( | |
r''' _________ _______ _______ _ ___ ___ ''', | |
r''' ___ /\ | | / ___ \ _| | |_ / |/ | / \ ''', | |
r'''/ \__/\ / \ | | | / \ | | | | / / / \ ''', | |
r'''| __ | / \ \_____/ | | O | | -- -- --/ /_ /___^___\ ''', | |
r'''\/ \___/ `-._ \ ___ | \_____| |_ _| / / | ''', | |
r''' `-._\ |___| \_______/ |__|__| |___/|_/ ''', | |
))) | |
r.update(map_characters('&*()-_+', ( | |
r''' ____ _ _ _____ _____ _____ ''', | |
r'''/ \ / \_/ \ ,' ,' `. `. | | ''', | |
r'''| () | _ \ / / / \ \ --------- --' '-- ''', | |
r''') // | [_ _] ( ( ) ) | | | | ''', | |
r'''| (\ V / / _ \ \ \ / / --------- --------- --. .-- ''', | |
r'''\___.__\ \_/ \_/ `.___`. ,'___,' |_______| |___| ''', | |
))) | |
r.update(map_characters('=[]{}:;', ( | |
r''' _________ _________ ______ ______ ______ _____ ''', | |
r'''_________ | | | | / | | \ / | / | ''', | |
r'''|_______| | ---- ---- | | / \ | |______/ |____/ ''', | |
r'''_________ | | | | < | | > ______ ______ ''', | |
r'''|_______| | ---- ---- | | \ / | / | _| | ''', | |
r''' |_______| |_______| \_____| |_____/ |______/ |______/ ''', | |
))) | |
r.update(map_characters('''"',<>.?''', ( | |
r'''____ ____ ________ ____ ____ _________ ''', | |
r'''| | | | | | ,' ,' `. `. | | ''', | |
r'''|_ | |_ | |_ | ________ ,' ,' `. `. _______ | __ | ''', | |
r''' / | / | ) | | | < < > > / | '--|____| ''', | |
r'''/__/ /__/ /_____/ / / `. `. .' ,' | | ___ ''', | |
r''' (______/ `.__`. ,'__,' |_______/ |___| ''', | |
))) | |
r.update(map_characters(r'/\|$ ', ( | |
r''' _____ _____ _____ ___ ''', | |
r''' / | | \ --' '-- | | ''', | |
r''' / / \ \ | --.__| | | ''', | |
r''' / / \ \ |__ | | | ''', | |
r'''/ / \ \ | `-- | | | ''', | |
r'''|____/ \____| ---___--- |___| ''', | |
))) | |
return r | |
def transform(text): | |
mapper = build() | |
segs = [[] for _ in range(FIXED_HEIGHT)] | |
for ch in text.upper(): | |
if ch not in mapper: | |
continue | |
for i in range(FIXED_HEIGHT): | |
segs[i].append(mapper[ch][i]) | |
return '\n'.join([' '.join(segs[i]) for i in range(FIXED_HEIGHT)]) | |
def usage(): | |
print 'Argument:' | |
print ' -json : output character mapping in JSON' | |
print ' -trans TEXT : transform a string (ignores non-ASCII)' | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
usage() | |
sys.exit(1) | |
if sys.argv[1] == '-json': | |
print json.dumps(build()) | |
elif sys.argv[1] == '-trans': | |
print transform(sys.argv[2]) | |
else: | |
usage() | |
sys.exit(2) | |
# % python tukasans.py -trans "Tom & Jerry" | |
# _________ _______ _________ ____ _______ _________ ________ ________ ____ ____ | |
# | | / \ | | / \ | | | | | \ | \ | | | | |
# |_ _| | | | | | () | _ | | | --| | - | | - | | | | |
# | | | O | | | ) // | _/ | | | | / | / \ / | |
# | | | | | | | | | (\ V / | | | --| | _ \ | _ \ | | | |
# |___| \_______/ |__|__|_| \___.__\ |_______/ |_______| |__| \__| |__| \__| |___| |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment