# Bbresenham Midpoint Ellipse Algotithm

Complete Bbresenham Midpoint Ellipse Algotithm

# include<stdio.h>
# include<conio.h>
# include<math.h>
# include <graphics.h>
int xcentre, ycentre, rx, ry;
int p,px,py,x,y,rx2,ry2,tworx2,twory2;
void drawelipse();
void main()
{
int gd=3,gm=1;
clscr();
initgraph(&gd,&gm,””);
printf(“n Enter X center value: “);
scanf(“%d”,&xcentre);
printf(“n Enter Y center value: “);
scanf(“%d”,&ycentre);
printf(“n Enter X redius value: “);
scanf(“%d”,&rx);
printf(“n Enter Y redius value: “);
scanf(“%d”,&ry);
cleardevice();
ry2=ry*ry;
rx2=rx*rx;
twory2=2*ry2;
tworx2=2*rx2;
/* REGION first */
x=0;
y=ry;
drawelipse();
p=(ry2-rx2*ry+(0.25*rx2));
px=0;
py=tworx2*y;
while(px<py)
{
x++;
px=px+twory2;
if(p>=0)
{

y=y-1;
py=py-tworx2;
}
if(p<0)
p=p+ry2+px;
else
{
p=p+ry2+px-py;
drawelipse();
}
}
/*REGION second*/
p=(ry2*(x+0.5)*(x+0.5)+rx2*(y-1)*(y-1)-rx2*ry2);
while(y>0)
{
y=y-1:
py=py-tworx2;
if(p<=0)
{
x++;
px =px + twory2;
}
if(p >0)
p=p+rx2-py;
else
{
p=p+rx2-py+px;
drawelipse();
}
}
getch();
closegraph();
}
void drawelipse()
{
Putpixel (xcenter +x, ycenter +y, BROWN);
putpixel (xcenter +x, ycenter +y, BROWN);
putpixel (xcenter +x, ycenter +y, BROWN);
putpixel (xcenter +x, ycenter +y, BROWN);
}