• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Boundary and Flood Fill Algorithms in C++ Language

April 6, 2011 by ProjectsGeek 2 Comments

Boundary and Flood Fill Algorithms

Write a program for Boundary and Flood Fill Algorithms in C++ Language . Boundary and Flood Fill Algorithms in C++ should accept the coordinates for polygon.

  • INPUT
  • FLOOD FILL
  • BOUNDARY FILL
  • EXIT

After selecting Boundary and Flood fill algorithm option , It must fill polygon by both algorithms.

Boundary and Flood Fill Algorithms Code

 #include  
 #include  
 #include  
 #include  
 #define max 100000  
 class fill  
 {  
   int edge,a[50],sx,sy,midx,midy;  
   public:  
   void input()  
   {  
     cout<<"\nENTER NO OF EDGES:";  
     cin>>edge;  
     int j=0;  
     for(int i=0;i<edge;i++) <br="">     {  
       cout<<"\nENTER THE X"<<i+1<<"coordinate:"; <br="">       cin>>a[j++];  
       cout<<"\nENTER THE Y"<<i+1<<"coordinate:"; <br="">       cin>>a[j++];  
     }  
   }  
   void b_fill(int x,int y,int clr)  
   {  
     int j=0;  
     midx=getmaxx()/2;  
     midy=getmaxy()/2;  
     setcolor(WHITE);  
     line(0,midy,2*midx,midy);  
     line(midx,0,midx,2*midy);  
     setcolor(RED);  
     for(int i=0;i<edge;i++) <br="">     {  
       if(edge-i!=1)  
         line(a[j]+midx,midy-a[j+1],a[j+2]+midx,midy-a[j+3]);  
       else  
         line(a[j]+midx,midy-a[j+1],a[0]+midx,midy-a[1]);  
       j=j+2;  
     }  
     getch();  
     int st[max][2],top=-1;  
     x=midx+x;  
     y=midy-y;  
     st[++top][0]=x;  
     st[top][1]=y;  
     while(top!=-1)  
     {  
       x=st[top][0];  
       y=st[top][1];  
       top--;  
       if((getpixel(x+1,y)!=clr)&&(getpixel(x+1,y)!=RED))  
       {  
         putpixel(x+1,y,clr);  
         st[++top][0]=x+1;  
         st[top][1]=y;  
       }  
       if((getpixel(x-1,y)!=clr)&&(getpixel(x-1,y)!=RED))  
       {  
         putpixel(x-1,y,clr);  
         st[++top][0]=x-1;  
         st[top][1]=y;  
       }  
       if((getpixel(x,y+1)!=clr)&&(getpixel(x,y+1)!=RED))  
       {  
         putpixel(x,y+1,clr);  
         st[++top][0]=x;  
         st[top][1]=y+1;  
       }  
       if((getpixel(x,y-1)!=clr)&&(getpixel(x,y-1)!=RED))  
       {  
         putpixel(x,y-1,clr);  
         st[++top][0]=x;  
         st[top][1]=y-1;  
       }  
      }  
   }  
   void f_fill(int x,int y,int clr)  
   {  
     int j=0;  
     midx=getmaxx()/2;  
     midy=getmaxy()/2;  
     setcolor(WHITE);  
     line(0,midy,2*midx,midy);  
     line(midx,0,midx,2*midy);  
     setcolor(RED);  
     for(int i=0;i<edge;i++) <br="">     {  
       if(edge-i!=1)  
         line(a[j]+midx,midy-a[j+1],a[j+2]+midx,midy-a[j+3]);  
       else  
         line(a[j]+midx,midy-a[j+1],a[0]+midx,midy-a[1]);  
       j=j+2;  
     }  
     getch();  
     int st[max][2],top=-1;  
     x=midx+x;  
     y=midy-y;  
     st[++top][0]=x;  
     st[top][1]=y;  
     putpixel(x,y,col);  
     while(top!=-1)  
     {  
       x=st[top][0];  
       y=st[top][1];  
       top--;  
       if((getpixel(x+1,y)!=clr)&&(getpixel(x+1,y)==7))  
       {  
         putpixel(x+1,y,clr);  
         st[++top][0]=x+1;  
         st[top][1]=y;  
       }  
       if((getpixel(x-1,y)!=clr)&&(getpixel(x-1,y)==7))  
       {  
         putpixel(x-1,y,clr);  
         st[++top][0]=x-1;  
         st[top][1]=y;  
       }  
       if((getpixel(x,y+1)!=clr)&&(getpixel(x,y+1)==7))  
       {  
         putpixel(x,y+1,clr);  
         st[++top][0]=x;  
         st[top][1]=y+1;  
       }  
       if((getpixel(x,y-1)!=clr)&&(getpixel(x,y-1)==7))  
       {  
         putpixel(x,y-1,clr);  
         st[++top][0]=x;  
         st[top][1]=y-1;  
       }  
      }  
   }  
 };  
 void menu()  
 {  
   clrscr();  
   cout<<"\n\t##### MAIN MENU #####";  
   cout<<"\n\t1.INPUT";  
   cout<<"\n\t2.FLOOD FILL";  
   cout<<"\n\t3.BOUNDARY FILL";  
   cout<<"\n\t4.EXIT";  
   cout<<"\n\tENTER UR CHOICE:";  
 }  
 void main()  
 {  
   int gd=DETECT,gm;  
     initgraph(&gd,&gm,"c:\\tc\\bgi");  
   int ch,x,y,clr;  
   fill f;  
   do  
   {  
     menu();  
     cin>>ch;  
     clrscr();  
     switch(ch)  
     {  
       case 1:  
         f.input();  
         break;  
       case 2:  
         cout<<"\n#### FLOOD FILL ####";  
         cout<<"\nENTER THE COLOR CODE TO FILL:";  
         cin>>clr;  
         cout<<"\nENTER THE X-COORDINATE OF SEED POINT:";  
         cin>>x;  
         cout<<"\nENTER THE Y-COORDINATE OF SEED POINT:";  
         cin>>y;  
         f.f_fill(x,y,clr);  
         getch();  
         break;  
       case 3:  
         cout<<"\n#### BOUNDARY FILL ####";  
         cout<<"\nENTER THE COLOR CODE TO FILL:";  
         cin>>clr;  
         cout<<"\nENTER THE X-COORDINATE OF SEED POINT:";  
         cin>>x;  
         cout<<"\nENTER THE Y-COORDINATE OF SEED POINT:";  
         cin>>y;  
         f.b_fill(x,y,clr);  
         getch();  
         break;  
       case 4:  
         break;  
     }  
   }while(ch!=4);  
 }

 

 

Other Projects to Try:

  1. Graphics Editor code Using C++ Language
  2. Transformations computer graphics using C++ Language
  3. Computer graphics codes in C++ Language
  4. Paging Algorithms using C language OS problem
  5. Bressenham and DDA Line Drawing algorithms

Filed Under: C Assignments, Computer Graphics Tagged With: Computer Graphics

Reader Interactions

Comments

  1. ZH says

    June 16, 2014 at 2:44 am

    Hi. your code looks interesting. but i can’t compile it, too many errors.
    can you provide any information about the compiling tools and required headers?
    thank you very much.

    Reply
    • ProjectsGeek says

      June 20, 2014 at 3:18 pm

      @zh….I used turbo c compiler for developing this code. Try to compile this code using turbo c IDE.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy