-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·285 lines (235 loc) · 5.74 KB
/
main.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
using namespace std;
#include<iostream>
#include<string.h>
#include<GLUT/glut.h>
#include "game1.h"
void myinit()
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0,0.0,0.0);
glPointSize(3.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
}
void drawAxis()
{
char opt[] = "OPTIMIZER";
char imt[] = "IMITATOR";
int i;
glColor3f(0.0,0.0,0.0);
glBegin(GL_LINES);
glVertex2d(100,100);
glVertex2d(400,100);
glVertex2d(100,100);
glVertex2d(100,400);
glEnd();
glFlush();
for(i=0;i<strlen(opt);i++)
{
glRasterPos2d(200+(i*18), 50);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, opt[i]);
}
for(i=0;i<strlen(imt);i++)
{
glRasterPos2d(50, 300-(i*18));
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, imt[i]);
}
glRasterPos2d(90, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(140, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '2');
glRasterPos2d(150, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(180, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '4');
glRasterPos2d(190, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(220, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '6');
glRasterPos2d(230, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(260, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '8');
glRasterPos2d(270, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(300, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '1');
glRasterPos2d(310, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(320, 85);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
// y axis
glRasterPos2d(80, 140);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '2');
glRasterPos2d(90, 140);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(80, 180);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '4');
glRasterPos2d(90, 180);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(80, 220);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '6');
glRasterPos2d(90, 220);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(80, 260);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '8');
glRasterPos2d(90, 260);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(70, 300);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '1');
glRasterPos2d(80, 300);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
glRasterPos2d(90, 300);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '0');
}
void plotpoints(float x,float y,int value)
{
//printf("\nValue : %d",value);
if(value==0)
glColor3f(0.7,0.7,0.7);
else if(value<N/5)
glColor3f(1,1,0); //Level 1: YELLOW
else if(value<2*N/5)
glColor3f(1,0,1); //Level 2: Magenta
else if(value<3*N/5)
glColor3f(0,1,0); //Level 3: GREEN
else if(value<4*N/5)
glColor3f(0,0,1); //Level 4: BLUE
else if(value<N)
glColor3f(1,0,0); //Level 5: RED
glVertex2d(x,y);
}
void legend()
{
glPointSize(10.0);
glBegin(GL_POINTS);
char letters[5];
int i=0;
//strcpy(letters,"20");
glColor3f(1,1,0);
glVertex2d(300,390);
glColor3f(1,0,1);
glVertex2d(300,360);
glColor3f(0,1,0);
glVertex2d(300,330);
glColor3f(0,0,1);
glVertex2d(300,300);
glColor3f(1,0,0);
glVertex2d(300,270);
glColor3f(0.7,0.7,0.7);
glVertex2d(300,240);
glEnd();
glFlush();
glColor3f(0,0,0);
strcpy(letters,"X=Av.Sz.Herd");
for(i=0;i<strlen(letters);i++)
{
glRasterPos2d(300+(i*9),420);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, letters[i]);
}
strcpy(letters,"X<20%N");
for(i=0;i<strlen(letters);i++)
{
glRasterPos2d(320+(i*9),387);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, letters[i]);
}
strcpy(letters,"20%N<X<40%N");
for(i=0;i<strlen(letters);i++)
{
glRasterPos2d(320+(i*9),357);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, letters[i]);
}
strcpy(letters,"40%N<X<60%N");
for(i=0;i<strlen(letters);i++)
{
glRasterPos2d(320+(i*9),327);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, letters[i]);
}
strcpy(letters,"60%N<X<80%N");
for(i=0;i<strlen(letters);i++)
{
glRasterPos2d(320+(i*9),297);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, letters[i]);
}
strcpy(letters,"80%N<X ");
for(i=0;i<strlen(letters);i++)
{
glRasterPos2d(320+(i*9),267);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, letters[i]);
}
strcpy(letters,"No Herd.");
for(i=0;i<strlen(letters);i++)
{
glRasterPos2d(320+(i*9),237);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, letters[i]);
}
}
void myDisplay()
{
int hp,nr,value;
initialize_game();
glClear(GL_COLOR_BUFFER_BIT);
printf("\n Game Initializd.\n");
drawAxis();
glBegin(GL_POINTS);
for(hp=5,nr=60;hp<=20;hp++,nr-=2)
{
//printf("\nBefore game start for CONST Randomizer %d.",r);
//for(nr=5;nr<=100;nr+=5)
//{
value = play_game1(nr,hp);
plotpoints((hp*2)+100,(nr*2)+100,value);
reinitialize();
//}
printf(".");
}
printf("\nGAME OVER.");
glEnd();
glFlush();
legend();
glFlush();
}
/*void myDisplay1()
{
int i;
float *value;//=(int*)malloc(sizeof(int)*NR*2);
initialize_game();
glClear(GL_COLOR_BUFFER_BIT);
printf("Game intialized.\n");
glColor3f(0.0,0.0,0.0);
glBegin(GL_LINES);
glVertex2d(100,100);
glVertex2d(400,100);
glVertex2d(100,100);
glVertex2d(100,400);
glEnd();
glFlush();
value = play_game2(30,10);
glBegin(GL_LINES);
for(i=0;i<2*NR;i++)
{
glPointSize(1.0);
glColor3f(1.0,0.0,0.0);
glVertex2d(100+(i+1)*5,100);
glVertex2d(100+(i+1)*5,100+10*value[i]);
i++;
glColor3f(0.0,0.0,1.0);
glVertex2d(100+(i+1)*5+2,100);
glVertex2d(100+(i+1)*5+2,100+10*value[i]);
}
glEnd();
glFlush();
}*/
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("Graph plotting");
glutDisplayFunc(myDisplay);
myinit();
glutMainLoop();
return 0;
}