Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text-to-ASCII art generator in Python

I would like to add an easter egg to one our developers' command line tools, which will greet its user if a certain date is matched. Basically, I'm looking for:

>>> print big_text("Happy\nBirthday")                                                                                   

   .                   _________   _...._    _________   _...._                    
 .'|                   \        |.'      '-. \        |.'      '-. .-.          .- 
<  |                    \        .'```'.    '.\        .'```'.    '.\ \        / / 
 | |             __      \      |       \     \\      |       \     \\ \      / /  
 | | .'''-.   .:--.'.     |     |        |    | |     |        |    | \ \    / /   
 | |/.'''. \ / |   \ |    |      \      /    .  |      \      /    .   \ \  / /    
 |  /    | | `" __ | |    |     |\`'-.-'   .'   |     |\`'-.-'   .'     \ `  /     
 | |     | |  .'.''| |    |     | '-....-'`     |     | '-....-'`        \  /      
 | |     | | / /   | |_  .'     '.             .'     '.                 / /       
 | '.    | '.\ \._,\ '/'-----------'         '-----------'           |`-' /        
 '---'   '---'`--'  `"                    _______                     '..'         
/|        .--.                   .        \  ___ `'.                               
||        |__|                 .'|         ' |--.\  \          .-.          .-     
||        .--..-,.--.      .| <  |         | |    \  '          \ \        / /     
||  __    |  ||  .-. |   .' |_ | |         | |     |  '    __    \ \      / /      
||/'__ '. |  || |  | | .'     || | .'''-.  | |     |  | .:--.'.   \ \    / /       
|:/`  '. '|  || |  | |'--.  .-'| |/.'''. \ | |     ' .'/ |   \ |   \ \  / /        
||     | ||  || |  '-    |  |  |  /    | | | |___.' /' `" __ | |    \ `  /         
||\    / '|__|| |        |  |  | |     | |/_______.'/   .'.''| |     \  /          
|/\'..' /     | |        |  '.'| |     | |\_______|/   / /   | |_    / /           
'  `'-'`      |_|        |   / | '.    | '.            \ \._,\ '/|`-' /            
                         `'-'  '---'   '---'            `--'  `"  '..'             

Is there a package for that?

Credit where credit is due.

like image 953
Adam Matan Avatar asked Jul 08 '12 13:07

Adam Matan


2 Answers

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.

like image 75
patorjk Avatar answered Oct 15 '22 04:10

patorjk


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 ""
like image 25
zenpoy Avatar answered Oct 15 '22 05:10

zenpoy