Repository navigation
Expand file tree
/
Copy pathCG_Lab6_Bresenham_Circle_UserInput.cpp
More file actions
86 lines (70 loc) · 1.77 KB
/
Copy pathCG_Lab6_Bresenham_Circle_UserInput.cpp
File metadata and controls
86 lines (70 loc) · 1.77 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>
/* Draw a thick pixel (3x3) */
void thickPixel(int x, int y, int color)
{
int i, j;
for(i = -1; i <= 1; i++)
{
for(j = -1; j <= 1; j++)
{
putpixel(x + i, y + j, color);
}
}
}
/* Plot 8 symmetric points with different colors */
void symmetry(int xc, int yc, int x, int y)
{
thickPixel(xc + x, yc + y, RED); // Octant 1 - (x, y)
thickPixel(xc + y, yc + x, GREEN); // Octant 2 - (y, x)
thickPixel(xc - y, yc + x, BLUE); // Octant 3 - (-y, x)
thickPixel(xc - x, yc + y, CYAN); // Octant 4 - (-x, y)
thickPixel(xc - x, yc - y, MAGENTA); // Octant 5 - (-x, -y)
thickPixel(xc - y, yc - x, YELLOW); // Octant 6 - (-y, -x)
thickPixel(xc + y, yc - x, BROWN); // Octant 7 - (y, -x)
thickPixel(xc + x, yc - y, WHITE); // Octant 8 - (x, -y)
}
void drawCircle(int xc, int yc, int R)
{
int x = 0;
int y = R;
int d = 1 - R;
symmetry(xc, yc, x, y);
while(y > x)
{
if(d < 0)
{
d = d + 2 * x + 3;
x++;
}
else
{
d = d + 2 * x - 2 * y + 5;
x++;
y--;
}
symmetry(xc, yc, x, y);
delay(20);
}
}
int main()
{
int gd = DETECT, gm;
int xc, yc, R;
printf("Enter Center X : ");
scanf("%d", &xc);
printf("Enter Center Y : ");
scanf("%d", &yc);
printf("Enter Radius : ");
scanf("%d", &R);
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
setbkcolor(BLACK);
cleardevice();
drawCircle(xc, yc, R);
outtextxy(10, 10, "8-Coloured Midpoint Circle Drawing Algorithm");
getch();
closegraph();
return 0;
}