-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mid Point Circle Drawing.c
66 lines (66 loc) · 1.29 KB
/
Mid Point Circle Drawing.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
65
66
#include<stdlib.h>
#include<stdio.h>
#include <GL/gl.h>
#include <GL/glut.h>
float xc, yc, r;
void TakeInput()
{
printf("Value of x1 : ");
scanf("%f", & xc);
printf("Value of y1 : ");
scanf("%f", & yc);
printf("Enter the radius : ");
scanf("%f", & r);
}
void display(void)
{
float p = 1 - r;
float x = 0;
float y = r;
glBegin(GL_POINTS);
glVertex2f(xc + x, yc + y);
glVertex2f(xc + y, yc + x);
glVertex2f(xc + x, yc - y);
glVertex2f(xc - y, yc - x);
while (x <= y)
{
if (p < 0)
{
x = x + 1;
p = p + 2.0 * x + 1;
}
else
{
x = x + 1;
y = y - 1;
p = p + 2 * (x - y) + 1;
}
glVertex2f(xc + x, yc + y);
glVertex2f(xc + x, yc - y);
glVertex2f(xc - x, yc + y);
glVertex2f(xc - x, yc - y);
glVertex2f(xc + y, yc + x);
glVertex2f(xc - y, yc + x);
glVertex2f(xc + y, yc - x);
glVertex2f(xc - y, yc - x);
}
glEnd();
glFlush();
}
int main(int argc, char ** argv)
{
TakeInput();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 150);
glutCreateWindow("Circle Drawing Using OpenGL");
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
gluOrtho2D(-250, 250, -250, 250);
glMatrixMode(GL_PROJECTION);
glViewport(0, 0, 500, 500);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}