-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMid-point Ellipse.c
More file actions
69 lines (56 loc) · 1.61 KB
/
Mid-point Ellipse.c
File metadata and controls
69 lines (56 loc) · 1.61 KB
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
65
66
67
68
69
#include <stdio.h>
#include <graphics.h>
void main() {
long x, y, x_center, y_center;
long a_sqr, b_sqr, fx, fy, d, a, b, tmp1, tmp2;
int g_driver = DETECT, g_mode;
clrscr();
initgraph(&g_driver, &g_mode, "C:\\TURBOC3\\BGI");
printf("\nEnter coordinate x and y = ");
scanf("%ld%ld", &x_center, &y_center);
printf("\nEnter the 2 radiuses = ");
scanf("%ld%ld", &a, &b);
x = 0;
y = b;
a_sqr = a * a;
b_sqr = b * b;
fx = 2 * b_sqr * x;
fy = 2 * a_sqr * y;
d = b_sqr - (a_sqr * b) + (a_sqr * 0.25);
do {
putpixel(x_center + x, y_center + y, 1);
putpixel(x_center - x, y_center - y, 1);
putpixel(x_center + x, y_center - y, 1);
putpixel(x_center - x, y_center + y, 1);
if (d < 0) {
d = d + fx + b_sqr;
} else {
y = y - 1;
d = d + fx - fy + b_sqr;
fy = fy - (2 * a_sqr);
}
x = x + 1;
fx = fx + (2 * b_sqr);
delay(10);
} while (fx < fy);
tmp1 = (x + 0.5) * (x + 0.5);
tmp2 = (y - 1) * (y - 1);
d = b_sqr * tmp1 + a_sqr * tmp2 - (a_sqr * b_sqr);
do {
putpixel(x_center + x, y_center + y, 1);
putpixel(x_center - x, y_center - y, 1);
putpixel(x_center + x, y_center - y, 1);
putpixel(x_center - x, y_center + y, 1);
if (d >= 0) {
d = d - fy + a_sqr;
} else {
x = x + 1;
d = d + fx - fy + a_sqr;
fx = fx + (2 * b_sqr);
}
y = y - 1;
fy = fy - (2 * a_sqr);
} while (y > 0);
getch();
closegraph();
}