-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBresenham Circle Drawing.cpp
84 lines (72 loc) · 1.73 KB
/
Bresenham Circle Drawing.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int centerX, centerY, radius;
void putpixel(int x, int y){
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POINTS);
glVertex2d(centerX+x, centerY+y);
glVertex2d(centerX+y, centerY+x);
glVertex2d(centerX-x, centerY+y);
glVertex2d(centerX-y, centerY+x);
glVertex2d(centerX+x, centerY-y);
glVertex2d(centerX+y, centerY-x);
glVertex2d(centerX-x, centerY-y);
glVertex2d(centerX-y, centerY-x);
glEnd();
}
void circleDrawing(){
int x=0, y=radius, d;
d = 3-(2*radius);
while(x <= y){
putpixel(x,y);
if (d >= 0){
d = d+4*(x-y)+10;
y--;
}
else{
d = d+(4*x)+6;
}
x++;
}
}
void drawAxis()
{
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_POINTS);
for (int i=-500; i<=500; i++)
{
glVertex2d(i,0);
glVertex2d(0,i);
}
glEnd();
glFlush();
}
void display(){
circleDrawing();
glFlush();
drawAxis();
}
int main(int argc, char **argv){
cout<<"Enter the center of the Circle as X and Y"<<endl;
cin>>centerX>>centerY;
cout<<"Enter the Radius of the circle"<<endl;
cin>>radius;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Bresenham Circle Drawing Algorithm");
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(-500,500,-500,500);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}