-
Notifications
You must be signed in to change notification settings - Fork 4
/
circle.c
52 lines (50 loc) · 1.28 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
#include "graphics_utils.h"
void drawCircle(int xc, int yc, int x, int y)
{
drawPixel(xc+x, yc+y);
drawPixel(xc-x, yc+y);
drawPixel(xc+x, yc-y);
drawPixel(xc-x, yc-y);
drawPixel(xc+y, yc+x);
drawPixel(xc-y, yc+x);
drawPixel(xc+y, yc-x);
drawPixel(xc-y, yc-x);
}
// Function for circle-generation
// using Bresenham's algorithm
void circleBres(int xc, int yc, int r)
{
int x = 0, y = r;
int d = 3 - 2 * r;
while (y >= x)
{
// for each pixel we will
// draw all eight pixels
drawCircle(xc, yc, x, y);
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(200);
}
}
// driver function
int main()
{
int xc = 0, yc = 0, r2 = 15;
initialiseGraph();
grid();
delay(5000);
circleBres(xc, yc, r2);
delay(1000000);
closegraph();
return 0;
}