0% found this document useful (0 votes)
174 views

Ellipse

This C program draws an ellipse on the screen using the Bresenham's algorithm. It takes the major and minor axes of the ellipse as input from the user. It then uses a set of conditions to determine the pixel coordinates along the ellipse and calls a draw function to plot these points on the screen to render the ellipse shape.

Uploaded by

Varshini Varsha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
174 views

Ellipse

This C program draws an ellipse on the screen using the Bresenham's algorithm. It takes the major and minor axes of the ellipse as input from the user. It then uses a set of conditions to determine the pixel coordinates along the ellipse and calls a draw function to plot these points on the screen to render the ellipse shape.

Uploaded by

Varshini Varsha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

SOURCE CODE :

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void draw(int x,int y);
void main()
{
int gdriver=DETECT,gmode;
int max,min,x,y;
long s1,s2,p,q;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI\\");
printf("\n\nEnter the major axis :");
scanf("%d",&max);
printf("\nEnter the minor axis :");
scanf("%d",&min);
x=0;
y=min;
s1=pow(min,2);
s2=pow(max,2);
p=(s1-(s2*min)+(.25*s2));
draw(x,y);
while(s2*(y-0.5)>s1*(x+1))
{
x++;
if(p<0)
p=(p+s1*(2*x+3));
else
{
p=(p+s1*(2*x+3)+s2*(-2*y+2));
y--;
}
draw(x,y);
}
q=s1*pow((x+0.5),2)+s2*pow((y-1),2)-s1*s2;
while(y>0)
{
if(q<0)
{
q=q+s1*(2*x+2)+s2*(-2*y+3);

x++;
}
else
q=q+s2*(-2*y+3);
y--;
draw(x,y);
}
getch();
closegraph();
}
void draw(int x,int y)
{
putpixel(x+200,y+200,7);
putpixel(-x+200,y+200,7);
putpixel(x+200,-y+200,7);
putpixel(-x+200,-y+200,7);
}

OUTPUT:
Enter the Major Axis :100
Enter the Minor Axis :50

You might also like