-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircle2.cpp
88 lines (71 loc) · 1.34 KB
/
Circle2.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
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
87
88
#include<windows.h>
#include <stdio.h>
#include <GL/glut.h>
int pntX1, pntY1, r;
void plot(int x, int y)
{
glBegin(GL_POINTS);
glVertex2i(x+pntX1, y+pntY1);
glEnd();
}
void myInit (void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void midPointCircleAlgo()
{
int x = 0;
int y = r;
float decision = 5/4 - r;
plot(x, y);
while (y > x)
{
if (decision < 0)
{
x++;
decision += 2*x+1;
}
else
{
y--;
x++;
decision += 2*(x-y)+1;
}
plot(x, y);
plot(x, -y);
plot(-x, y);
plot(-x, -y);
plot(y, x);
plot(-y, x);
plot(y, -x);
plot(-y, -x);
}
}
void myDisplay(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 0.0);
glPointSize(1.0);
midPointCircleAlgo();
glFlush ();
}
int main(int argc, char** argv)
{
printf("Enter the coordinates of the center:\n\n");
scanf("%d%d",&pntX1,&pntY1);
printf("Enter the radius\n");
scanf("%d",&r);
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (640, 480);
glutInitWindowPosition (100, 150);
glutCreateWindow ("Line Drawing Alogrithms");
glutDisplayFunc(myDisplay);
myInit ();
glutMainLoop();
}