Logo 
Search:

C++ Programming Articles

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

Program of Boundary Fill (8 Connected Point).

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

Write a program of Boundary Fill (8 Connected Point).

Code for Program of Boundary Fill (8 Connected Point). in C++ Programming

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

class Circle
{
    int XCoord;
    int YCoord;
    int Radius;
    void PlotPoint(int,int,int);
    public:
    Circle()
    {
        XCoord=0;
        YCoord=0;
        Radius=0;
    }

    Circle(int x, int y, int z)
    {
        XCoord=x;
        YCoord=y;
        Radius=z;
    }

    void CircleMidpoint();
    void InitGraphs();
    void BoundryFill(int,int,int,int);
    void BoundryFillRound();
};

void Circle :: InitGraphs()
{
    int gMode, gDriver=DETECT;
    int errorcode;
    initgraph(&gDriver,&gMode,"c:\\tc\\bgi");
    errorcode = graphresult();

    if (errorcode != grOk)  /* an error occurred */
    {
       cout<<"Graphics error: "<< grapherrormsg(errorcode);
       cout<<"Press any key to halt:";
       getch();
       exit(1);             /* return with error code */
    }
    setbkcolor(3);
}

void Circle :: PlotPoint(int x,int y,int z)
{
    putpixel(XCoord+x,YCoord+y,z);
    putpixel(XCoord-x,YCoord+y,z);
    putpixel(XCoord+x,YCoord-y,z);
    putpixel(XCoord-x,YCoord-y,z);
    putpixel(XCoord+y,YCoord+x,z);
    putpixel(XCoord-y,YCoord+x,z);
    putpixel(XCoord+y,YCoord-x,z);
    putpixel(XCoord-y,YCoord-x,z);
}

void Circle :: CircleMidpoint()
{
    int x,y;
    int p;
    x=0;
    y=Radius;
    PlotPoint(x,y,15);

    p=1-Radius;
    while(x<y)
    {
        if(p<0)
            x+=1;
        else
        {
            x+=1;
            y-=1;
        }

        if(p<0)
            p=p+2*x+1;
        else
        {
            p=p + 2 *(x-y) + 1;
        }
        PlotPoint(x,y,15);
    }
}

void Circle :: BoundryFillRound()
{
    int x,y;
    int p;
    for(int iCntr=1;iCntr<Radius;iCntr++)
    {
    x=0;
    y=iCntr;
    PlotPoint(x,y,5);

    p=1-iCntr;
    while(x<y)
    {
        if(p<0)
            x+=1;
        else
        {
            x+=1;
            y-=1;
        }

        if(p<0)
            p=p+2*x+1;
        else
        {
            p=p + 2 *(x-y) + 1;
        }
        PlotPoint(x,y,5);
    }
//    sleep(1);
    }
}

void Circle :: BoundryFill(int x, int y,int fill,int bound)
{
    int cur;
    cur=getpixel(x,y);
    if(cur!=bound && cur!= fill)
    {
        putpixel(x,y,fill);
        Circle :: BoundryFill(x+1, y,fill,bound);
        Circle :: BoundryFill(x-1, y,fill,bound);
        Circle :: BoundryFill(x, y-1,fill,bound);
        Circle :: BoundryFill(x, y+1,fill,bound);
        Circle :: BoundryFill(x+1, y+1,fill,bound);
        Circle :: BoundryFill(x+1, y+1,fill,bound);
        Circle :: BoundryFill(x-1, y-1,fill,bound);
        Circle :: BoundryFill(x-1, y+1,fill,bound);
    }
}

void main()
{
    Circle cObj(250,250,42);
    cObj.InitGraphs();
    cObj.CircleMidpoint();
    cObj.BoundryFillRound();
    //cObj.BoundryFill(250,250,11,15);
    getch();
    closegraph();
}
  
Share: 


Didn't find what you were looking for? Find more on Program of Boundary Fill (8 Connected Point). Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program of Boundary Fill (8 Connected Point). 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

Related Articles and Code:


 
Please enter your Comment

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

 
No Comment Found, Be the First to post comment!