forked from koolkarthik97/Graphics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EllipseMidPoint.cpp~
64 lines (61 loc) · 1.4 KB
/
EllipseMidPoint.cpp~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void ellipse(int xc, int yc, int rx, int ry)
{
int gm= DETECT, gd;
int x,y,p;
// clrscr();
initgraph(&gm, &gd, "C:\\TC\\BGI");
x=0;
y=ry;
p = (ry*ry) - (rx*rx*ry) + ((rx*rx)/4);
while((2*x*ry*ry) < (2*y*rx*rx))
{
putpixel(xc+x,yc-y,WHITE);
putpixel(xc-x,yc+y,WHITE);
putpixel(xc+x,yc+y,WHITE);
putpixel(xc-x,yc-y,WHITE);
if(p<0)
{
x++;
p += (2*ry*ry*x) +(ry*ry);
}
else
{
x++;
y--;
p += (2*ry*ry*x + ry*ry) - (2*rx*rx*y);
}
}
p = ((float)x+0.5)*((float)x+0.5)*ry*ry + ((y-1)*(y-1)*rx*rx) - (rx*rx*ry*ry);
while(y>=0)
{
putpixel(xc+x,yc-y,WHITE);
putpixel(xc-x,yc+y,WHITE);
putpixel(xc+x,yc+y,WHITE);
putpixel(xc-x,yc-y,WHITE);
if(p>0)
{
y--;
p-=(2*rx*rx*y) + (rx*rx);
}
else
{
y--;
x++;
p+=(2*ry*ry*x) - (2*rx*rx*y) - (rx*rx);
}
}
getch();
closegraph();
}
int main1()
{
int xc,yc,rx,ry;
printf("Enter center, x axis and y axis");
scanf("%d%d%d%d",&xc,&yc,&rx,&ry);
ellipse(xc,yc,rx,ry);
getch();
return 0;
}