-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawCircle.cpp
More file actions
154 lines (139 loc) · 2.78 KB
/
drawCircle.cpp
File metadata and controls
154 lines (139 loc) · 2.78 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <GL/glut.h>
#include <iostream>
#include <list>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <wchar.h>
#include<stdio.h>
//#include <tchar.h>
using namespace std;
struct node{
int data;
int x;
int y;
};
list<node> nodeList;
int count=0;
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 )
{
void Sprint(int,int,int);
int x = 0, y = radius, p = 1 - radius;
node xnode;
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);
}
Sprint(xCenter,yCenter,count);
xnode.x=xCenter;
xnode.y=yCenter;
xnode.data=count++;
nodeList.push_back(xnode);
}
void drawLine( int xStart, int yStart, int xEnd, int yEnd )
{
int x1,y1,x2,y2,dx,dy,step,i,xinc,yinc;
x1=xStart;
x2=xEnd;
y1=yStart;
y2=yEnd;
dx=abs(x1-x2);
dy=abs(y1-y2);
if(dx>dy){
step=dx;
}
else{
step=dy;
}
xinc=(float)dx/step;
yinc=dy/(float)step;
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POINTS);
printf("step=%d,xinc=%d,yinc=%d",dx,xinc,yinc);
for(i=0;i<=step;i++)
{
glVertex2i(x1,y1);
glVertex2i(xEnd, yEnd);
x1+=(int)xinc;
y1+=(int)yinc;
}
glEnd();
}
void Sprint( int x, int y, int num)
{
int l,i;
char *st,stx[3];
stx[0]=48+num;
stx[2]='\0';
st=stx;
glRasterPos2i( x-7, y-7);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, st[0]);
}
void display()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
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();
//drawLine(x+20,500-y, x+40,y+40);
for (list<node>::iterator it=nodeList.begin(); it != nodeList.end(); ++it)
{
node xnode=*it;
cout<<xnode.data;
}
//cout << ' ' << *it;
}
}
if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN))
{
drawLine( x, 500-y, x+30, 500-y+40 );
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(50,50);
glutInitWindowSize(800, 500);
glutCreateWindow("BFS");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 800, 0, 500);
glutDisplayFunc(display);
glutMouseFunc(mouseClick);
glutMainLoop();
return 0;
}