#include<conio.h>
#include<stdio.h>
#include<Graphics.h>
void main() {
int gd = DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
int xc,yc,x,y;
long rx,ry;
float d;
printf("Enter Coordinates of Centre of Ellipse: ");
scanf("%d%d",&xc,&yc);
printf("Enter Radius along X-AXIS: ");
scanf("%ld",&rx);
printf("Enter Radius along Y-AXIS: ");
scanf("%ld",&ry);
//Region 1
d=((ry*ry)-(rx*rx*ry)+(rx*rx))/4;
x=0; y=ry;
while(2.0*ry*ry*x < = 2.0*rx*rx*y)
{
if(d < 0)
{
x++;
d = d+(2*ry*ry*x)+(ry*ry);
}
else
{
x++;y--;
d = d+(2*ry*ry*x)-(2*rx*rx*y)-(ry*ry);
}
putpixel(xc+x,yc+y,15);
putpixel(xc+x,yc-y,15);
putpixel(xc-x,yc+y,15);
putpixel(xc-x,yc-y,15);
}
//Region 2
d =ry*ry*(x+0.5)*(x+0.5) + (rx*rx*(y-1)*(y-1)) - (rx*rx*ry*ry);
while(y > 0)
{
if(d<= 0)
{
x++; y--;
d = d + (2*ry*ry*x) - (2*rx*rx*y) + (rx*rx);
}
else
{
y--;
d = d - (2*rx*rx*y) + (rx*rx);
}
putpixel (xc+x,yc+y, 15 );
putpixel (xc+x,yc-y, 15 );
putpixel (xc-x,yc+y, 15 );
putpixel (xc-x,yc-y, 15 );
}
getch();
closegraph();
}
Total education solutions
ReplyDeleteAwesome explanation of the midpoint algorithm for drawing ellipses! Tools like GodMode9 can really aid in managing C++ programming tasks.
ReplyDelete