C Graphics Program For Boundary Fill in C

C Graphics Program For Boundary Fill in C

Source Code:-







1:  //Program to implement Boundary Fill Algorithm  

2:  #include <graphics.h>  
3:  #include <stdlib.h>  
4:  #include <stdio.h>  
5:  #include <conio.h>  
6:  #include "grplib.h"  
7:  int bfill(int x,int y,int f,int b)  
8:       {  
9:       if(getpixel(x,y) !=b && getpixel(x,y)!=f)  
10:            {  
11:            putpixel(x,y,f);  
12:            bfill(x+1,y,f,b);  
13:            bfill(x-1,y,f,b);  
14:            bfill(x,y+1,f,b);  
15:            bfill(x,y-1,f,b);  
16:            }  
17:       return 0;  
18:       }  
19:  int main(void)  
20:  {  
21:    int gdriver = DETECT, gmode;  
22:    int x,y;  
23:    int bx,by;  
24:    int vert[10],n,i;  
25:    int left, top, right, bottom;  
26:    initgraph(&gdriver, &gmode, "");  
27:    printf(" Boundary fill :\n");  
28:    printf(" Enter the no. of vertices .. ? ");  
29:    scanf("%d",&n);  
30:    printf(" Select the vertices >>");  
31:    initmouse();  
32:    showmouse();  
33:    for(i=0;i<n*2;i+=2)  
34:       {  
35:       getposOnClick(&x,&y);  
36:       hidemouse();  
37:       putpixel(x,y,10);  
38:       showmouse();  
39:       vert[i]=x;  
40:       vert[i+1]=y;  
41:       }  
42:   hidemouse();  
43:   dpoly(n,vert);  
44:   showmouse();  
45:   gotoxy(10,23);  
46:   printf("Click on a point to fill .. ");  
47:   getposOnClick(&x,&y);  
48:   hidemouse();  
49:   bx=x;  
50:   by=y;  
51:   showmouse();  
52:   hidemouse();  
53:   bfill(bx,by,10,15);  
54:   gotoxy(10,24);  
55:   printf(" all done !");  
56:   getch();  
57:   closegraph();  
58:   return 0;  
59:  }  

Comments

Popular posts from this blog

How To Install LEX and YACC in Linux or Ubuntu

Lex Program To Check The Syntax of For Loop

Listing/Delisting of an article in to an Assortment in SAP SCM Retail