some more code!

posted in Programmology
Published July 04, 2005
Advertisement
to fulfill all your sexual desires:

another ascii art program. I made this a couple nights ago just for the fun of it. Very crude and the ascii isn't very good due to resolution problems, but it was fun to make

Ascii art!
#include "AXCore.h"#include #include "IL\\il.h"#include "IL\\ilu.h"#define PICTURENAME "TestData\\nad17_2"#define PICTUREEXT ".jpg"/*	Forward Declarations	*/int initialize();void shutdown();void run();/*	System	*/AXLogger* const AXAppLog = new AXLogger;AXSettings* const AXAppSettings = new AXSettings;/* Application */unsigned char *App_ImageData = NULL;unsigned int App_ImageDataSize;int			 App_ImageFormat;unsigned int App_ImageWidth;unsigned int App_ImageHeight;const char* asciiTable = "$#;+:,..  \0";unsigned char asciiTableSize = (unsigned char)strlen(asciiTable);unsigned char asciiLookup(unsigned char value) {	return asciiTable[value/(255/asciiTableSize)];}int initialize() {#ifdef _DEBUG	//Check for memory leaks at the end	int tempflag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);	tempflag |= _CRTDBG_LEAK_CHECK_DF;	_CrtSetDbgFlag(tempflag);#endif	AXAppLog->Initialize();	AXAppLog->Write(MESSAGE_USER, "AliquiX Started ~ " __TIMESTAMP__);	AXAppSettings->ParseFile("settings.txt", SETTING_USER);	ilInit();	ilEnable(IL_FILE_OVERWRITE);	ilEnable(IL_ORIGIN_SET);	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);	ILuint ImageName;	ilGenImages(1, &ImageName);	ilBindImage(ImageName);	AXAppLog->Write(MESSAGE_APP, "Loading picture " PICTURENAME PICTUREEXT "...");	if(!ilLoadImage(PICTURENAME PICTUREEXT)) {		AXAppLog->Write(MESSAGE_APP, "Could not load " PICTURENAME PICTUREEXT);		ilDeleteImages(1, &ImageName);		return AXFAILURE;	}	// Resize it	int NewImageWidth = AXAppSettings->GetSetting<int>("ascii_cols");	int NewImageHeight = AXAppSettings->GetSetting<int>("ascii_rows");	if(NewImageWidth > 0 && NewImageHeight > 0)		iluScale(NewImageWidth, NewImageHeight, 1);		ILint ImageFormat;	ILuint ImageWidth, ImageHeight;	ImageFormat = ilGetInteger(IL_IMAGE_FORMAT);	ImageWidth = ilGetInteger(IL_IMAGE_WIDTH);	ImageHeight = ilGetInteger(IL_IMAGE_HEIGHT);	App_ImageWidth = ImageWidth;	App_ImageHeight = ImageHeight;	App_ImageFormat = ImageFormat;	if(ImageFormat == IL_RGB) {		App_ImageData = new unsigned char[ImageWidth*ImageHeight*3];		App_ImageDataSize = ImageWidth*ImageHeight*3;	}	else if(ImageFormat == IL_LUMINANCE) {		App_ImageData = new unsigned char[ImageWidth*ImageHeight];		App_ImageDataSize = ImageWidth*ImageHeight;	}	else {		AXAppLog->Write(MESSAGE_APP, "Image format not supported.  Must be RGB or grayscale.");		ilDeleteImages(1, &ImageName);		return AXFAILURE;	}	unsigned char *image = ilGetData();	memcpy(App_ImageData, image, sizeof(unsigned char)*App_ImageDataSize);	ilDeleteImages(1, &ImageName);	AXAppLog->Write(MESSAGE_APP, "Loaded symbol table: %s", asciiTable);	return AXSUCCESS;}void shutdown() {	SafeDelete(App_ImageData);	AXAppSettings->WriteToFile("settings.txt", SETTING_USER);	delete AXAppSettings;	AXAppLog->Shutdown();	delete AXAppLog;}/* ------------------------------------------------------		Run()				The meat of the program!  This is where the image processing is done.------------------------------------------------------ */void run() {		if(App_ImageFormat == IL_RGB) {		/* ----------------------------------			Need to convert to grayscale first		--------------------------------- */		AXAppLog->Write(MESSAGE_APP, "Since the picture is RGB, converting to grayscale...");		unsigned char r, g, b;		unsigned char *NewImageData = new unsigned char[App_ImageWidth*App_ImageHeight];		for(unsigned int i=0; i3
) {
r = App_ImageData;
g = App_ImageData[i+1];
b = App_ImageData[i+2];

unsigned char grayscale = (unsigned char)(0.3f*r + 0.59f*g + 0.11f*b);
NewImageData[i/3] = grayscale;
}

SafeDeleteArr(App_ImageData);
App_ImageData = NewImageData;
App_ImageDataSize /= 3;
}

/* ----------------------------------
Now switch it up with ASCII values
---------------------------------- */

AXAppLog->Write(MESSAGE_APP, "Converting it to ascii and saving to file...");
ofstream asciiFile(PICTURENAME ".txt");

for(unsigned int i=0; i if(i%App_ImageWidth == 0) asciiFile << endl;
unsigned char pixelValue = App_ImageData;
unsigned char asciiValue = asciiLookup(pixelValue);
asciiFile << asciiValue;
}

asciiFile.close();

}














lets see if I can get this to work... (well, can't find a way to do fixed width font, I thought the tag did it, but evidentally not...)



(edit: duh, I didn't even think of the source tags, or at least I didn't realize it formatted it as fixed width, thanks rob!)
                                                                       ...,..                                                                                    :::,.                       ..                                                                +:.;:                            ...... .,                                                     +!,,+i+.                      .........    .....,,:                                              ;+.i;+;;i::.:                        ................,                                           ii+!:::,.. , ! . ,                            ...........                                         ;.               ,  :.                   ..................                                         ,,!  .             ,  !     ......        .................                                          ,,.!                : :       ........      ..,,.,,,,.,..,                                         .. :i+:!             .,::   ..  ..  .,:,:,,.,.   .,,,,,,,.,                                         , .   .:+:, ..       ...,:: . .,, ,,o;!,,!+,,:!,,.,,..,,...                                        ,    ,      .  .,      ....:: ,. ,+;,!;+i7;i.;,,,,,!!,.,....                                        : ,           .  .,     ..,.,:  :, :;;,ii+;++t7i,+,,,.++.,..                                       :  !    !.,:os:::: ..      ...,:   :0,;,tiioo,+i;,,,:,,:,:+:.                                      ,:  !     o+;o68xt8$. ,,     .,.::   !+t;::,;it!,oii,,,,,:::!+                                      +          i:!+!!.     , ,    ,,.,,   ++xi:s6oii7ii,o,,,+..++,                                     .,          ,              ,    ..,,::  ++7+tii,!tooot,,!;:..+;                                     i,   :                  ,  ,.7    :,:!t  ++io!+:7to,o!!o:.+,.:;                                     ,,                      ,   ,,6,    :!+t  ++;i+txt ,!::!,,i+,,;                                      ,      i                  , :.i    :.!ot  !;iit,o!i+!:!o,;;!,,                                    .,,,      i!,i              .  !,; .  ! !t6. !6    !o:;.i;,,ii,,                                    . .:                       .,,,.:o, !  !!+77. ;ti!+o o!,:;+,ii,,                                       ,           !io,        .,:!.,,t. +  +;+7,!!i!,,,. +;.+;,ii!,                                     ,               .        .,:+i; :to  !  ;;i6 ioi..+ ; . 6+,i+:,                                       ,,               i:.  .,:;ooi+   : ::; ;;oi.io,,  : , o!,;!!,                                         .                ,,:!;tit   !,    ,++ ;io.it;:,!  .,+!.;!!,                                          .                                .:,+ ;oi!+.  !:  ;++:++!:                                          ..                           ! . .,++.;it.o;.:,!:+++++!!::                                            .                          ,   ..+; ,i+!it, +i+++++:!:,,
Previous Entry Chunk of code
Next Entry Logger
0 likes 6 comments

Comments

Sir Sapo
Awesome.
July 04, 2005 03:12 AM
Rob Loach
                                                                                                   
                                                                      ...,..                        
                                                            :::,.                       ..          
                                                      +:.;:                            ...... .,    
                                                 +!,,+i+.                      .........    .....,,:
                                              ;+.i;+;;i::.:                        ................,
                                           ii+!:::,.. , ! . ,                            ...........
                                         ;.               ,  :.                   ..................
                                         ,,!  .             ,  !     ......        .................
                                          ,,.!                : :       ........      ..,,.,,,,.,..,
                                         .. :i+:!             .,::   ..  ..  .,:,:,,.,.   .,,,,,,,.,
                                         , .   .:+:, ..       ...,:: . .,, ,,o;!,,!+,,:!,,.,,..,,...
                                        ,    ,      .  .,      ....:: ,. ,+;,!;+i7;i.;,,,,,!!,.,....
                                        : ,           .  .,     ..,.,:  :, :;;,ii+;++t7i,+,,,.++.,..
                                       :  !    !.,:os:::: ..      ...,:   :0,;,tiioo,+i;,,,:,,:,:+:.
                                      ,:  !     o+;o68xt8$. ,,     .,.::   !+t;::,;it!,oii,,,,,:::!+
                                      +          i:!+!!.     , ,    ,,.,,   ++xi:s6oii7ii,o,,,+..++,
                                     .,          ,              ,    ..,,::  ++7+tii,!tooot,,!;:..+;
                                     i,   :                  ,  ,.7    :,:!t  ++io!+:7to,o!!o:.+,.:;
                                     ,,                      ,   ,,6,    :!+t  ++;i+txt ,!::!,,i+,,;
                                      ,      i                  , :.i    :.!ot  !;iit,o!i+!:!o,;;!,,
                                    .,,,      i!,i              .  !,; .  ! !t6. !6    !o:;.i;,,ii,,
                                    . .:                       .,,,.:o, !  !!+77. ;ti!+o o!,:;+,ii,,
                                       ,           !io,        .,:!.,,t. +  +;+7,!!i!,,,. +;.+;,ii!,
                                     ,               .        .,:+i; :to  !  ;;i6 ioi..+ ; . 6+,i+:,
                                       ,,               i:.  .,:;ooi+   : ::; ;;oi.io,,  : , o!,;!!,
                                         .                ,,:!;tit   !,    ,++ ;io.it;:,!  .,+!.;!!,
                                          .                                .:,+ ;oi!+.  !:  ;++:++!:
                                          ..                           ! . .,++.;it.o;.:,!:+++++!!::
                                            .                          ,   ..+; ,i+!it, +i+++++:!:,,


YAY!
July 04, 2005 09:26 AM
choffstein
Thats pretty slick, mate.
July 04, 2005 11:08 AM
okonomiyaki

Thanks [grin]

making little programs like this keeps you from burning out.
July 04, 2005 11:37 AM
DecipherOne
Awesome, I've been looking at various ascii art programs lately, and it's nice to be able to look at the source from one. In fact, this helps me so much, have some rating points.
July 04, 2005 02:18 PM
okonomiyaki
Great, glad to be of service. I hope it's not too simplistic of an example. I pretty much pulled it out of my butt without looking at the real ways of doing it!
July 04, 2005 09:18 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement