Flood Fill Algorithm (C++)

#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
void ffill(int x,int y,int o_col,int n_col){
int current = getpixel(x,y);
if(current==o_col){
delay(1);
putpixel(x,y,n_col);
ffill(x+1,y,o_col,n_col);
ffill(x-1,y,o_col,n_col);
ffill(x,y+1,o_col,n_col);
ffill(x,y-1,o_col,n_col);
}
}
void main(){
int xc,yc,r;
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,”C:\TC\BGI”);
cout<<“Enter co-ordinates of the centre: “;
cin>>xc>>yc;
cout<<“Enter radius of circle: “;
cin>>r;
circle(xc,yc,r);
cout<<“Press any key to fill circle…”;
getch();
ffill(xc,yc,BLACK,RED);
getch();
closegraph();
}

Advertisement

4 thoughts on “Flood Fill Algorithm (C++)

  1. I have problem in cohen sutherland
    That how i could clip the line on topleft ,topright,bottomleft and bottom right

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.