WELCOME IN THE SEA OF C

Here you find some good quality programs.
If any one want any type of help in C and C++ then you can mail me.
Google

Tuesday, February 26, 2008

Coloured Rectangle's

This is the simple example of drawing and filling of different images.

"/" is used instead of "<" and ">".

#include/stdio.h/
#include/conio.h/
#include/graphics.h/
void main()
{
int gd=DETECT,gm,maxx,maxy,x=40,y=40,fst;
char str[40];
char *pattern[]={"EMPTY_FILL","SOLID_FILL",
"LINE_FILL","LTSLASH_FILL","SLASH_FILL","BKSLASH_FILL","LTBKSLASH_FILL",
"HATCH_FILL","XHATCH_FILL","INTERLEAVE_FILL","WIDE_DOT_FILL",
"CLOSE_DOT_FILL","USER_FILL"};
initgraph(&gd,&gm,"c:\\tc\\bgi");
maxx=getmaxx();
maxy=getmaxy();
rectangle(0,10,maxx,maxy);

setcolor(WHITE);
outtextxy(175,0,"pre-defined Fill style");

for(fst=0;fst<12;fst++)
{
setfillstyle(fst,MAGENTA);
bar(x,y,x+20,y+20);
rectangle(x,y,x+80,y+80);
setfillstyle(fst,BLUE);
bar(x+40,y,x+60,y+20);
rectangle(x,y,x+80,y+80);
setfillstyle(fst,RED);
bar(x+20,y+20,x+40,y+40);
rectangle(x,y,x+80,y+80);
setfillstyle(fst,GREEN);
bar(x+60,y+20,x+80,y+40);
rectangle(x,y,x+80,y+80);
setfillstyle(fst,MAGENTA);
bar(x,y+40,x+20,y+60);
rectangle(x,y,x+80,y+80);
setfillstyle(fst,BLUE);
bar(x+40,y+40,x+60,y+60);
rectangle(x,y,x+80,y+80);
setfillstyle(fst,RED);
bar(x+20,y+60,x+40,y+80);
rectangle(x,y,x+80,y+80);
setfillstyle(fst,GREEN);
bar(x+60,y+60,x+80,y+80);
rectangle(x,y,x+80,y+80);
itoa(fst,str,10);
outtextxy(x,y+100,str);
outtextxy(x,y+110,pattern[fst]);
x=x+150;
if(x>490)
{
y=y+150;
x=40;
}
}
getch();
closegraph();
restorecrtmode();
}

0 comments: