-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle.cpp
More file actions
90 lines (78 loc) · 1.63 KB
/
circle.cpp
File metadata and controls
90 lines (78 loc) · 1.63 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
78
79
80
81
82
83
84
85
86
87
/*
Circle Drawing algorithm
Sadeed Ameen PO
ROll No:267
*/
#include <GL/glut.h>
#include <iostream>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <wchar.h>
using namespace std;
void circlePlotPoints(int xCenter, int yCenter, int x, int y )
{
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_POINTS);
glVertex2i(xCenter + x, yCenter + y );
glVertex2i(xCenter - x, yCenter + y );
glVertex2i(xCenter + x, yCenter - y );
glVertex2i(xCenter - x, yCenter - y );
glVertex2i(xCenter + y, yCenter + x );
glVertex2i(xCenter - y, yCenter + x );
glVertex2i(xCenter + y, yCenter - x );
glVertex2i(xCenter - y, yCenter - x );
glEnd();
}
void drawCircle( int xCenter, int yCenter, int radius )
{
int x = 0, y = radius, p = 1 - radius;
circlePlotPoints( xCenter, yCenter, x, y );
while( x < y )
{
x++;
if( p < 0 )
{
p += (2 * x) + 1;
}
else
{
y--;
p += ( 2*(x-y) ) +1;
}
circlePlotPoints(xCenter, yCenter, x, y);
}
}
void mouseClick( int button, int state, int x, int y )
{
if( button == GLUT_LEFT_BUTTON )
{
if( state == GLUT_DOWN )
{
drawCircle(x, 500-y, 20);
glutSwapBuffers();
}
}
}
void display()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(50,50);
glutInitWindowSize(800, 500);
glutCreateWindow("Midpoint Circle Generation");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 800, 0, 500);
glutDisplayFunc(display);
glutMouseFunc(mouseClick);
glutMainLoop();
return 0;
}
//End Of program