Header file:
graphics.h
Synopsis:
void floodfill (int x, int y, int border);
(x, y) - seed point
border - border color of the bounder area
Description:
floodfill() fills enclosed area with current fill color. If the seed point is inside the enclosed area, then the interior portion of bounded area will be filled. If the seed point is outside the enclosed area, then the exterior portion of bounded area will be filled.
floodfill function in c graphics
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
int main(void) {
/* request auto detection */
int graphicDriver = DETECT, graphicMode;
int i, err;
/* initialize graphics, local variables */
initgraph(&graphicDriver, &graphicMode,
"C:/TURBOC3/BGI");
/* read result of initialization */
err = graphresult();
if (err != grOk) {
printf("Graphic Error: %s\n",
grapherrormsg(err));
return 0;
}
for (i = 0; i < 15; i++) {
floodfill(getmaxx() / 2, getmaxy() / 2, (i + 12) % 15);
delay(400);
setcolor(i % 15);
setfillstyle(LINE_FILL, i % 15);
arc(0, 0, 270, 360, 100);
/* fills enclosed area with current fill color & style */
floodfill(0, 0, i % 15);
delay(250);
setcolor((i + 3) % 15);
setfillstyle(SLASH_FILL, (i + 3) % 15);
arc(getmaxx(), 0, 180, 270, 100);
floodfill(getmaxx(), 0, (i + 3) % 15);
delay(250);
setcolor((i + 7) % 15);
setfillstyle(BKSLASH_FILL, (i + 7) % 15);
arc(0, getmaxy(), 0, 90, 100);
floodfill(0, getmaxy(), (i + 7) % 15);
delay(250);
setcolor((i + 9) % 15);
setfillstyle(SOLID_FILL, (i + 9) % 15);
arc(getmaxx(), getmaxy(), 90, 180, 100);
floodfill(getmaxx(), getmaxy(), (i + 9) % 15);
delay(250);
}
getch();
/* clean up */
closegraph();
return 0;
}
Output: (floodfill built-in function in c graphics.h)
No comments:
Post a Comment