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 pyfiglet
pyfiglet
library to generate ASCII text art and termcolor
termcolor
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.
C:\Users\Your Name>pip install pyfiglet
C:\Users\Your Name>pip install termcolor
C:\Users\Your Name>pip install colorama
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
- Create a folder named
ascii-art-generator
ascii-art-generator
. - Open the folder in your favorite code editor or IDE.
- Create a file named
asciiartgenerator.py
asciiartgenerator.py
. - Copy the given code and paste it in your
asciiartgenerator.py
asciiartgenerator.py
file.
Write the Code
- Copy and paste the following code in your
asciiartgenerator.py
asciiartgenerator.py
file.
⚙️ 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
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()
- Save the file.
- Open the terminal in your code editor or IDE and navigate to the folder
ascii-art-generator
ascii-art-generator
.
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!
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
- Import the required modules.
import pyfiglet # pip install pyfiglet
import termcolor # pip install termcolor
import colorama
import os
import pyfiglet # pip install pyfiglet
import termcolor # pip install termcolor
import colorama
import os
- Create the main function that handles ASCII art generation.
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()
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()
- Display available font styles for the user to choose from.
print('''
3-d
3x5
5lineoblique
acrobatic
alligator
# ... more font options
''')
print('''
3-d
3x5
5lineoblique
acrobatic
alligator
# ... more font options
''')
- Generate ASCII art with the selected font and color.
font = input()
asciiart = pyfiglet.figlet_format(text, font=font)
colored_asciiart = termcolor.colored(asciiart, color=color)
print(colored_asciiart)
font = input()
asciiart = pyfiglet.figlet_format(text, font=font)
colored_asciiart = termcolor.colored(asciiart, color=color)
print(colored_asciiart)
- Optional file saving functionality.
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!")
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 pyfiglet
pyfiglet
for text-to-ASCII conversion and termcolor
termcolor
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