_____ _____ _____ _____ _____ _______
/\ / ____| / ____| |_ _| |_ _| /\ | __ \ |__ __|
/ \ | (___ | | | | | | / \ | |__) | | |
/ /\ \ \___ \ | | | | | | / /\ \ | _ / | |
/ ____ \ ____) | | |____ _| |_ _| |_ / ____ \ | | \ \ | |
/_/ \_\ |_____/ \_____| |_____| |_____| /_/ \_\ |_| \_\ |_|
As a part of a console utilities module that I'm building, the central function (after which the module is named) is a function that generates ASCII art representation of given text.
Any comments or suggestions for improvement will be great!
default_conf = open('C://Programs//Python35//Lib//asciiart.txt').read()
...
def asciiart (text, conf=default_conf):
"""Produces an ascii art representation of text using the conf data"""
if isinstance(conf, str): conf = conf.split('\n')
height, key, data = int(conf[0]), conf[1], conf[2:]
figures = dict(map(lambda x: (x, data[key.index(x) * height : key.index(x) * height + height]), key))
art = '\n'.join(['\n'.join([' '.join([figures[x][i] for x in t.lower() if x in figures]) for i in range(height)]) for t in text.split('\n')])
return art
Here is a demo:
>>> import asciiart
>>> print(asciiart.asciiart('code-review'))
_____ ____ _____ ______ _____ ______ __ __ _____ ______ __ __
/ ____| / __ \ | __ \ | ____| | __ \ | ____| \ \ / / |_ _| | ____| \ \ / /
| | | | | | | | | | | |__ ____ | |__) | | |__ \ \ / / | | | |__ \ \ /\ / /
| | | | | | | | | | | __| |____| | _ / | __| \ \/ / | | | __| \ \/ \/ /
| |____ | |__| | | |__| | | |____ | | \ \ | |____ \ / _| |_ | |____ \ /\ /
\_____| \____/ |_____/ |______| |_| \_\ |______| \/ |_____| |______| \/ \/
The configuration file format is as follows:
First line: the
height
of every character in the configuration file (number of lines).Second line: the
key
. A string containing the letters in the order they appear in the configuration file.Next
height * len(key)
lines: the text representation of the characters.
The full configuration file can be found here (covers most of the printable ASCII characters).