-
Notifications
You must be signed in to change notification settings - Fork 1
/
3-BresenhamCircleDrawingAlgo.cpp
63 lines (54 loc) · 1.28 KB
/
3-BresenhamCircleDrawingAlgo.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
#include <windows.h>
#include <gl/glut.h>
#include <iostream>
#include <cmath>
#include "./custom-headers/Point.h"
#include "./openGL-comp/HelperDrawerMethod.h"
#include "./algos/3-BresenhamCircleAlgo.h"
using namespace std;
int cx1 = 0, cy1 = 0, r;
void myInit()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, 500, 0, 500);
glColor3f(0.0, 0.0, 0.0);
}
void myDisplay()
{
int offsetX = 250, offsetY = 250; // origin at (250,250)
RGBColor color(0, 0, 0, 1);
auto points = bresenhamCircleAlgo(r);
drawPixels<int>(points, color, cx1 + offsetX, cy1 + offsetY);
glFlush();
}
void myMouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP)
{
cx1 = x, cy1 = y;
glutPostRedisplay();
}
}
int main(int argc, char **argv)
{
cout << "Enter the coordinates of the center:\n\n"
<< endl;
cout << "X-coordinate : ";
cin >> cx1;
cout << "\nY-coordinate : ";
cin >> cy1;
cout << "\nEnter radius : ";
cin >> r;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("- Bresenham's Circle Drawing -");
myInit();
glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);
glutMainLoop();
return 0;
}