ASCII Art Generator is a lightweight image to ASCII art converter, without reducing image resolution.
The Joker - Batman’s greatest adversary
(Image copyright: http://antagonists.wikia.com/wiki/Joker_(The_Dark_Knight))
And the eternal embodiment of gorgeousness, Scarlett Johanssen
ASCII Art Generator works in three steps:
(i,j), assign a rough shade by:
In the RGB colour model, every pixel in an image is represented by combining red, green and blue colours. The average RGB colour of the pixel is calculated as:
int avgColor = (pixel[i][j].red + pixel[i][j].green +
pixel[i][j].blue) / 3;
Then the brightness of the pixel is determined. A brigher pixel will be less darker and
vice versa. Hence, characters like
/, etc. represent the brightest shades
while characters like
$, etc. represent the darkest ones. The entire ASCII
pixel set this program uses is as shown (ASCII pixels are ordered as per their increasing
'@', '#', '9', '8', '&', '6', '5', '4', '0', '3', '7', '?', 'o', '>', '<', '2', ']', '[', '\\', '/', '1', '!', ';', ':', '+', '*', '~', '-', '\'', '"', '\'', ',', '.', ' '
Now, the higher the value of
avgColor, more the chances that the pixel is bright and
will be represented by a ASCII pixel nearer the end of the ASCII pixel set. So, the brightness is
determined in the next step as:
int brightness = avgColor / (Max. brightness value / Max. brightness value available);
In RBG color model, the maximum brightness possible is
255, i.e., the maximum possible red,
green or blue value. And in our ASCII pixel set, we have
34 pixels. Hence, maximum
brightness value available is
Now the corresponding ASCII pixel for
pixel[i][j] is given by
NOTE : The above code lines just represent how the logic works. In ASCII Art Generator’s
source, the actual code do do this is different.
You can find ASCII Art Generator’s source here.
Build & run:
$ g++ main.cpp -std=c++11 -lsfml-graphics -lsfml-system -o ascii-art-gen && ./ascii-art-gen