Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Computer GraphicsRSS Feeds

Program of Flood fill algorithm

Posted By: Easy Tutor     Category: C++ Programming     Views: 27039

Write a program of flood fill algorithm.

Code for Program of Flood fill algorithm in C++ Programming

# include <stdio.h>
# include <dos.h>
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
# include <graphics.h>

void FloodFill(int,int,int,int);
void MidPoint(int);
void main()
{
    int xCenter=320;
    int yCenter=240;
    int gDriver = DETECT, gMode, errorcode;
    initgraph(&gDriver, &gMode, "c:\\tc\\bgi");
    cleardevice();
    MidPoint(49);

    FloodFill(xCenter+1,yCenter+1,0,8);
    getch();
    return;
}

void MidPoint(int Radius)
{
    int iCntr, x, y,p0;
    x=0;
    y=Radius;
    int xCenter=320;
    int yCenter=240;

    p0=(5/4)-Radius;

    putpixel(xCenter+x,yCenter+y,15);
    putpixel(xCenter-x,yCenter+y,15);
    putpixel(xCenter+x,yCenter-y,10);
    putpixel(xCenter-x,yCenter-y,10);
    putpixel(xCenter+y,yCenter+x,12);
    putpixel(xCenter-y,yCenter+x,12);
    putpixel(xCenter+y,yCenter-x,9);
    putpixel(xCenter-y,yCenter-x,9);


    while(x<=y)
    {
        if(p0 < 0)
        {
            p0=p0 + 2*(x+1) + 1;
            x=x+1;
        }
        else
        {
            p0=p0 + 2*(x+1) + 1 - 2*(y-1);
            x=x+1;
            y=y-1;
        }

        putpixel(xCenter+x,yCenter+y,15);
        putpixel(xCenter-x,yCenter+y,15);
        putpixel(xCenter+x,yCenter-y,10);
        putpixel(xCenter-x,yCenter-y,10);
        putpixel(xCenter+y,yCenter+x,12);
        putpixel(xCenter-y,yCenter+x,12);
        putpixel(xCenter+y,yCenter-x,9);
        putpixel(xCenter-y,yCenter-x,9);

    }

}
void FloodFill(int pointx,int pointy,int OldColor,int NewColor)
{
    int Intensity=getpixel(pointx,pointy);
    if(Intensity==OldColor)
    {
        putpixel(pointx,pointy,NewColor);
        FloodFill(pointx+1,pointy,OldColor,NewColor);
        FloodFill(pointx-1,pointy,OldColor,NewColor);
        FloodFill(pointx,pointy+1,OldColor,NewColor);
        FloodFill(pointx,pointy-1,OldColor,NewColor);
    }
}
  
Share: 


Didn't find what you were looking for? Find more on Program of Flood fill algorithm Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program of Flood fill algorithm is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Anisha Amir from Taiwan Comment on: Nov 05
I get errors and one of my error is:
graphics.h: No such file or directory.

Do I have to download any additional library?

View All Comments