0% found this document useful (0 votes)
186 views

Boundary Fill Algorithm in C

This document contains the source code for implementing a boundary fill algorithm in C. It includes function definitions for boundaryfill() and main(), where boundaryfill() recursively fills pixels of a given color inside a boundary, and main() initializes graphics mode, draws a circle, calls boundaryfill() to fill it, waits, and ends the program.

Uploaded by

Chess Blogs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
186 views

Boundary Fill Algorithm in C

This document contains the source code for implementing a boundary fill algorithm in C. It includes function definitions for boundaryfill() and main(), where boundaryfill() recursively fills pixels of a given color inside a boundary, and main() initializes graphics mode, draws a circle, calls boundaryfill() to fill it, waits, and ends the program.

Uploaded by

Chess Blogs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Source Code of Boundary Fill Algorithm in C:

#include<stdio.h>
#include<graphics.h>
#include<dos.h>
void boundaryfill(int x,int y,int f_color,int b_color)
{
if(getpixel(x,y)!=b_color && getpixel(x,y)!=f_color)
{
putpixel(x,y,f_color);
boundaryfill(x+1,y,f_color,b_color);
boundaryfill(x,y+1,f_color,b_color);
boundaryfill(x-1,y,f_color,b_color);
boundaryfill(x,y-1,f_color,b_color);
}
}
//getpixel(x,y) gives the color of specified pixel
int main()
{
int gm,gd=DETECT,radius;
int x,y;
printf("This code is coded by Dipesh Giri \n");
printf("Enter x and y positions for circle\n");
scanf("%d%d",&x,&y);
printf("Enter radius of circle\n");
scanf("%d",&radius);
initgraph(&gd,&gm,"..\\BGI");
circle(x,y,radius);
boundaryfill(x,y,4,15);
delay(5000);
closegraph();
getch();
return 0;
}

RESULT:

Thus, Boundary Fill Algorithm in C was implemented.

You might also like