Program : Boundaryfill Polygon Filling
#include<stdio.h>
#include<conio.h>
#include<math.h> //header file inclusion
#include<graphics.h>
void main() //main function
{
int gdriver=DETECT,gmode,errorcode;
int x,y,i,r;
int xc,yc,t; //variable initializations
clrscr();
initgraph(&gdriver,&gmode,"D:\\TC\\BGI"); //initializing graphics window
printf("\nEnter the co-ordinates of the centre of the circle(xc,yc): \n");
scanf("%d%d",&xc,&yc); //Inputting center coordinates
printf("\nEnter the radius of the circle ,r:");
scanf("%d",&r); //Inputting circle radius
for(i=0;i<360;i++)
{
x=r*cos(i); //polar conversion
y=r*sin(i);
circleplot(xc,yc,x,y); //calling circleplot() function
}
boundaryfill4(xc,yc,1,12); //calling boundaryfill4() function
getch();
}
circleplot(int xa,int ya,int x,int y) //function to plot circle
{
putpixel((xa+x),(ya+y),12); //plotting the point
return(0);
}
boundaryfill4(int x,int y,int fillcolor,int bdycolor) //function for filling polygon
{
int ct=getpixel(x,y); //get pixel color
if((ct!=bdycolor)&&(ct!=fillcolor)) //if not already filled
{
putpixel(x,y,fillcolor); //plotting the point
boundaryfill4(x+1,y,fillcolor,bdycolor);
boundaryfill4(x-1,y,fillcolor,bdycolor);
boundaryfill4(x,y+1,fillcolor,bdycolor); //filling neighboring pixels
boundaryfill4(x,y-1,fillcolor,bdycolor);
}
return(0);
}
0 comments:
Post a Comment