Wednesday, June 13, 2007

Generating character (letter) in C language

Generating character (letter) in C language

As shown below is the demostratation to generate a character B using pixels using C.

This is how the computer renders(displays) fonts at very low level. While making any doc you must know how the system renders font. Each and every letter is displayed by a pixel square of 1's and 0's ... 1 represents visibility while 0 represents hiding the pixel.

Eg: Its B as below. Its rather looks like a 8. You have to make perfect combination of 1's and 0's as in the grid to get desired output.
111111
110011
111111
111111
110011
111111

/************************************************/

#include
#include
#include
void generatecharback();
void generatechar(char);
void main()
{
int gdriver, gmode;

gdriver=DETECT;
gmode=EGAHI;
initgraph(&gdriver,&gmode,"");
setbkcolor(4);
generatecharback();
generatechar('B');
outtextxy(203, 200, "char generation");
getch();
closegraph();
}

void generatecharback(){
int i=0;
int j=0;
for(i=0;i<=7;i++){
for(j=0;j<=7;j++){
putpixel(i+100,j+100,8);
}
}
}
void generatechar() {
int charray[1][65]={{1,1,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0}};
int i,j,k;
k=0;
for(i=0;i<=7;i++){
for(j=0;j<=7;j++){
if(charray[0][k]==1){
putpixel(j+100,i+100,WHITE);
}
k++;
}
}
}

No comments: