Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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 ""

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

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)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top