FLOODFILL AND BOUNDARYFILL PROGRAM IN C USING SWITCH CASE.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void floodFill();
void boundaryfill();
int x,y;
void main()
{
int gm,gd=DETECT,radius;
int ch;
clrscr();
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
do
{
printf("\n Enter your choice:");
printf("\n1.Floodfill\n2.Boundaryfill\n3.exit:");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter x and y positions for circle\n");
scanf("%d%d",&x,&y);
printf("Enter radius of circle\n");
scanf("%d",&radius);
circle(x,y,radius);
floodFill(x,y,0,15);
delay(5000);
getch();
closegraph();
break;
case 2: printf("Enter x and y positions for circle\n");
scanf("%d%d",&x,&y);
printf("Enter radius of circle\n");
scanf("%d",&radius);
circle(x,y,radius);
boundaryfill(x,y,4,15);
delay(5000);
getch();
closegraph();
break;
case 3: exit(0);
break;
default: printf("\n Please enter valid choice:");
}
}while(ch!=3);
}
void floodFill(int x,int y, int oldcolor,int newcolor)
{
if(getpixel(x,y) == oldcolor)
{
putpixel(x,y,newcolor);
floodFill(x+1,y,oldcolor,newcolor);
floodFill(x,y+1,oldcolor,newcolor);
floodFill(x-1,y,oldcolor,newcolor);
floodFill(x,y-1,oldcolor,newcolor);
}
}
void boundaryfill(int x,int y,int f_color,int b_color)
{
if(getpixel(x,y)!=b_color && getpixel(x,y)!=f_color)
{
putpixel(x,y,f_color);
boundaryfill(x+1,y,f_color,b_color);
boundaryfill(x,y+1,f_color,b_color);
boundaryfill(x-1,y,f_color,b_color);
boundaryfill(x,y-1,f_color,b_color);
}
}
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void floodFill();
void boundaryfill();
int x,y;
void main()
{
int gm,gd=DETECT,radius;
int ch;
clrscr();
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
do
{
printf("\n Enter your choice:");
printf("\n1.Floodfill\n2.Boundaryfill\n3.exit:");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter x and y positions for circle\n");
scanf("%d%d",&x,&y);
printf("Enter radius of circle\n");
scanf("%d",&radius);
circle(x,y,radius);
floodFill(x,y,0,15);
delay(5000);
getch();
closegraph();
break;
case 2: printf("Enter x and y positions for circle\n");
scanf("%d%d",&x,&y);
printf("Enter radius of circle\n");
scanf("%d",&radius);
circle(x,y,radius);
boundaryfill(x,y,4,15);
delay(5000);
getch();
closegraph();
break;
case 3: exit(0);
break;
default: printf("\n Please enter valid choice:");
}
}while(ch!=3);
}
void floodFill(int x,int y, int oldcolor,int newcolor)
{
if(getpixel(x,y) == oldcolor)
{
putpixel(x,y,newcolor);
floodFill(x+1,y,oldcolor,newcolor);
floodFill(x,y+1,oldcolor,newcolor);
floodFill(x-1,y,oldcolor,newcolor);
floodFill(x,y-1,oldcolor,newcolor);
}
}
void boundaryfill(int x,int y,int f_color,int b_color)
{
if(getpixel(x,y)!=b_color && getpixel(x,y)!=f_color)
{
putpixel(x,y,f_color);
boundaryfill(x+1,y,f_color,b_color);
boundaryfill(x,y+1,f_color,b_color);
boundaryfill(x-1,y,f_color,b_color);
boundaryfill(x,y-1,f_color,b_color);
}
}
OUTPUT:-
1} FLOODFILL
2} BOUNDARYFILL
No comments:
Post a Comment