This project is a simple Go program that converts normal text into ASCII art.
ASCII art means drawing letters using symbols like o, |, -, /, etc.
Instead of printing plain text, the program prints a larger artistic version of the text using patterns stored in a file called standard.txt.
Example:
Input:
go run . "Hi"
Output (example):
Each character is built from multiple lines of symbols.
Your project folder contains the following files:
ascii-art/
│
├── main.go → Runs the program and handles user input
├── ascii.go → Contains the AsciiArt function
├── standard.txt → Contains the ASCII art patterns for characters
└── README.md → Project documentation
The program follows these steps:
- The user enters a word or sentence in the terminal.
- The program reads a file called
standard.txt. - This file contains ASCII drawings for every character.
- The program finds the drawing for each letter in the input.
- It combines the drawings and prints them in the terminal.
The file standard.txt contains drawings for characters.
Each character is made of 8 lines of ASCII art, followed by one empty line.
So each character block uses 9 lines.
Example structure:
line 1 of character
line 2 of character
line 3 of character
line 4 of character
line 5 of character
line 6 of character
line 7 of character
line 8 of character
Characters are stored in ASCII order, starting from ASCII character 32 (space).
The program uses these Go packages:
os
strings
log
fmt
These packages help the program:
- read files
- work with strings
- print messages
- handle errors
func AsciiArt(s string) string
This function takes a normal string and converts it into ASCII art.
content, err := os.ReadFile("standard.txt")
This loads the ASCII art patterns from the file.
If the file cannot be read, the program stops and prints an error.
arts := strings.Split(string(content), "\n")
The file content is split into individual lines and stored in a slice.
s = strings.ReplaceAll(s, "\\n", "\n")
This allows users to type \n to create a new line.
Example:
Input:
Hello\nWorld
Output:
Hello
World
words := strings.Split(s, "\n")
If the user entered multiple lines, each line will be processed separately.
result := strings.Builder{}
strings.Builder helps efficiently build the final ASCII art string.
for _, word := range words
Each word or line is converted into ASCII art.
If a line is empty, the program simply prints a blank line.
Each character drawing has 8 rows, so the program prints them one row at a time.
for row := 1; row <= 8; row++
for _, ch := range word
The program looks at each character in the word.
Example:
Hello
Characters processed:
H
e
l
l
o
ascii := int(ch)
index := ascii - 32
start := index * 9
Explanation:
- Every character has an ASCII number.
- The ASCII art file starts at character 32 (space).
- Each character uses 9 lines in the file.
This calculation tells the program where the drawing for that character starts.
result.WriteString(arts[start+row])
This adds the correct ASCII art line for the character.
result.WriteByte('\n')
After printing one row for all characters, the program moves to the next line.
return result.String()
The complete ASCII art is returned as a string.
The main function is the entry point of the program.
It handles the input from the terminal.
Example:
go run . "Hello"
if len(os.Args) != 2
The program expects exactly one argument.
If none is provided, it prints:
No arguments provided!
If the user enters an empty string, the program prints nothing.
If the user enters \n, the program prints a blank line.
fmt.Print(AsciiArt(args))
The input text is converted and displayed.
Go to the project folder and run:
go run . "Hello"
Example:
go run . "Go"
The terminal will display the ASCII art version of the text.
You need:
- Go installed on your system
- The
standard.txtfile in the same folder as the program
Check your Go version: