C++ PROGRAM TO IMPLEMENT CIRCLE WITH GRAPHICS
CODE:
//Implementation
of circle in computer graphics using c++
//created
by Abhijt, 10/11/2020
#include<graphics.h>
#include<stdio.h>
//defining
pixel function to color pixels
void
pixel(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,WHITE);
putpixel(xc+x,yc-y,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-y,yc+x,WHITE);
putpixel(xc-y,yc-x,WHITE);
}
//driver
code
int main()
{
int gd,gm,xc,yc,r,x,y,p;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C://TurboC3//BGI");
printf("Enter center of
circle :");
scanf("%d%d",&xc,&yc);
printf("Enter radius of
circle :");
scanf("%d",&r);
x=0;
y=r;
p=1-r;
pixel(xc,yc,x,y);
while(x<y)
{
if(p<0)
{
x+=1;
p=p+2*x+1;
}
else
{
x+=1;
y-=1;
p=p+2*(x-y)+1;
}
pixel(xc,yc,x,y);
}
getch();
closegraph();
return 0;
}
INPUT:
Enter center of circle :200 200
Enter radius of circle :100
OUTPUT:
Comments
Post a Comment