Skip to content

ASCII Art Generator

Abstract

ASCII Art Generator is a fun Python program that converts text into ASCII art using various fonts and colors. The program uses the pyfigletpyfiglet library to generate ASCII text art and termcolortermcolor to add colors. Users can choose from multiple font styles, customize colors, and save their ASCII art to a file. This is a great project for beginners to learn about external libraries and file handling in Python.

Prerequisites

  • Python 3.6 or above
  • A code editor or IDE
  • pyfiglet module
  • termcolor module
  • colorama module

Before you Start

Before starting this project, you must have Python installed on your computer. If you don’t have Python installed, you can download it from here. You must have a code editor or IDE installed on your computer. If you don’t have any code editor or IDE installed, you can download Visual Studio Code from here. You must have the required modules installed on your computer. If you don’t have these modules installed, you can install them by using the following commands in your terminal.

command
C:\Users\Your Name>pip install pyfiglet
C:\Users\Your Name>pip install termcolor
C:\Users\Your Name>pip install colorama
command
C:\Users\Your Name>pip install pyfiglet
C:\Users\Your Name>pip install termcolor
C:\Users\Your Name>pip install colorama

Getting Started

Create a Project

  1. Create a folder named ascii-art-generatorascii-art-generator.
  2. Open the folder in your favorite code editor or IDE.
  3. Create a file named asciiartgenerator.pyasciiartgenerator.py.
  4. Copy the given code and paste it in your asciiartgenerator.pyasciiartgenerator.py file.

Write the Code

  1. Copy and paste the following code in your asciiartgenerator.pyasciiartgenerator.py file.
⚙️ ASCII Art Generator
ASCII Art Generator
# ASCII Art Generator
 
import pyfiglet # pip install pyfiglet
import termcolor # pip install termcolor
import colorama
import os
 
def asciiartgenerator():
    print("ASCII Art Generator")
    print("Enter the text to convert to ASCII Art: ")
    text = input()
    print("Enter the color of the text: ")
    color = input()
    print('''
    3-d	
3x5	
5lineoblique
acrobatic
alligator
alligator2
alphabet
avatar
banner
banner3-D
banner3
banner4
barbwire
basic
bell
big
bigchief
binary
block
bubble
bulbhead
calgphy2
caligraphy
catwalk
chunky
coinstak
colossal
computer
contessa	
contrast
cosmic
cosmike
cricket
cursive
cyberlarge
cybermedium
cybersmall
diamond
digital
doh
doom
dotmatrix
drpepper
eftichess
eftifont
eftipiti
eftirobot
eftitalic
eftiwall
eftiwater
epic
fender
fourtops
fuzzy
goofy	
gothic
graffiti
hollywood
invita
isometric1
isometric2
isometric3
isometric4
italic
ivrit	
jazmine	
jerusalem
katakana
kban
larry3d
lcd
lean
letters
linux
lockergnome	
madrid
marquee
maxfour
mike
mini
mirror
mnemonic	
morse
moscow
nancyj-fancy
nancyj-underlined	
nancyj	
nipples
ntgreek
o8	
ogre
pawp
peaks
pebbles
pepper
poison
puffy
pyramid
rectangles
relief
relief2
rev	
roman
rot13
rounded
rowancap
rozzo
runic
runyc
sblood
script
serifcap	
shadow
short
slant
slide
slscript
small
smisome1
smkeyboard
smscript
smshadow
smslant
smtengwar
speed
stampatello
standard
starwars
stellar
stop
straight	
tanja	
tengwar
term
thick
thin
threepoint
ticks
ticksslant
tinker-toy
tombstone
trek
tsalagi
twopoint
univers
usaflag
wavy
weird
    ''')
    print("Enter the font style: ")
    font = input()
    asciiart = pyfiglet.figlet_format(text, font=font)
    colored_asciiart = termcolor.colored(asciiart, color=color)
    print(colored_asciiart)
    print("Do you want to save the ASCII Art? (y/n)")
    save = input()
    if save == 'y':
        print("Enter the name of the file: ")
        filename = input()
        with open(filename, 'w') as f:
            f.write(colored_asciiart)
        print("File saved successfully!")
    else:
        print("File not saved!")
    print("Do you want to clear the screen? (y/n)")
    clear = input()
    if clear == 'y':
        os.system('cls')
    else:
        print("Thank you for using ASCII Art Generator!")
        
if __name__ == "__main__":
    asciiartgenerator()
     
ASCII Art Generator
# ASCII Art Generator
 
import pyfiglet # pip install pyfiglet
import termcolor # pip install termcolor
import colorama
import os
 
def asciiartgenerator():
    print("ASCII Art Generator")
    print("Enter the text to convert to ASCII Art: ")
    text = input()
    print("Enter the color of the text: ")
    color = input()
    print('''
    3-d	
3x5	
5lineoblique
acrobatic
alligator
alligator2
alphabet
avatar
banner
banner3-D
banner3
banner4
barbwire
basic
bell
big
bigchief
binary
block
bubble
bulbhead
calgphy2
caligraphy
catwalk
chunky
coinstak
colossal
computer
contessa	
contrast
cosmic
cosmike
cricket
cursive
cyberlarge
cybermedium
cybersmall
diamond
digital
doh
doom
dotmatrix
drpepper
eftichess
eftifont
eftipiti
eftirobot
eftitalic
eftiwall
eftiwater
epic
fender
fourtops
fuzzy
goofy	
gothic
graffiti
hollywood
invita
isometric1
isometric2
isometric3
isometric4
italic
ivrit	
jazmine	
jerusalem
katakana
kban
larry3d
lcd
lean
letters
linux
lockergnome	
madrid
marquee
maxfour
mike
mini
mirror
mnemonic	
morse
moscow
nancyj-fancy
nancyj-underlined	
nancyj	
nipples
ntgreek
o8	
ogre
pawp
peaks
pebbles
pepper
poison
puffy
pyramid
rectangles
relief
relief2
rev	
roman
rot13
rounded
rowancap
rozzo
runic
runyc
sblood
script
serifcap	
shadow
short
slant
slide
slscript
small
smisome1
smkeyboard
smscript
smshadow
smslant
smtengwar
speed
stampatello
standard
starwars
stellar
stop
straight	
tanja	
tengwar
term
thick
thin
threepoint
ticks
ticksslant
tinker-toy
tombstone
trek
tsalagi
twopoint
univers
usaflag
wavy
weird
    ''')
    print("Enter the font style: ")
    font = input()
    asciiart = pyfiglet.figlet_format(text, font=font)
    colored_asciiart = termcolor.colored(asciiart, color=color)
    print(colored_asciiart)
    print("Do you want to save the ASCII Art? (y/n)")
    save = input()
    if save == 'y':
        print("Enter the name of the file: ")
        filename = input()
        with open(filename, 'w') as f:
            f.write(colored_asciiart)
        print("File saved successfully!")
    else:
        print("File not saved!")
    print("Do you want to clear the screen? (y/n)")
    clear = input()
    if clear == 'y':
        os.system('cls')
    else:
        print("Thank you for using ASCII Art Generator!")
        
if __name__ == "__main__":
    asciiartgenerator()
     
  1. Save the file.
  2. Open the terminal in your code editor or IDE and navigate to the folder ascii-art-generatorascii-art-generator.
command
C:\Users\Your Name\ascii-art-generator> python asciiartgenerator.py
ASCII Art Generator
Enter the text to convert to ASCII Art: 
Hello
Enter the color of the text: 
red
Enter the font style: 
big
 
 _   _          _   _       
| | | |   ___  | | | |  ___ 
| |_| |  / _ \ | | | | / _ \
|  _  | |  __/ | | | || (_) |
|_| |_|  \___| |_| |_| \___/ 
 
Do you want to save the ASCII Art? (y/n)
y
Enter the name of the file: 
hello.txt
File saved successfully!
Do you want to clear the screen? (y/n)
n
Thank you for using ASCII Art Generator!
command
C:\Users\Your Name\ascii-art-generator> python asciiartgenerator.py
ASCII Art Generator
Enter the text to convert to ASCII Art: 
Hello
Enter the color of the text: 
red
Enter the font style: 
big
 
 _   _          _   _       
| | | |   ___  | | | |  ___ 
| |_| |  / _ \ | | | | / _ \
|  _  | |  __/ | | | || (_) |
|_| |_|  \___| |_| |_| \___/ 
 
Do you want to save the ASCII Art? (y/n)
y
Enter the name of the file: 
hello.txt
File saved successfully!
Do you want to clear the screen? (y/n)
n
Thank you for using ASCII Art Generator!

Explanation

  1. Import the required modules.
asciiartgenerator.py
import pyfiglet # pip install pyfiglet
import termcolor # pip install termcolor
import colorama
import os
asciiartgenerator.py
import pyfiglet # pip install pyfiglet
import termcolor # pip install termcolor
import colorama
import os
  1. Create the main function that handles ASCII art generation.
asciiartgenerator.py
def asciiartgenerator():
    print("ASCII Art Generator")
    print("Enter the text to convert to ASCII Art: ")
    text = input()
    print("Enter the color of the text: ")
    color = input()
asciiartgenerator.py
def asciiartgenerator():
    print("ASCII Art Generator")
    print("Enter the text to convert to ASCII Art: ")
    text = input()
    print("Enter the color of the text: ")
    color = input()
  1. Display available font styles for the user to choose from.
asciiartgenerator.py
print('''
3-d	
3x5	
5lineoblique
acrobatic
alligator
# ... more font options
''')
asciiartgenerator.py
print('''
3-d	
3x5	
5lineoblique
acrobatic
alligator
# ... more font options
''')
  1. Generate ASCII art with the selected font and color.
asciiartgenerator.py
font = input()
asciiart = pyfiglet.figlet_format(text, font=font)
colored_asciiart = termcolor.colored(asciiart, color=color)
print(colored_asciiart)
asciiartgenerator.py
font = input()
asciiart = pyfiglet.figlet_format(text, font=font)
colored_asciiart = termcolor.colored(asciiart, color=color)
print(colored_asciiart)
  1. Optional file saving functionality.
asciiartgenerator.py
print("Do you want to save the ASCII Art? (y/n)")
save = input()
if save == 'y':
    print("Enter the name of the file: ")
    filename = input()
    with open(filename, 'w') as f:
        f.write(colored_asciiart)
    print("File saved successfully!")
asciiartgenerator.py
print("Do you want to save the ASCII Art? (y/n)")
save = input()
if save == 'y':
    print("Enter the name of the file: ")
    filename = input()
    with open(filename, 'w') as f:
        f.write(colored_asciiart)
    print("File saved successfully!")

Features

  • Convert text to ASCII art using various fonts
  • Add colors to your ASCII art
  • Choose from 50+ different font styles
  • Save ASCII art to a file
  • User-friendly command-line interface
  • Option to clear screen after generation

Next Steps

You can enhance this project by:

  • Adding a GUI interface using Tkinter
  • Creating a web version using Flask
  • Adding more color options and effects
  • Implementing font preview functionality
  • Adding support for multi-line text input
  • Creating preset font and color combinations

Conclusion

In this project, we learned how to create an ASCII Art Generator using Python. We used external libraries like pyfigletpyfiglet for text-to-ASCII conversion and termcolortermcolor for adding colors. This project demonstrates file handling, user input processing, and working with external libraries. To find more projects like this, you can visit Python Central Hub.

Was this page helpful?

Let us know how we did