ASCII Art in Python Programming Language

ASCII Art FeaImg

In this tutorial, we’re going to create ASCII Art using the pyfiglet library that will make displaying the art on the screen much easier and more interesting! ASCII Art implies showing a word or a sentence using some patterns or special symbols to specially make the text more creative and enhance the overall look of the text.

As I mentioned, in order to create ASCII Art we require a python module pyfiglet using the pip command in command prompt.

pip install pyfiglet

We will start by importing the module and then take the input of the text from the user using the input function. Then we will make use of the figlet_format function which will take the text as a parameter. We will print the ASCII art in the end.

import pyfiglet
T = input("Enter Text you want to convert to ASCII art : ")
ASCII_art_1 = pyfiglet.figlet_format(T)
print(ASCII_art_1)

Let’s look at a sample output after the execution of the code.

ASCII Art Output 1
ASCII Art Output 1

We can change the font style as well. All we need to do is add a new parameter to the main function of the pyfiglet library known as font.

import pyfiglet
T = input("Enter Text you want to convert to ASCII art : ")
ASCII_art_1 = pyfiglet.figlet_format(T,font='digital')
print(ASCII_art_1)

After the execution of code, look at the magic of how the text changes just by playing around with the font attribute.

ASCII Art Output 2
ASCII Art Output 2

If you wish to use alphabets instead of symbol lines, you can easily achieve that by changing the font attribute to alphabet. Look at the code mentioned below.

import pyfiglet
T = input("Enter Text you want to convert to ASCII art : ")
ASCII_art_1 = pyfiglet.figlet_format(T,font='alphabet')
print(ASCII_art_1)

Look at a sample output below.

ASCII Art Output 3
ASCII Art Output 3

Everyone loves 3D visualizations of things. Lucky for you, ASCII arts can also be displayed in 3D form by changing the font style again,

import pyfiglet
T = input("Enter Text you want to convert to ASCII art : ")
ASCII_art_1 = pyfiglet.figlet_format(T,font='isometric1')
print(ASCII_art_1)
ASCII Art Output 4
ASCII Art Output 4

Conclusion

Congratulations! You can use ASCII art in your projects on the daily basis to make sure your projects stand out from the rest of the projects. You can play around with the font style and explore more display options.

Thank you for reading! Happy coding! 😁