ASCII Art in Code


In preparation for my next project, a text-based game, I’ve decided to look into the most popular text-based games in history to see what makes them work.

Also known as interactive fiction, or IF for short, text-based games originated due to hardware limitations. Early computers had limited graphics capabilities, and many were just a terminal with a keyboard! But, some enterprising developers still wanted graphics of some kind in their games, despite the hardware limitations. And so, games were made utilizing ASCII art!

What is ASCII art? Emojis are ASCII art! For example, “:)” is a smiley face! But, ASCII art can also be much more complicated, like the below example, The Pearly Gates by Joan G. Stark.

The Pearly Gates ASCII art by Joan G. Stark, via www.asciiart.eu/religion/other

ASCII art is just art made from the standard 128 ASCII (American Standard Code for Information Interchange) symbols. Dating back to 1867, even typewriters were used to create art! The ASCII art above is composed of slashes, asterisks, parenthesis, letters, quotation marks, tildes, colons, and several other signs. It is simple, but it gets the idea across very well.

By utilizing ASCII art within a terminal software, text-based games were able to add graphics to their gameplay, providing another layer of immersion to the story telling. So, how is ASCII art made?

(\_/)
(=’ . ‘=)
(“)___(“)3

Like the above figure, you can just type into any word processor! Experiment with a variety of letters and symbols to find different shapes. But, to add these artworks to a code, you’ll need to think a bit more. Break up the artwork based on lines. Here’s an example of how to implement the bunny above in python

println("    (\_/)")
println("(=\' . \'=)")
println("(\")___(\")3"

See the slash before the quotation marks in the bunny’s feet? Those are escape lines, which are necessary so that python doesn’t recognize just the ( as a string to be printed, which would cause an error when the following (_) symbols would be outside of quotation marks. The same goes for the single quotes, which are the bunny’s eyes.

Thus, ASCII art is an interesting challenge to add to a program, and can help boost the feel and environment significantly. So play around with some graph paper, a spreadsheet, or python and a command line and see how ASCII art concepts can improve your own projects!

Sources:
www.asciiart.eu
https://en.wikipedia.org/wiki/ASCII_art

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *