This Go program reads a text input and prints its ASCII art representation using a predefined set of ASCII characters stored in a file named standard.txt
.
- Converts text input to ASCII art
- Supports newline characters (
\n
) - Handles missing characters with an error message
- Go installed on your machine
-
Clone the repository:
git clone https://github.com/Hilary-code/ascii-art.git
-
Navigate to the project directory:
cd ascii-art
Run the program with a text input as a command-line argument:
go run . "Hello, World!" | cat -e
go run . "Hello, World!" | cat -e
-
Input Parsing:
- The program takes a text input from the command-line arguments using
os.Args[1]
. - The input may contain newline characters (
\n
), which are replaced with actual newline characters usingstrings.ReplaceAll
.
- The program takes a text input from the command-line arguments using
-
ASCII Art Mapping:
- The
Banner
function reads a file namedstandard.txt
to load predefined ASCII art characters. - It splits the file content into lines and maps each character to its corresponding ASCII art representation.
- The
-
Text to ASCII Conversion:
- The
PrintAscii
function processes each character in the input text. - For each character, it looks up its ASCII art representation from the map created by the
Banner
function. - The ASCII art lines for each character are collected in a 2D slice (
Output
).
- The
-
Printing ASCII Art:
- Finally, the
Output
slice is printed to the console, displaying the input text as ASCII art.
- Finally, the
For the input text "Hello\nWorld"
, the program will:
- Replace
\n
with actual newline characters. - Split the text into lines:
["Hello", "World"]
. - Look up each character's ASCII art representation from
standard.txt
. - Print the ASCII art representation of each character to the console, maintaining the line structure.
_ _ _ _
| | | | | | | |
| |__| | ___ | | | | ___
| __ | / _ \ | | | | / _ \
| | | | | __/ | | | | | (_) |
|_| |_| \___| |_| |_| \___/
__ __ _ _
\ \ / / | | | |
\ \ /\ / / ___ _ __ | | __| |
\ \/ \/ / / _ \ | '__| | | / _` |
\ /\ / | (_) | | | | | | (_| |
\/ \/ \___/ |_| |_| \__,_|
You can provide a custom banner file to use for printing. The file should contain characters represented as ASCII art with each character separated by newline characters. The program reads 8 lines for each character.
To use a custom banner file, execute the following command:
go run . "Your text" "customBannerFileName"
Replace customBannerFileName with the name of your custom banner file without the ./ and .txt .
main.go
: Main source code filestandard.txt
: File containing ASCII art charactersshadow.txt
: File containing ASCII art charactersthinkertoy.txt
: File containing ASCII art charactersBanner folder
: contains the LoadBanner, PrintBanner, RemoveSpecialcase and filecheck functions
Feel free to contribute to this project. Create a pull request with your changes, or open an issue if you find any bugs or have suggestions.