Header file:
graphics.h
Synopsis:
void initgraph (int *gd, int *gm, char *path);
gd - pointer to graphic driver
gm - pointer to graphic mode
path - directory path where initgraph looks for graphic driver
Description:
initgraph() loads the graphic system from disk then puts the system into graphic mode.
initgraph function in c graphics
#include <conio.h>
#include <graphics.h>
#include <dos.h>
int main() {
/* request auto detection */
int graphicDriver = DETECT, graphicMode;
int i, err, midx, midy;
int circleRadius = 150, arcRadius = 150;
initgraph(&graphicDriver, &graphicMode, "C:/TURBOC3/BGI");
err = graphresult();
if (err != grOk) {
/* error occurred */
printf("Graphic Error: %s\n",
grapherrormsg(err));
return 0;
}
/* mid position in x and y-axis */
midx = getmaxx() / 2;
midy = getmaxy() / 2;
for (i = 15; i > 0; i--) {
/* sets the current drawing color */
setcolor(i);
/* setting the current fill style */
setfillstyle(SOLID_FILL, i);
/* drawing circle at the middle of the screen */
circle(midx, midy, circleRadius);
/* fill the bounded area using the given color */
floodfill(midx, midy, i);
/* drawing arcs at the four end of the screen */
arc(0, 0, 270, 360, arcRadius);
floodfill(0, 0, i);
arc(getmaxx(), 0, 180, 270, arcRadius);
floodfill(getmaxx(), 0, i);
arc(0, getmaxy(), 0, 90, arcRadius);
floodfill(0, getmaxy(), i);
arc(getmaxx(), getmaxy(), 90, 180, arcRadius);
floodfill(getmaxx(), getmaxy(), i);
circleRadius = circleRadius - 10;
arcRadius = arcRadius - 10;
delay(400);
}
getch();
/* clean up */
closegraph();
return 0;
}
Output: (initgraph built-in function in c graphics.h)
No comments:
Post a Comment