Monday 21 July 2014

Graphics Under C

Graphics Under C

This is my First Simple program.
In this program you can see a rocket going from one corner to another.

#include
#include
#include
#include
int main(void)
{ /* request auto detection */
int gdriver = DETECT, gmode, errorcode; int maxx, maxy,i;
/* our polygon array */
int poly[10]; int poly1[10];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{ printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch(); /* terminate with an error code */
exit(1); }
/* maxx = getmaxx();
maxy = getmaxy(); */
for(i=400;i>=0;i--)
{ poly[0] = 60+i; /* 1st vertext */
poly[1] = 40+i;
poly[2] = 30+i; /* 2nd */ poly[3] = 20+i;
poly[4] = 10+i; /* 3rd */ poly[5] = 40+i;
poly[6] = 30+i; /* 4th */ poly[7] = 30+i;
/* drawpoly doesn't automatically close the polygon, so we close it.*/
poly[8] = poly[0];
poly[9] = poly[1];
/* draw the polygon */
setfillstyle(1,14); drawpoly(5, poly);
fillpoly(5,poly); setcolor(14);
rectangle(40+i,35+i,25+i,80+i)
;
clearviewport(); } /* clean up */
closegraph();
return 0;
}
I think you will love this programs. From SARAVANA