File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < GL/glut.h>
2+ #include < stdlib.h>
3+ #include < iostream>
4+ #include < math.h>
5+ using namespace std ;
6+ int pntX1, pntY1, r;
7+ void plot (int x, int y)
8+ {
9+ glBegin (GL_POINTS);
10+ glVertex2i (x + pntX1, y + pntY1);
11+ glEnd ();
12+ }
13+ void myInit (void )
14+ {
15+ glClearColor (0.2 , 0.3 , 0.4 , 0.5 );
16+ glColor3f (0 .5f , 0 .6f , 0 .7f );
17+ glPointSize (4.0 );
18+ glMatrixMode (GL_PROJECTION);
19+ glLoadIdentity ();
20+ gluOrtho2D (0.0 , 640.0 , 0.0 , 480.0 );
21+ }
22+ void midPointCircleAlgo ()
23+ {
24+ int x = 0 ;
25+ int y = r;
26+ float decision=5 /4 -r;
27+ plot (x,y);
28+ while (y>x)
29+ {
30+ if (decision<0 )
31+ {
32+ x++;
33+ decision += 2 * x + 1 ;
34+ }
35+ else
36+ {
37+ y--;
38+ x++;
39+ decision+=2 *(x-y)+1 ;
40+
41+ }
42+ plot (x,y);
43+ plot (x,-y);
44+ plot (-x,y);
45+ plot (-x,-y);
46+ plot (y,x);
47+ plot (-y,x);
48+ plot (y,-x);
49+ plot (-y,-x);
50+ }
51+ }
52+ void myDisplay (void )
53+ {
54+ glClear (GL_COLOR_BUFFER_BIT);
55+ glColor3f (0.5 , 0.2 , 0.7 );
56+ glPointSize (1.0 );
57+ midPointCircleAlgo ();
58+ glFlush ();
59+ }
60+ int main (int argc, char ** argv)
61+ {
62+ cout << " Enter the center's coordinates:" <<endl;
63+ cout << " X-coordinate:" ;
64+ cin>>pntX1;
65+ cout << " \n Y-coordinate:" ;
66+ cin>>pntY1;
67+ cout << " \n Enter radius:" ;
68+ cin>>r;
69+ glutInit (&argc, argv);
70+ glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
71+ glutInitWindowSize (640 , 480 );
72+ glutInitWindowPosition (100 , 150 );
73+ glutCreateWindow (" Circle Mid Point Alogrithm" );
74+ glutDisplayFunc (myDisplay);
75+ myInit ();
76+ glutMainLoop ();
77+ }
You can’t perform that action at this time.
0 commit comments