#include
#include
#include
#include
#include
#include
#include
#include
int convertx(int k)
{
return(320+k);
}
int converty(int k)
{
return(240-k);
}
int convertxc(int k)
{
return(320+k);
}
int convertyc(int k)
{
return(240-k);
}
void axis();
int circlemid(int,int,int);
void plotpoint();
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc1\\bgi");
float xc,yc;
float r;
while(1)
{
cout<<"\n Enter The Center Of The Circle : ";
cin>>xc>>yc;
cout<<"\n Enter the Radius Of The Circle: ";
cin>>r;
circlemid(xc,yc,r);
cout<<"\n Do you want to continue ('y' or 'Y') : ";
char c;
c=getch();
if(c=='y' || c=='Y')
break;
}
}
void axis()
{
setcolor(1);
line(320,0,320,480);
line(0,240,640,240);
}
void plotpoint(int xc,int yc,int x1,int y1)
{
delay(50);
putpixel(convertxc(xc)+x1,convertyc(yc)+y1,1);
putpixel(convertxc(xc)-x1,convertyc(yc)+y1,2);
putpixel(convertxc(xc)+x1,convertyc(yc)-y1,3);
putpixel(convertxc(xc)-x1,convertyc(yc)-y1,4);
putpixel(convertxc(xc)+y1,convertyc(yc)+x1,5);
putpixel(convertxc(xc)-y1,convertyc(yc)+x1,6);
putpixel(convertxc(xc)+y1,convertyc(yc)-x1,7);
putpixel(convertxc(xc)-y1,convertyc(yc)-x1,8);
}
int circlemid(int xc,int yc,int r)
{
int x,y;
x=0;
y=r;
axis();
putpixel(convertxc(xc),convertyc(yc),5);
plotpoint(xc,yc,x,y);
double p=1-r;
while(x
{
if(p<0)
{
x=x+1;
p=p+2*x+1;
}
else
{
x=x+1;
y=y-1;
p=p+2*(x-y)+1;
}
plotpoint(xc,yc,x,y);
}
return(0);
}
try to follow the code rules and try on your own for developing yous coding knowldge
2006-09-18 22:34:29
·
answer #2
·
answered by Guru 3
·
0⤊
0⤋