#include<stdio.h>
#include <graphics.h>
#include <conio.h>
#include<math.h>
void main()
{
int gdriver = DETECT, gmode;
int p,x,y;
int xc,yc,r;
initgraph(&gdriver,&gmode,"c:/tc/bgi");
printf("Enter the origin of circle(xc,yc)=");
scanf("%d %d",&xc,&yc);
printf("\nEnter the radius of the circle=");
scanf("%d",&r);
x=0;
y=r;
putpixel(xc+x,yc+y,1);
putpixel(xc-x,yc+y,1);
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,1);
putpixel(xc+y,yc+x,1);
putpixel(xc-y,yc+x,1);
putpixel(xc+y,yc-x,1);
putpixel(xc-y,yc-x,1);
p=1-r;
while(x<y)
{
if (p<0)
x++;
else
{
x++;
y--;
}
if(p<0)
p=p+2*x+1;
else
p=p+2*(x-y)+1;
putpixel(xc+x,yc+y,1);
putpixel(xc-x,yc+y,1);
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,1);
putpixel(xc+y,yc+x,1);
putpixel(xc-y,yc+x,1);
putpixel(xc+y,yc-x,1);
putpixel(xc-y,yc-x,1);
}
getch();
}
#include <graphics.h>
#include <conio.h>
#include<math.h>
void main()
{
int gdriver = DETECT, gmode;
int p,x,y;
int xc,yc,r;
initgraph(&gdriver,&gmode,"c:/tc/bgi");
printf("Enter the origin of circle(xc,yc)=");
scanf("%d %d",&xc,&yc);
printf("\nEnter the radius of the circle=");
scanf("%d",&r);
x=0;
y=r;
putpixel(xc+x,yc+y,1);
putpixel(xc-x,yc+y,1);
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,1);
putpixel(xc+y,yc+x,1);
putpixel(xc-y,yc+x,1);
putpixel(xc+y,yc-x,1);
putpixel(xc-y,yc-x,1);
p=1-r;
while(x<y)
{
if (p<0)
x++;
else
{
x++;
y--;
}
if(p<0)
p=p+2*x+1;
else
p=p+2*(x-y)+1;
putpixel(xc+x,yc+y,1);
putpixel(xc-x,yc+y,1);
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,1);
putpixel(xc+y,yc+x,1);
putpixel(xc-y,yc+x,1);
putpixel(xc+y,yc-x,1);
putpixel(xc-y,yc-x,1);
}
getch();
}
No comments:
Post a Comment