/*CSEMATTER.BLOGSPOT.IN
PROGRAM-TO IMPLELMENT BOUNDARY FILL ALGORITHM*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void colouring(int,int,int,int,int);
int main()
{
int gd=DETECT,gm,x,y,a=0,b=0,c,tempx,tempy,left,right,top,bottom;
initgraph(&gd,&gm,"C:\TC\BGI");
printf("Enter the left, top, right & bottom coordinates of rectangle: ");
scanf("%d %d %d %d",&left,&top,&right,&bottom);
rectangle(left,top,right,bottom);
printf("Enter the corresponding code of color to be filled");
scanf("%d",&c);
tempx=(right-left)/2;
tempy=(bottom-top)/2;
x=tempx+left;
y=tempy+top;
printf("%d %d",x,y);
while(a!=tempx | b!=tempy)
{printf("%d %d\n",a,b);
colouring(x,y,a,b,c);
if(a<=tempx)
a++;
if(b<=tempy)
b++;
}
getch();
closegraph();
}
void colouring(int x,int y,int a,int b,int c)
{
int i,j;
for(i=0; i<=a; i++)
{
for(j=0; j<=b; j++)
{
putpixel(x,y,c);
putpixel(x-i,y,c);
putpixel(x+i,y,c);
putpixel(x,y-j,c);
putpixel(x,y+j,c);
putpixel(x-i,y-j,c);
putpixel(x-i,y+j,c);
putpixel(x+i,y-j,c);
putpixel(x+i,y+j,c);
}
}
}
No comments:
Post a Comment