Draw a circle using mid point circle drawing algorithm in Second Order
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void bressCir(int);
void circlepoints(int, int);
void main()
{
int gdriver=DETECT, gmode, r;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
cleardevice();
printf("Enter the Radius : ");
scanf("%d",&r);
bressCir(r);
getch();
closegraph();
}
void bressCir(int r)
{
int x=0, y=r , d=1-r;
circlepoints(x,y);
while(x <= y)
{
if(d < 0)
d += 4*x + 3;
else
{
d += 4*(x-y) + 10;
y--;
}
x++;
circlepoints(x,y);
}
}
void circlepoints(int x, int y)
{
putpixel(319+x,239+y,11);
putpixel(319+x,239-y,11);
putpixel(319-x,239+y,11);
putpixel(319-x,239-y,11);
putpixel(319+y,239+x,11);
putpixel(319+y,239-x,11);
putpixel(319-y,239+x,11);
putpixel(319-y,239-x,11);
}