#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<iostream.h>
#include<dos.h>
void bfill(int x,int y,int a);
void ffill(int x,int y,int a);
void main()
{
/* request auto detection */
int gdriver = DETECT, gmode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI");
/*Initialize the variables and accept data*/
int r,xc,yc,x,y,p;
cout<<"Enter the radius:";
cin>>r;
cout<<"Enter the center co-ordinates:";
cin>>xc>>yc;
x=0;
y=r;
p=1-r;
/*Calculate and plot the points*/
do
{
putpixel(xc+x,yc+y,WHITE);
putpixel(xc+y,yc+x,WHITE);
putpixel(xc-y,yc+x,WHITE);
putpixel(xc+x,yc-y,WHITE);
putpixel(xc-x,yc-y,WHITE);
putpixel(xc-y,yc-x,WHITE);
putpixel(xc+y,yc-x,WHITE);
putpixel(xc-x,yc+y,WHITE);
if(p<0)
{
x=x+1;
y=y;
p=p+(2*x)+1;
}
else
{
x=x+1;
y=y-1;
p=p+(2*x)+1-(2*y);
}
}
while(x<=y);
//start boundary filling
bfill(xc,yc,4);
ffill(xc,yc,6);
/* clean up */
getch();
}
void bfill(int x,int y,int a)
{int current;
current=getpixel(x,y);
if((current!=a)&&(current!=WHITE))
{
putpixel(x,y,a);
delay(5);
bfill(x+1,y,a);
bfill(x-1,y,a);
bfill(x,y+1,a);
bfill(x,y-1,a);
}
}
void ffill(int x,int y,int a)
{int current;
current=getpixel(x,y);
if((current!=a)&&(current==4))
{
putpixel(x,y,a);
delay(5);
ffill(x+1,y,a);
ffill(x-1,y,a);
ffill(x,y+1,a);
ffill(x,y-1,a);
}
}
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<iostream.h>
#include<dos.h>
void bfill(int x,int y,int a);
void ffill(int x,int y,int a);
void main()
{
/* request auto detection */
int gdriver = DETECT, gmode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI");
/*Initialize the variables and accept data*/
int r,xc,yc,x,y,p;
cout<<"Enter the radius:";
cin>>r;
cout<<"Enter the center co-ordinates:";
cin>>xc>>yc;
x=0;
y=r;
p=1-r;
/*Calculate and plot the points*/
do
{
putpixel(xc+x,yc+y,WHITE);
putpixel(xc+y,yc+x,WHITE);
putpixel(xc-y,yc+x,WHITE);
putpixel(xc+x,yc-y,WHITE);
putpixel(xc-x,yc-y,WHITE);
putpixel(xc-y,yc-x,WHITE);
putpixel(xc+y,yc-x,WHITE);
putpixel(xc-x,yc+y,WHITE);
if(p<0)
{
x=x+1;
y=y;
p=p+(2*x)+1;
}
else
{
x=x+1;
y=y-1;
p=p+(2*x)+1-(2*y);
}
}
while(x<=y);
//start boundary filling
bfill(xc,yc,4);
ffill(xc,yc,6);
/* clean up */
getch();
}
void bfill(int x,int y,int a)
{int current;
current=getpixel(x,y);
if((current!=a)&&(current!=WHITE))
{
putpixel(x,y,a);
delay(5);
bfill(x+1,y,a);
bfill(x-1,y,a);
bfill(x,y+1,a);
bfill(x,y-1,a);
}
}
void ffill(int x,int y,int a)
{int current;
current=getpixel(x,y);
if((current!=a)&&(current==4))
{
putpixel(x,y,a);
delay(5);
ffill(x+1,y,a);
ffill(x-1,y,a);
ffill(x,y+1,a);
ffill(x,y-1,a);
}
}
No comments:
Post a Comment