Skip to content

Instantly share code, notes, and snippets.

@haseeb-heaven
Last active June 15, 2022 10:11
Show Gist options
  • Save haseeb-heaven/fdaf136fd5d664abeb79e4af33944fd5 to your computer and use it in GitHub Desktop.
Save haseeb-heaven/fdaf136fd5d664abeb79e4af33944fd5 to your computer and use it in GitHub Desktop.
AsciiTextGenerator is text generator like FIGlet fonts.
/*Ascii text Generator in C. - Convert your text or any text to fancy ASCII font.
Artic Coder */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define TEXT_LEN 0x64
#define FONT_HEIGHT 5
#define FONT_WIDTH 53
#define FONT_LEN 0x7F
void StoreFonts(char *[]);
int PrintLine(char *);
void PrintAsciiFont(char *);
int main(void)
{
char text[TEXT_LEN] = {'\0'};
puts("Enter text.");
fgets(text,TEXT_LEN,stdin);
strtok(text, "\n");
PrintAsciiFont(text);
getchar();
return 0;
}
void PrintAsciiFont(char *ascii_text)
{
char split_line[TEXT_LEN] = {'\0'};
int ascii_text_len = strlen(ascii_text),split_begin = 0,split_index = 18
;
if(ascii_text_len > split_index)
{
do
{
strncpy(split_line,&ascii_text[split_begin], split_index);
PrintLine(split_line);
split_begin += split_index;
}while(split_begin <= ascii_text_len);
}
else
{
PrintLine(ascii_text);
}
}
int PrintLine(char *ascii_text)
{
int print_status = 0;
char *fonts[FONT_LEN] = {'\0'};
StoreFonts(fonts);
int i = 0,j = 0,k = 0,h = 0,alphanum_count = 0;
size_t text_len = strlen(ascii_text);
int index_arr[text_len];
memset(index_arr,0,sizeof(index_arr));
/*Error checking for special characters.*/
for(i = 0; i < text_len;++i)
{
if(isalnum(ascii_text[i]) || isspace(ascii_text[i])){
alphanum_count++;
}
}
if(alphanum_count != text_len)
{
fprintf(stderr,"Error : AsciiTextGenerator fonts only supports Alphanumeric values [A-Z,a-z,0-9] . Special characters and symbols not supported yet! thanks.");
print_status = 1;
return print_status;
}
for(h = 1; h <= FONT_HEIGHT; h++)
{
for(i = 0; i < text_len; i++)
{
for(j = index_arr[k]; j < strlen(fonts[ascii_text[i]]); j++)
{
if(fonts[ascii_text[i]][j] == FONT_LEN)
{
index_arr[k++] = j+1;
break;
}
putchar(fonts[ascii_text[i]][j]);
}
}
k = 0;
printf("\n");
}
return print_status;
}
/*Store all fonts (A-Z,a-z,0-9). Special characters not supported yet.*/
void StoreFonts(char *fonts[])
{
fonts[' '] = "\
\
\
\
\
";
fonts['0'] = "\
___ \
/ _ \\ \
| | | | \
| |_| | \
\\___/ ";
fonts['1'] = "\
_ \
/ |\
| |\
| |\
|_|";
fonts['2'] = "\
____ \
|____\\ \
__) | \
/ __/ \
|_____| ";
fonts['3'] = "\
_____ \
|___ / \
|_ \\ \
___) |\
|____/ ";
fonts['4'] = "\
_ _ \
| || | \
| || |_ \
|__ _|\
|_| ";
fonts['5'] = "\
____ \
| ___| \
|___ \\  \
___) | \
|____/ ";
fonts['6'] = "\
__ \
/ /_ \
| '_ \\ \
| (_) |\
\\___/ ";
fonts['7'] = "\
_____ \
|___ |\
/ / \
/ / \
/_/ ";
fonts['8'] = "\
___ \
( _ ) \
/ _ \\ \
| (_) |\
\\___/ ";
fonts['9'] = "\
___ \
/ _ \\ \
| (_) |\
\\__, |\
/_/ ";
fonts['A'] = fonts['a'] = "\
_ \
/ \\ \
/ _ \\ \
/ ___ \\ \
/_/ \\_\\ ";
fonts['B'] = fonts['b'] ="\
____ \
| __ ) \
| _ \\ \
| |_) |\
|____/ ";
fonts['C'] = fonts['c'] = "\
____ \
/ ___| \
| | \
| |___ \
\\____| ";
fonts['D'] = fonts['d'] = "\
____ \
| _ \\\
| | | |\
| |_| |\
|____/ ";
fonts['E'] = fonts['e'] ="\
_____ \
| ____|\
| _| \
| |___ \
|_____|";
fonts['F'] = fonts['f'] = "\
_____ \
| ___|\
| |_ \
| _| \
|_| ";
fonts['G'] = fonts['g'] = "\
____ \
/ ___|\
| | _ \
| |_| |\
\\____|";
fonts['H'] = fonts['h'] ="\
_ _ \
| | | |\
| |_| |\
| _ |\
|_| |_|";
fonts['I'] = fonts['i'] ="\
___ \
|_ _|\
| | \
| | \
|___|";
fonts['J'] = fonts['j'] ="\
_ \
| |\
_ | |\
| |_| |\
\\___/ ";
fonts['K'] = fonts['k'] = "\
_ __\
| |/ /\
| ' / \
| . \\ \
|_|\\_\\";
fonts['L'] = fonts['l'] = "\
_ \
| | \
| | \
| |___ \
|_____|";
fonts['M'] = fonts['m'] = "\
__ __ \
| \\/ |\
| |\\/| |\
| | | |\
|_| |_|";
fonts['N'] = fonts['n'] = "\
_ _ \
| \\ | |\
| \\| |\
| |\\ |\
|_| \\_|";
fonts['O'] = fonts['o'] ="\
___ \
/ _ \\ \
| | | | \
| |_| | \
\\___/ ";
fonts['P'] = fonts['p'] = "\
____ \
| _ \\ \
| |_) |\
| __/ \
|_| ";
fonts['Q'] = fonts['q'] = "\
___ \
/ _ \\ \
| | | | \
| |_| | \
\\__\\ _\\";
fonts['R'] = fonts['r'] = "\
____ \
| _ \\ \
| |_) |\
| _ < \
|_| \\_\\";
fonts['S'] = fonts['s'] = "\
____ \
/ ___| \
\\___ \\ \
___) |\
|____/ ";
fonts['T'] = fonts['t'] = "\
_____ \
|_ _|\
| | \
| | \
|_| ";
fonts['U'] = fonts['u'] = "\
_ _ \
| | | |\
| | | |\
| |_| |\
\\___/ ";
fonts['V'] = fonts['v'] = "\
__ __\
\\ \\ / /\
\\ \\ / / \
\\ V / \
\\_/ ";
fonts['W'] = fonts['w'] = "\
__ __\
\\ \\ / /\
\\ \\ /\\ / / \
\\ V V / \
\\_/\\_/ ";
fonts['X'] = fonts['x'] ="\
__ __\
\\ \\/ /\
\\ / \
/ \\ \
/_/\\_\\";
fonts['Y'] = fonts['y'] = "\
__ __\
\\ \\ / /\
\\ V / \
| | \
|_| ";
fonts['Z'] = fonts['z'] = "\
_____\
|__ /\
/ / \
/ /_ \
/____|";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment