-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5. bresenham circle.cpp
92 lines (76 loc) · 1.88 KB
/
5. bresenham circle.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
89
90
91
92
#include<GL/freeglut.h>
#include<GL/gl.h>
#include<iostream>
#include<math.h>
#include<cstdlib>
using namespace std;
typedef struct Point
{
int x;
int y;
}Point;
int radius;
void init()
{
glClearColor(0.0 , 0.0 , 0.0 , 1.0);
glColor3f(1.0 , 1.0 ,1.0);
glPointSize(3.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0 , 1204.0 , 0.0 , 764.0);
}
void drawCircle(int r , int cx , int cy)
{
Point p;
p.x = 0;
p.y = r;
glColor3f(0.0 , 1.0 , 0.0);
glBegin(GL_POINTS);
float Pi= 3 - 2 *r;
while(p.x <= p.y)
{
if(Pi < 0)
{
p.x++;
Pi += 4 * p.x + 6;
}else
{
p.x++;
p.y--;
Pi += 4 *(p.x - p.y) + 16;
}
glVertex2i (cx + p.x , cy + p.y);
glVertex2i (cx + p.y , cy + p.x);
glVertex2i (cx + p.y , cy - p.x);
glVertex2i (cx + p.x , cy - p.y);
glVertex2i (cx - p.x , cy - p.y);
glVertex2i (cx - p.y , cy - p.x);
glVertex2i (cx - p.y , cy + p.x);
glVertex2i (cx - p.x , cy + p.y);
}
glEnd();
}
void start()
{
init();
Point Max;
Max.x = glutGet(GLUT_WINDOW_WIDTH);
Max.y = glutGet(GLUT_WINDOW_HEIGHT);
Point Origin;
Origin.x = Max.x/2;
Origin.y = Max.y/2;
drawCircle(radius , Origin.x , Origin.y);
glFlush();
}
int main(int argc , char **argv)
{
cout<<"\nEnter Radius of Circle:";
cin>>radius;
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1204 , 764);
glutInitWindowPosition(0,0);
int winid = glutCreateWindow("OPenGL - CReating a Circle");
glutDisplayFunc(start);
glutMainLoop();
return 0;
}