-
Notifications
You must be signed in to change notification settings - Fork 0
/
midpoint_circle.c
64 lines (64 loc) · 1.09 KB
/
midpoint_circle.c
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
// Mid point circle code in CG(Computer Graphics) In C
#include<GL/glut.h>
#include <stdio.h>
#include <math.h>
double r;
void Circle(void)
{
int pko,pk;
int x,y,xk1,yk1;
pko=(1-r);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
pk=pko;
x=0;
y=r;
while(x<=y)
{
if(pk>=0)
{
xk1=x+1;
yk1=y-1;
}
else
{
xk1=x+1;
yk1=y;
}
glVertex2d(x,y);
glVertex2d(-x,y);
glVertex2d(x,-y);
glVertex2d(-x,-y);
glVertex2d(y,x);
glVertex2d(-y,x);
glVertex2d(y,-x);
glVertex2d(-y,-x);
printf("(%d %d) ",x,y);
pko=pk;
pk = pko+2*(x+1)+(yk1*yk1-y*y)-(yk1-y)+1;
x=xk1;
y=yk1;
}
glEnd();
glFlush();
}
void Init()
{
glClearColor(1.0,1.0,1.0,0);
glColor3f(1.0,0.0,0.0);
gluOrtho2D(-100 , 100 , -100 , 100);
}
void main(int argc, char **argv)
{
printf("Enter radius of circle to be drawn:\n");
printf("\nEnter radius:\n");
scanf("%lf",&r);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(640,640);
glutCreateWindow("Mid Point Circle");
Init();
glutDisplayFunc(Circle);
glutMainLoop();
}