forked from DPrinceKumar/HacktoberFest2020-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbresenhams_circle_drawing_algorithm.cpp
57 lines (54 loc) · 1.06 KB
/
bresenhams_circle_drawing_algorithm.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
// C++ Implementation for drawing line
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <iostream.h>
void plotCircle(int xc, int yc, int x, int y)
{
putpixel(xc + x, yc + y, WHITE);
putpixel(xc - x, yc + y, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc - x, yc - y, WHITE);
putpixel(xc + y, yc + x, WHITE);
putpixel(xc - y, yc + x, WHITE);
putpixel(xc + y, yc - x, WHITE);
putpixel(xc - y, yc - x, WHITE);
}
void circle()
{
int Xc, Yc, R, D, X, Y;
cout << "Enter Coordinates of centre of circle : ";
cin >> Xc >> Yc;
cout << "Enter the Radius of Circle : ";
cin >> R;
D = 3 - 2 * R;
X = 0;
Y = R;
plotCircle(Xc, Yc, X, Y);
while (X < Y)
{
if (D < 0)
{
D = D + 4 * X + 6;
X = X + 1;
Y = Y;
}
else
{
D = D + 4 * X - 4 * Y + 10;
X = X + 1;
Y = Y - 1;
};
plotCircle(Xc, Yc, X, Y);
}
}
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\turboc3\\bgi");
circle();
getch();
closegraph();
return 0;
}