flood fill program in c in computer graphics with output

/*Flood Fill Algorithm in C in Computer Graphics with Output*/
FloodFill Algorithm

#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
void floodfill(int x,int y,int old,int newcol)
{
                int current;
                current=getpixel(x,y);
                if(current==old)
                {
                                delay(5);
                                putpixel(x,y,newcol);
                                floodfill(x+1,y,old,newcol);
                                floodfill(x-1,y,old,newcol);
                                floodfill(x,y+1,old,newcol);
                                floodfill(x,y-1,old,newcol);
                                floodfill(x+1,y+1,old,newcol);
                                floodfill(x-1,y+1,old,newcol);
                                floodfill(x+1,y-1,old,newcol);
                                floodfill(x-1,y-1,old,newcol);
                }
}

void main()
{
                int gd=DETECT,gm;
                initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
                rectangle(50,50,150,150);
                floodfill(70,70,0,15);
                getch();
                closegraph();
}

output:

1 comment:

  1. 100% Working

    #include
    #include
    #include
    #include
    void floodFill(int x,int y,int old,int newcol)
    {
    int current;
    current=getpixel(x,y);
    if(current==old)
    {
    delay(5);
    putpixel(x,y,newcol);
    floodFill(x+1,y,old,newcol);
    floodFill(x-1,y,old,newcol);
    floodFill(x,y+1,old,newcol);
    floodFill(x,y-1,old,newcol);
    floodFill(x+1,y+1,old,newcol);
    floodFill(x-1,y+1,old,newcol);
    floodFill(x+1,y-1,old,newcol);
    floodFill(x-1,y-1,old,newcol);
    }
    }

    void main()
    {
    int gd=DETECT,gm;
    int left,top,right,bottom;

    printf("Enter the left point: ");
    scanf("%d",&left);

    printf("Enter the top point: ");
    scanf("%d",&top);

    printf("Enter the right point: ");
    scanf("%d",&right);

    printf("Enter the bottom point: ");
    scanf("%d",&bottom);

    initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");


    rectangle(left,top,right,bottom);
    floodFill(left+1,top+1,0,15);
    getch();
    closegraph();
    }

    ReplyDelete