forked from sunnyshahabuddin/Coding-Ninjas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle.cpp
More file actions
77 lines (76 loc) · 1.32 KB
/
circle.cpp
File metadata and controls
77 lines (76 loc) · 1.32 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
#include<GL/glut.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
using namespace std;
int pntX1, pntY1, r;
void plot(int x, int y)
{
glBegin(GL_POINTS);
glVertex2i(x + pntX1, y + pntY1);
glEnd();
}
void myInit(void)
{
glClearColor(0.2, 0.3, 0.4, 0.5);
glColor3f(0.5f, 0.6f, 0.7f);
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.5, 0.2, 0.7);
glPointSize(1.0);
midPointCircleAlgo();
glFlush();
}
int main(int argc, char** argv)
{
cout << "Enter the center's coordinates:" << endl;
cout << "X-coordinate:";
cin >> pntX1;
cout << "\nY-coordinate:";
cin >> pntY1;
cout << "\nEnter radius:";
cin >> r;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 150);
glutCreateWindow("Circle Mid Point Alogrithm");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}