/* Program to draw a circle using bresenham’s method */
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
void plot8pixels(int,int,int,int);
void main()
{
int x,y,r,h,k,p;
cout<<“\n\t\t\t\**circle using Bresenham’s method**\n”;
cout<<“\nenter the x and y coordinates:-\n”;
cin>>h>>k;
cout<<“\nenter the radius:-\n”;
cin>>r;
x=0;
y=r;
p=3-(2*r);
int gd=DETECT,gm;
initgraph(&gd,&gm,””);
setbkcolor(WHITE);
while(x<=y)
{
plot8pixels(x,y,h,k);
if(p>=0)
{
p+=4*(x-y)+10;
y–;
}
else
p+=(4*x)+6;
x++;
}
setcolor(8);
outtextxy(115,70,”Circle using Bresenham’s method”);
getch();
closegraph();
}
void plot8pixels(int x,int y,int h,int k)
{
putpixel(x+h,y+k,8);
putpixel(x+h,-y+k,8);
putpixel(-x+h,y+k,8);
putpixel(-x+h,-y+k,8);
putpixel(y+h,x+k,8);
putpixel(y+h,-x+k,8);
putpixel(-y+h,x+k,8);
putpixel(-y+h,-x+k,8);
}