-
Notifications
You must be signed in to change notification settings - Fork 2
/
CIRCLE.C
64 lines (54 loc) · 1.05 KB
/
CIRCLE.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
#include <dos.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
int setaspect();
int plot();
int plot8();
int glcircle();
int xcenter,ycenter;
unsigned xaspect,yaspect;
extern int MaxX,MaxY;
main()
{
int i;
grafinit(VGA,VGAHI); /* INITIALIZE THE GRAPHICS */
cleardevice();
while (!kbhit()) glcircle(random(MaxX),random(MaxY),random(50));
}
int glcircle (xpos,ypos,radius)
int xpos;
int ypos;
int radius;
{
int x,y,sum;
xcenter = xpos;
ycenter = ypos;
x = 0;
y = radius << 1;
sum = 0;
while (x<=y)
{
if (x & 1) plot8(x>>1,(y+1)>>1); /* Plot if x is odd */
sum += (x<<1)+1;
x++;
if (sum>0)
{
sum -= (y<<1)-1;
y--;
}
}
}
int plot8(int x, int y)
{
putpixel(x+xcenter,y+ycenter,CYAN);
putpixel(x+xcenter,ycenter-y,CYAN);
putpixel(xcenter-x,y+ycenter,CYAN);
putpixel(xcenter-x,ycenter-y,CYAN);
putpixel(y+xcenter,x+ycenter,CYAN);
putpixel(y+xcenter,ycenter-x,CYAN);
putpixel(xcenter-y,x+ycenter,CYAN);
putpixel(xcenter-y,ycenter-x,CYAN);
}