This commit is contained in:
Miloslav Ciz 2024-03-04 23:14:06 +01:00
parent fa1f0b9cbd
commit d44127c798
13 changed files with 2124 additions and 1701 deletions

View file

@ -2,7 +2,7 @@
ASCII art is the [art](art.md) of (mostly manually) creating graphics and images only out of [fixed-width](fixed_width.md) (monospace) [ASCII](ascii.md) characters. Strictly speaking this means no [Unicode](unicode.md) or extended ASCII characters are allowed -- these would rather be called Unicode art, [ANSI art](ansi_art.md) etc., though the term ASCII art is quite often used loosely for any art of this kind. If we keep being pedantic, ASCII art might also be seen as separate from mere [ASCII rendering](ascii_rendering.md), i.e. automatically rendering a bitmap image with ASCII characters in place of [pixels](pixel.md), and ASCII graphics that utilizes the same techniques as ASCII art but can't really be called art (e.g. computer generated diagrams); though in practice this distinction is also rarely made. Pure ASCII art is [plain text](plain_text.md), i.e. it can't make use of [color](color.md), text decoration and other [rich text](rich_text.md) formatting.
This kind of art used to be a great part of the [culture](culture.md) of earliest [Internet](internet.md) communities for a number of reasons imposed largely by the limitations of old computers -- it could be created easily with a text editor and saved in pure text format, it didn't take much space to store or send over a network and it could be displayed on text-only displays and terminals. The principle itself predates computers, people were already making this kind of images with type writers. Nevertheless the art survives even to present day and lives on in the hacker culture, among [programmers](programming.md), in [Unix](unix.md) communities, on the [Smol Internet](smol_internet.md) etc. ASCII diagram may very well be embedded e.g. in a comment in a source code to explain some spatial concept -- that's pretty [KISS](kiss.md). We, [LRS](lrs.md), highly advocate use of ASCII art whenever it's [good enough](good_enough.md).
This kind of art used to be a great part of the [culture](culture.md) of earliest [Internet](internet.md) and near-Internet (e.g. [BBS](bbs.md)) communities for a number of reasons imposed largely by the limitations of old computers -- it could be created easily with a text editor and saved in pure text format, it didn't take much space to store or send over a network and it could be displayed on text-only displays and [terminals](terminal.md). The idea itself even predates computers, people were already making this kind of images with type writers, e.g. some poets were formatting their poems with typewriters to picture-shapes. Despite the technical limitations of displays having been overpassed, ASCII art survives even to present day and lives on in the [hacker culture](hacking.md), among [programmers](programming.md), in [Unix](unix.md) and "retro" game communities as well as on the [Smol Internet](smol_internet.md), among people who just want to [keep it simple](kiss.md) and so on. ASCII diagram may very well be embedded in a comment on a text-only forum or in source code to explain some spatial concept. We, [LRS](lrs.md), highly advocate use of ASCII art whenever it's [good enough](good_enough.md).
Here is a simple 16-shade ASCII [palette](palette.md) (but watch out, whether it works will depend on your font): `#OVaxsflc/!;,.- `. Another one can be e.g.: `WM0KXkxocl;:,'. `.
@ -82,6 +82,100 @@ V
|___|_[H]___|=|=|=|=|=|=|=|=|
```
The following is a raster picture auto-converted to ASCII: { For copyright clarity, it's one of my OGA pictures. ~drummyfish }
```
!.-
clxVl.
c###xl,
,.- -,/ac/l!,
.,,,;;,.;.---!c..;.-
-!;.;,;cl;c##aV#s,....ca//cfs!;;.--,,,;
!;;/s/,,c/slc;,;/#l!as;!f/c;;cVOfOf;---.s#c-
-OOfl,,,,;/,,,!ll.!;!,,!c/!;;!/;cxxO/.;aO##a/,.,!,c;.
!,;,,,,!!,/f/c!a,,,!//c;;;;;;;!cVOV/lf/......------,l/;.---
!.!/!/!/;,//c! ;#s,///;;;;;;!c/a#l;-.----....------.,...,..;,-
;x/;;;cslsac #a!,,;;/,,./casl,---..!cxfs/.,.,!x#xl....-.;,/l,
-;;;;;- s;!V....;;;lca#/.---;f#Vxcf######s;.,..-----,,;ssa.
xxl!,,,.!,//c##l ;/c!.,;....c#/.;ac,.,----.,,,fs;a,
!Os;!!c,scfa##x- ---,,,,/,,..###x#;.,!-!,-.lc/cfx/#f
xOOs##lO##f;;, ,-,,,,,,,;l#V;,!/,,,;.#--l#.;;/!,,#!
- !##,,,,, -ax;,,,,,.,f/...c//!./;-#,-##!,,c! ,l;/-
/#c- -/, ##/;,,,,,;./,,,;lclll/ -.V##.,,,c! !.,/;
/##! -.;,;#/,,,,,;,l,,,,,sl,x### - ,#/,,,,c; c,.,l/.
ls#,,,,l.#f.,,,.ff/;;;;O; ;l/s ---;#;,,;V ./lOcfl!.-
.lf#;,;/!Vl,,,,,xccccs/ ac/,--xf;,,,;# #////f#l,
l/cflc/;.;al/;lclx!, .f//--.;,,,,O f/fcx##l.
;s////l-;f#;,;,-- s//f;,,!,,;/ l#xf.c/!!
,;,//!--;;,,,c !///x.,,,,f- -c/f ./,/
,fl!flll.,!/cc, .ll//f;,,,,/; !;;. ,,;/
lf;!;!O/,;c;l!fc -fllclc/!!,,!l -,;;!- ;;!
////cc;llVcl/f #s/lccx;.!/c/c. .,lc!, !;;
./,,,!c--..,,,! x//cf#fscf/c/f. c,f; ;;!
-f///!!;---,.,!,f .cc!;/!f;;;//sf. .fl! !flls,
- fxl;#/!V/fc/ l! ,!;;;c ;l/lc- ,#Olcs;
- -!,-,l!; x.;a!/cfc ./ff; !.-
```
The are many tools for this, but for educational purposes this one was made using the following custom [C](c.md) program:
```
#include <stdio.h>
const char palette[] = "#OVaxsflc/!;,.- ";
int readNum(void)
{
int r = 0;
while (1)
{
char c = getchar();
if (c > '9' || c < '0')
break;
r = r * 10 + c - '0';
}
return r;
}
void skipAfterNewline(void)
{
while (getchar() != '\n');
}
int main(void)
{
skipAfterNewline(); // skip magic number
skipAfterNewline(); // skip header
int w = readNum(); // read width
int h = readNum(); // read height
skipAfterNewline(); // skip to pixels
for (int j = 0; j < h; ++j) // read rows
{
for (int i = 0; i < w; ++i) // read columns
{
/* The following is a bit cryptic way of reading RGB, averaging it (giving
higher significance to green, for human sight bias) to convert it to
grayscale and then getting it to range 0 to 15 (palette size). */
int v = ((getchar() + getchar() * 2 + getchar()) * 16) / (4 * 256);
putchar(palette[v]);
}
putchar('\n');
}
return 0;
}
```
This program is extremely simple, it just reads an image in [PPM](ppm.md) format on standard input and outputs the image to terminal. Watch out, it won't work for all PPM images -- this one worked with a picture exported from [GIMP](gimp.md) in raw RGB PPM. Also note you have to scale the image down to a very small size AND its aspect ratio has to be highly stretched horizontally (because text characters, i.e. pixels, are much more tall than wide). Also for best results you may want to mess with brightness, contrast, sharpness etc.
## See Also
- [ANSI art](ansi_art.md)