-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIDPOINT.C
52 lines (50 loc) · 1.08 KB
/
MIDPOINT.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
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void midPointCircleDraw(int x_centre, int y_centre, int r)
{
int x = r, y = 0,P;
if (r > 0)
{
putpixel(x+x_centre,-y+y_centre,WHITE);
putpixel(y+x_centre,x+y_centre,WHITE);
putpixel(-y+x_centre,x+y_centre,WHITE);
}
P = 1 - r;
while (x > y)
{
y++;
if (P <= 0)
P = P + 2*y + 1;
else
{
x--;
P = P + 2*y - 2*x + 1;
}
if (x < y)
break;
putpixel(x+x_centre,y+y_centre,BLUE);
putpixel(-x+x_centre,y+y_centre,BLUE);
putpixel(x+x_centre,-y+y_centre,BLUE);
putpixel(-x+x_centre,-y+y_centre,BLUE);
if (x != y)
{
putpixel(y+x_centre,x+y_centre,RED);
putpixel(-y+x_centre,x+y_centre,RED);
putpixel(y+x_centre,-x+y_centre,RED);
putpixel(-y+x_centre,-x+y_centre,RED);
}
}
}
int main()
{
int gd = DETECT, gm;
initgraph (&gd, &gm, "C:\\Turboc3\\BGI");
clrscr();
midPointCircleDraw(200,200, 50);
midPointCircleDraw(200,200,100);
midPointCircleDraw(200,200,150);
getch();
return 0;
}