To convert the color pair or attribute into color values that your program can use, you’ll need to use a bit mask to specify only the bits used for the text color or background color. The leftover bit in the byte is not used here, so we can ignore it. That’s four bits for the text color (0 to 15 or 0 to F in hexadecimal) and three bits for the background color (0 to 7 or 0 to E in hexadecimal). With color pairs, you can encode both the background and foreground colors in a single byte of eight bits. So the value F in hexadecimal is the number 15, or 1111 in binary. Counting sixteen values (from 0 to 15) in binary requires only four bits:Īnd conveniently, hexadecimal can represent 0 to 15 with a single character: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. That’s sixteen possible text colors and eight background colors. Hexadecimal turns out to be a compact way to express a color “pair” like this.Ĭharacter mode systems like ncurses on Linux or conio on DOS can display only sixteen colors. The color attribute in this ASCII art file defines both the background and foreground color in a single byte, represented by hexadecimal values like 0x08 or 0圆E.
To display this ASCII art to the screen, you need to write a small program to read the array and print each character with the right colors. For an 80x25 screen, where each character is paired with an attribute, the array contains 4000 entries (that’s 80 * 25 * 2 = 4000). Each character in the ASCII art screen can be represented by two bytes of data: The character to display and a color attribute containing both the foreground and background colors for the character. In this case, it’s an 80x25 ASCII art “image.” IMAGEDATA_LENGTH defines the number of entries in the IMAGEDATA array.
#COLORED ASCII ART CODE#
Note that the code snippet defines a few values: IMAGEDATA_WIDTH and IMAGEDATA_DEPTH define the number of columns and rows on the screen. Here’s part of a sample ASCII art file, saved as C source code. It doesn’t matter what tool you use as long as you know what the saved data looks like. For this example, I used an old DOS application called TheDraw, but you can find modern open source ASCII art programs on Linux, such as Moebius (Apache license) or PabloDraw (MIT license). You can use a variety of tools to draw your ASCII art.
#COLORED ASCII ART FREE#
Free online course: RHEL Technical Overview.