Text-to-ASCII art generator in Python

旧时模样 提交于 2019-12-04 04:08:41

Author of the TAAG app you linked here. Most of the fonts in TAAG are FIGlet fonts (figlet.org). FIGlet is a command line linux app, but FIGlet drivers have been written in several languages. I released the driver I wrote in JavaScript here:

https://github.com/patorjk/figlet.js

Though that would need to be ported to Python to work. I did a search for FIGlet Python libraries and found this:

https://github.com/pwaller/pyfiglet

I'm not sure how well it works, or how much of the spec it implements, but it looks pretty complete.

Here is a code snippet from ActiveState of a Python Banner example. http://code.activestate.com/recipes/577537-banner/

zenpoy

I think this question is a bit off topic for Stack Overflow, but you can try to google "ASCII art Python" and get things like: http://www.youtube.com/watch?v=NEWuZfTNoJE

OR you can try to do it yourself, here's an outline:

rows = 13 # Maximum height of character

# 0 is a , 1 is b and so on...
alphabeth = [[
r'''           ''',
r'''           ''',
r'''           ''',
r'''           ''',
r'''           ''',
r'''    __     ''',
r''' .:--.'.   ''',
r'''/ |   \ |  ''',
r'''`" __ | |  ''',
r''' .'.''| |  ''',
r'''/ /   | |_ ''',
r'''\ \._,\ '/ ''',
r''' `--'  `"  ''']]

text = raw_input('Enter text:\n')
c = map(lambda x: ord(x)-ord('a'),text)
for i in range(rows):
    for j in c:
        print alphabeth[j][i],
    print ""

As mentioned before you can use pyFiglet for creating ascii text in python.

For example:

import pyfiglet

result = pyfiglet.figlet_format("happy birthDay", font = "crazy")
print(result)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!