How do I write a code of ASCII text where I do not need to import like pyfiglet but do it manually and use whatever character of my choice in python

Viewed 13

How do I write a code of ASCII text where I do not need to import like pyfiglet but do it manually and use whatever character of my choice in python

What I want my output to be:

Hello world

+     + +----  -------
|     | |---|     |
|-----| |      -------

For example/reference: enter image description here

1 Answers

You can design the letters by hand with any character you wish (probably draw them on grid paper first), store them in a dictionary and write a function that composes each line of the output from the corresponding lines of the characters. It's quite some work to design a whole ASCII font by hand, but the function is quite simple:

def asciiart(letters,word=""):
    art = ""
    for line in range(letters["Size"]):
        for c in word:
            art+=letters[c].split('\n')[line]+" "
        art+="\n"
    return art
            
    

letters = {"Size":5,
           " ": "     \n     \n     \n     \n     ",
           "A": " ### \n#   #\n#####\n#   #\n#   #",
           "C": " ####\n#    \n#    \n#    \n ####"}

print(letters["A"],"\n")
print(letters["C"],"\n")
print(asciiart(letters,"AC CA AA"))

The output of this program would be:

 ### 
#   #
#####
#   #
#   # 

 ####
#    
#    
#    
 #### 

 ###   ####        ####  ###         ###   ###  
#   # #           #     #   #       #   # #   # 
##### #           #     #####       ##### ##### 
#   # #           #     #   #       #   # #   # 
#   #  ####        #### #   #       #   # #   # 
Related