-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBresenham circle drawing algorithm.cpp
More file actions
68 lines (62 loc) · 1.53 KB
/
Bresenham circle drawing algorithm.cpp
File metadata and controls
68 lines (62 loc) · 1.53 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
/* C++ program for circle drawing
using Bresenham’s Algorithm
in computer-graphics */
#include <stdio.h>
#include <graphics.h>
/*Function to put pixels
at subsequence points*/
void drawCircle(int xc, int yc, int x, int y)
{
putpixel(xc+x, yc+y, RED);
putpixel(xc-x, yc+y, RED);
putpixel(xc+x, yc-y, RED);
putpixel(xc-x, yc-y, RED);
putpixel(xc+y, yc+x, RED);
putpixel(xc-y, yc+x, RED);
putpixel(xc+y, yc-x, RED);
putpixel(xc-y, yc-x, RED);
}
/*Function for circle-generation
using Bresenham's algorithm*/
void circleBres(float xc, int yc, int r)
{
int x = 0, y = r;
int d = 3 - 2 * r;
drawCircle(xc, yc, x, y);
while (y >= x)
{
/* for each pixel we will
draw all eight pixels */
x++;
/*check for decision parameter
and correspondingly
update d, x, y*/
if (d > 0)
{
y--;
d = d + 4 * (x - y) + 10;
}
else
d = d + 4 * x + 6;
drawCircle(xc, yc, x, y);
delay(50);
}
getch();
}
// Driver code
int main()
{
float xc,yc,r;
/*Getting User input */
printf("Enter the value of xc: ");
scanf("%f", &xc);
printf("Enter the value of yc: ");
scanf("%f", &yc);
printf("Enter the value of r: ");
scanf("%f", &r);
int gd = DETECT, gm;
initgraph(&gd, &gm, ""); // initialize graph
circleBres(xc, yc, r); // function call
system("cls");
return 0;
}