Pages

Boundry fill & Flood fill algo

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void boundary(int,int,int,int);
void flood_fill(int,int,int,int);
void main()
{
    int gd=DETECT,gm;
    initgraph(&gd,&gm,"c:\\tc\\bgi");
    rectangle(50,50,100,100);
    boundary(55,55,4,15);
    flood_fill(55,55,4,1);
    getch();
    closegraph();

}
void boundary(int seed_x,int seed_y,int f_col,int b_col)
{
    if(getpixel(seed_x,seed_y)!=b_col && getpixel(seed_x,seed_y)!=f_col)
    {
        putpixel(seed_x,seed_y,f_col);
        boundary(seed_x+1,seed_y,f_col,b_col);
        boundary(seed_x-1,seed_y,f_col,b_col);
        boundary(seed_x,seed_y+1,f_col,b_col);
        boundary(seed_x,seed_y-1,f_col,b_col);
        boundary(seed_x+1,seed_y+1,f_col,b_col);
        boundary(seed_x-1,seed_y-1,f_col,b_col);
        boundary(seed_x+1,seed_y-1,f_col,b_col);
        boundary(seed_x-1,seed_y+1,f_col,b_col);
    }

}
void flood_fill(int seed_x,int seed_y,int old_col,int new_col)
{
    if(getpixel(seed_x,seed_y)==old_col)
    {
        putpixel(seed_x,seed_y,new_col);
        flood_fill(seed_x+1,seed_y,old_col,new_col);
        flood_fill(seed_x-1,seed_y,old_col,new_col);
        flood_fill(seed_x,seed_y+1,old_col,new_col);
        flood_fill(seed_x,seed_y-1,old_col,new_col);
        flood_fill(seed_x+1,seed_y+1,old_col,new_col);
        flood_fill(seed_x-1,seed_y-1,old_col,new_col);
        flood_fill(seed_x+1,seed_y-1,old_col,new_col);
        flood_fill(seed_x-1,seed_y+1,old_col,new_col);

    }

}