I want to make a program, where the user enters their name and the program generates an ASCII picture of their name. Is it possible to do that without using 3rd party tools? What I came up with was to create each letter in the alphabet manually and then convert the string into a char array. Then return each image that corresponds with the letter. Is there a better or more efficent way of doing this?
You can write text to a bitmap in any font you want and scan the bitmap to produce the ASCII art. You can even use anti-aliasing for effect. ;)
The last time I did this was about tens years ago. ;)
BufferedImage image = new BufferedImage(144, 32, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setFont(new Font("Dialog", Font.PLAIN, 24));
Graphics2D graphics = (Graphics2D) g;
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
graphics.drawString("Hello World!", 6, 24);
ImageIO.write(image, "png", new File("text.png"));
for (int y = 0; y < 32; y++) {
StringBuilder sb = new StringBuilder();
for (int x = 0; x < 144; x++)
sb.append(image.getRGB(x, y) == -16777216 ? " " : image.getRGB(x, y) == -1 ? "#" : "*");
if (sb.toString().trim().isEmpty()) continue;
System.out.println(sb);
}
writes out an image
and prints
## ## ## ## *#* *##** *#* ## ## ##
## ## ## ## *#* *###* *#* ## ## ##
## ## ## ## *#* *#*#* *#* ## ## ##
## ## ## ## *#* ******* *#* ## ## ##
## ## ******* ## ## ******* *#* *#* *#* *#* ******* ##**** ## ****** ## ##
## ## **#####** ## ## **#####** *#* *#* *#* *#* **#####** ##*##* ## **#####*## ##
## ## **#*****#** ## ## **#** **#** *#* **#* *#* *#* **#** **#** ##**** ## **#** ***## ##
############# *#* *#* ## ## *#* *#* *#* *#* *#* *#* *#* *#* ##* ## *#* *## ##
############# *#* *#* ## ## *#* *#* **** *#* *#* **** *#* *#* ##* ## *#* *## ##
## ## *#########* ## ## *#* *#* *#* *#* *#* *#* *#* *#* ## ## *#* *## ##
## ## *#########* ## ## *# #* *#* *#* *#* *#* *# #* ## ## *# ## ##
## ## *#* ## ## *#* *#* *#* *#* *#* *#* *#* *#* ## ## *#* *## ##
## ## *#* ## ## *#* *#* *****#* *#***** *#* *#* ## ## *#* *## ##
## ## *#* *#* ## ## *#* *#* *#*#* *#*#* *#* *#* ## ## *#* *##
## ## **#** ***** ## ## **#** **#** *#*#* *#*#* **#** **#** ## ## **#** ***##
## ## **######* ## ## **#####** *###* *###* **#####** ## ## **#####*## ##
## ## ******* ## ## ******* *##** **##* ******* ## ## ****** ## ##
change to BOLD
### ### ### ### *##* *###* *##* ### ### #
### ### ### ### *##* *###* *##* ### ### #
### ### ### ### *##* *###* *##* ### ### #
### ### ### ### **##* **###** *##** ### ### #
### ### ******* ### ### ******* *##* *##*##* *##* ******* ###**** ### ****** ### *
### ### **#####** ### ### **#######** *##* *##*##* *##* **#######** ###*##* ### **#####*### *
### ### **#######** ### ### *#########* *##** *#* *#* **#** *#########* #####** ### **########## *
############# *##** **##* ### ### *###** **###* *##* *##* *##* *##* *###** **###* ###** ### *##******### *
############# *##* *##* ### ### *##* *##* *##* *##* *##* *##* *##* *##* ###* ### *##* *### *
############# *#########* ### ### *##* *##* *##* *##* **#* *##* *##* *##* ###* ### *##* *### *
### ### *#########* ### ### ### ##* *##*##* *#**##* ### ##* ###* ### *## ### *
### ### *##* ### ### *##* *##* *##*##* *##*##* *##* *##* ### ### *##* *### *
### ### *##* ### ### *##* *##* *#####* *#####* *##* *##* ### ### *##* *### *
### ### *##*****##* ### ### *###** **###* **###** *###** *###** **###* ### ### *##******###
### ### **########* ### ### *#########* *###* *###* *#########* ### ### **########## #
### ### **######* ### ### **#######** *###* *###* **#######** ### ### **#####*### #
### ### ******* ### ### ******* *###* *###* ******* ### ### *******### #
in ITALIC
*#* *#* *#* *#* *#* *##* **#* *#* *#* *#*
*#* *#* *#* *#* *#* *###* *#* *#* *#* *#*
*#* *#* *#* *#* *#* *###* **#* *#* *#* *#*
*#* *#* *#* *#* *#* *#**#* *#* *#* *#* *#*
**** *#* ******* **** **** ******* *#* *#**#* **** ******* *#* **#* **** ********#* *#*
*#* *#* **######* *#* *#* **######* *#* *#***#* *#* **######* *#**###* *#* **####**#** **
*#* *#* **#******#* *#* *#* **#******#* *#* **#* *#* **** **#******#* *#**** *#* *##** **##* *#*
*############* **#* *#* *#* *#* **#* *#* *#* *#* *#* *#* **#* *#* *#** *#* **#* **#* *#*
**###########** *#* #* **** **** *#* *#* *#* **#* *#* **** *#* *#* **#* **** *#* *#* *#*
*#* *#* *##########* *#* *#* *#* #* *#* *#* *#* *#* *#* #* *#** *#* *#* *#* **
*#* *#* *##########* *#* *#* *#* *#* *#* **** *#* *#** *#* *#* *#* *#* *#* *#* **
*#* *#* *# *#* *#* *# *#* *#* *#* *#* *#* *# *#* *#* *#* *# *** **
*#* *#* *#* *#* *#* *#* **#* *#**#** *#**#** *#* **#* *#* *#* *#* *#* **
*#* *#* *#* **** *#* *#* *#* *#** *#**#* *#**#* *#* *#***#* *#* *#* **#*
*#* *#* *#*******#* *#* *#* *#*** **##* *###** *###** *#*** **##* *#* *#* *#******##*
*#* *#* *######** *#* *#* *######** *###* *###* *######** *#* *#* **#####**#* *#*
*#* *#* ******* *#* *#* ******* ##* *##* ******* *#* *#* ********#* *#*
Change the Font to SERIF BOLD
####### ####### #### #### *######* *######* ####* #### #### ***
*###* *###* *### *### **##** **##** **** *### *### *#*
### ### ### ### *##** **##* ** ### ### *#*
### ### ### ### *##* *##* *** ### ### *#*
### ### ### ### *##* **#** ** ### ### *#*
### ### ****** ### ### ****** **##* ***##* ** ****** #### **** ### *****### *#*
### ### *#***#** ### ### *#****#* *##* ***##* ** *#****#* *###*###* ### *#****### *#*
############# *##* *##* ### ### *##* *##* *##* ****#** ** *##* *##* ###***** ### *##* *### *#*
### ### *## ##* ### ### *##* *##* *##* ** *##* ** *##* *##* ###* ### *##* ### *#*
### ### *#######* ### ### *## ##* *##* ** *##* ** *## ##* ###* ### *## ### *#*
### ### *##* ### ### *## ##* *##*** **##** *## ##* ### ### *## ### *#
### ### *##* ### ### *## ##* *##** *##** *## ##* ### ### *## ###
### ### *##* ** ### ### *##* *##* *##** *###* *##* *##* ### ### *##* ###
### ### *##** *** ### ### *##* *##* **#* *#* *##* *##* ### ### *##* *###* ***
*###* *###* *#####* *###* *###* *#****#* *#* *#* *#****#* *###* *###* **#****#### *#*
####### ####### ****** ##### ##### ****** *** *#* ****** ##### ##### ********** ***
This problem is solved in four steps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With