Skip to content

Latest commit

 

History

History
109 lines (95 loc) · 5.69 KB

README.md

File metadata and controls

109 lines (95 loc) · 5.69 KB

ascii-art-generator

ASCIIArt Generator class generate ascii-art for input image.

Only supported on mono-type fonts because the font padding calculation isn't yet implemented.

[written in c++, microsoft visualstudio 2019 Community Edition.]

used stb lib for reading, writing, resizing image and reading font files.

Example image used is taken from unsplash.com submitted by Chris Lee.

ascii-art example :

#include "image.h"
#include "fontrender.h"
#include "pixelbrightness.h"
#include "asciiart.h"

int main()
{
	/*
	uses default font:
	"./fonts/RobotoMono-Regular.ttf
	currently only support mono fonts.
	*/
	FontRender robotoDefault;

	Image plant("../out/photo_1.jpg");
	plant.resizeWrtWidth(80);

	ASCIIArt art(&plant, &robotoDefault);
	art.outputPath = "../out/art.txt";
	art.generateArt();
}

input

output

with image width 80

_":~;^!~"""__-,,,''-":""__;S/~~=|1a/gQQQQQQQQQQWA',-5S=E]!]a+_`nP,!(F+<||=;!~;^;
_-_"":::"""_-_-,',,''-:~::|C|^r/=:(MWQQQQQQQQQQQ@u-,;#yF=|?j+_``;:=9{?SOh|!;;^;!
"-------------~Tx-,,,',_:;;r<]v;^=oQQQQQQQQQQQQQWp:|-<q):=?j+_``_;>i?kQWQp[^;;;!
^_----------_tGQO"--,,'``-:;<}1~6>|MWQQQQQQQQQQQWS:df>w/_\sJ/_''''T0SHSWWW&SP+=;
3:"_-__----=5&Q&s----,''```'_!_1h?[0WQQQQQQQQQQQQ&/"[oj^"7za1-'```!4Ss1KS0$WW&8A
0L;=_---"1qMQQMs----,'''`'''..'"*l9B@QQQQQQQQQQQQWN+~Y[<y#s{>'````'~;"_"~^/u{L(+
$@R2|![V8&Q&Gd|,,--,'<x''',````--!r)o@QQQQQQQQQQQQW$D7|]a[z}|,```-_,:||~"_-----,
$$$&hrEDd36?^_----,'^NS,','````"",`'!SWQQQQQQQQQQQQ$Xn~,';ai=''``2G3r:;><;:"_---
$$$$Or~:::::"_---,'~S$s`''``.'`"|--'`=0WQQQQQQQQQQWN2r-``^Ti^``,`r$W$#c;;==^!:::
$$$$&J:::::""_-,,'_RQ#-','"n`'`,v!-_,'6WQQQQQQQQQQQR)!,''!}z;,'`,'wQWWQSZ/^!~!;^
$$$$8!~:""__--,,,,Z$0|`',`7A`,`_]?___'1$QQQQQQQQQW0P1_v^'~)c~]d,',-kQWWWW&8P*^=>
$$$0*-!n~"_"_--,,o&&s'''',b[`,`tyc>-"-=&QQQQQQQQQQpt!"X:`~]r~=&4,,--i0WWWWWW&G#d
$$$%~~"KRv;::_,-7&&7''''`|G:`,`aM++!--|&QQQQQQQQQ@Hr-]C,`/+=!,4QE',-'!Jb&WWWWWWW
$$&u":"+8gE|;:~q$$Y''''``C8'`'`n$}<|_->$QQQQQQQQQ8)=-XL'`//=^-"BQ{',-'`-|ZB&QWWW
$$N>:__"j?|!::;Jqi-''''``**'```1QX!!",r$QQQQQQQQ&Ur3c8=`.1P<!~`|0Qx,-_,'''_=)UbM
$$4::"-,;?;"_-,,-''''''```''```^0M=::-+$QQQQQQQQB)]@O#-`.^3r~;,`/@$Y_--,''''''-~
$N|_""_-,=="-,,,,''''''``'''```,)&n"~:kQQQQQQQQ&CrDWWU```_u*/!"`'1MQy~',,''',,,,
$f___":-,-;"----,'''''``'``'```',2H~~|OQQQQQQQQO)c&WWB_``'<ny|:,''^#QG*,'''',,,-
G;____":_,-::=",'''''''`'``'`````,/|=3$QQQQQQQ$drRWWWW5,`'|u0a"-'''-s0$K^,'',,'-
A:"_"__":"-_";:,'''''''''`````````,|E@QQQQQQQQB))&WWWWQD;->I$b:,''''';6GGl~,',>5
I::"""_-___,_":_,''''''''``````````"gQQQQQQQQ&U*pWQWWWWW0Xc2Q$x:-'''',_1R$Ohwp&W
j^""""______,-__-,,,,,,''``'``````',>0QQQQQQQSxg$QQQWWWWW$LqQW$MbqJtaqp0QWWWWWWQ
e=___"_--___-,-___;/<_,`'``''`````',!N$$$$$Q&mU$QQQQQQWWW&n5WWWWWWWWWWWWWWWWWQQQ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