-
Notifications
You must be signed in to change notification settings - Fork 0
/
brezenham_ellipsis.c
76 lines (71 loc) · 1.79 KB
/
brezenham_ellipsis.c
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
70
71
72
73
74
75
76
#include <conio.h>
#include <stdlib.h>
void putpixel(unsigned int X,unsigned int Y,unsigned char Color)
{
asm {
mov ax, [Y]
mov dx, 320
imul dx
add ax, [X]
mov di, ax
push es
mov ax, 0xA000
mov es, ax
mov al,[Color]
stosb
pop es
}
}
void ellipse(int x, int y, int a, int b, int color)
{
int col, i, row, bnew;
long a_square, b_square, two_a_square, two_b_square, four_a_square, four_b_square,d;
b_square = b * b;
a_square = a * a;
row = b;
col = 0;
two_a_square = a_square << 1;
four_a_square = a_square << 2;
four_b_square = b_square << 2;
two_b_square = b_square << 1;
d = two_a_square * ((row - 1) * (row)) + a_square + two_b_square * (1 - a_square);
while (a_square * (row) > b_square * (col)) {
putpixel(col + x, row + y, color);
putpixel(col + x, y - row, color);
putpixel(x - col, row + y, color);
putpixel(x - col,y - row, color);
if (d >= 0) {
row--;
d -= four_a_square * (row);
}
d += two_b_square * (3 + (col << 1));
col++;
}
d = two_b_square * (col + 1) * col + two_a_square * (row * (row - 2) + 1) + (1 - two_a_square) * b_square;
while ((row) + 1) {
putpixel(col + x, row + y, color);
putpixel(col + x, y - row, color);
putpixel(x - col, row + y, color);
putpixel(x - col, y - row, color);
if (d <= 0) {
col++;
d += four_b_square * col;
}
row--;
d += two_a_square * (3 - (row << 1));
}
}
void main(void)
{
int X,Y;
asm mov ax,0x0013
asm int 0x10
while (!kbhit()) putpixel(random(320),random(200),random(255));
getch();
while (!kbhit()) {
X = 50 + random(220);
Y = 50 + random(100);
ellipse(X, Y, 1 + random(48), 1 + random(48), random(255));
}
getch();
}