-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSimulation of Radioactive elements
484 lines (474 loc) · 12.8 KB
/
Simulation of Radioactive elements
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#include<windows.h>
#include<gl/glut.h>
#define dx 32
#define dy 32
#define maxrow 25
#define maxcol 25
#include<math.h>
#include<string.h>
#include<stdio.h>
double x11, y11;
GLfloat z11=-650;
int i11=0;
double x22, y22;
int i22=0;
GLfloat z22=-650;
double x33, y33;
int i33=0;
GLfloat z33=-650;
double six, siy;
int si=0;
double si1x, si1y;
int si1=0;
double si2x, si2y;
int si2=0;
GLint i, j;
GLint x[maxcol], y[maxrow];
double trw=1.4;
double tmw=1.4;
double tlw=1.45;
void init()
{
glClearColor(0.0,1.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void clearscreenfunc()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void rwall() //right
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
float ambient[] = { 0.9,0.3,0.5,1 }; //set rgb color
float light_pos[] = { 27,8,2,3 };
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glRotatef(50, 0, 1, 0);
glRotatef(10, -1, 0, 0);
glRotatef(11.7, 0, 0, -1);
glTranslatef(0.4, trw, 0.4);
glScalef(0.5, 1.2, 0.07);
glutSolidCube(1);
}
void mwall() //middle
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
float ambient[] = { 0.7,0.8,0.7,1 };
float light_pos[] = { 27,8,2,3 };
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glRotatef(50, 0, 1, 0);
glRotatef(10, -1, 0, 0);
glRotatef(11.7, 0, 0, -1);
glTranslatef(0.1, tmw, 0.1);
glScalef(0.5, 1.2, 0.04);
glutSolidCube(1);
}
void lwall() //left
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
float ambient[] = { 1.0,1.0,1.0,1.0}; //white lighting
float light_pos[] = { 27,8,2,3};
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glRotatef(50, 0, 1, 0);
glRotatef(10, -1, 0, 0);
glRotatef(11.7, 0, 0, -1);
glTranslatef(-0.2, tlw, -0.2);
glScalef(0.4, 1.2, 0.01);
glutSolidCube(1);
}
void floor()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40, 1, 4, 20);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.09, -18.0, 3.0, 0.0, 0.0, 2.5, 0.0, 1.0, 0.0);
glTranslatef(-8, -10, -2);
glDisable(GL_LIGHTING);
glColor3f(0.2,0.4,0.4);
glScalef(0.02, 0.02, 0.02);
glLineWidth(2.0);
for (i = 0; i <= maxcol - 1; i++)
x[i] = x[0] + i*dx;
for (j = 0; j <= maxrow - 1; j++)
y[j] = y[0] + j*dy;
for (i = 0; i < maxcol - 1; i++)
{
for (j = 0; j < maxrow - 1; j++)
{
glBegin(GL_LINE_LOOP);
glVertex2f(x[i], y[j]);
glVertex2f(x[i], y[j + 1]);
glVertex2f(x[i + 1], y[j + 1]);
glVertex2f(x[i + 1], y[j]);
glEnd();
}
}
}
void gamma() //bottom;
{
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double w = glutGet(GLUT_WINDOW_WIDTH);
double h = glutGet(GLUT_WINDOW_HEIGHT);
double ar = w / h;
glOrtho(-360 * ar, 360 * ar, -120, 120, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_LIGHTING);
glTranslatef(z11,-45,0);
glPointSize(5);
glColor3f(1.0, 1.0, 0.0);
GLfloat qa=0;
for (GLfloat i11 = -1400; i11<=qa+10000; i11 = i11+4)
{
glBegin(GL_POINTS);
glVertex2f(x11,y11);
x11 = -(float)i11;
if(i11>=9995 && i11 <= 9998) qa = 10000;
else if(i11>=19995 && i11 <= 19998) qa = 20000;
else if(i11>=29995 && i11 <= 29998) qa = 30000;
else if(i11>=39995 && i11<= 39998) qa = 40000;
else if(i11>=49995 && i11<=49998) qa = 60000;
y11 = 10.0 * sin(i11 *(35.284 / 360.0));
glEnd();
}
z11+=2;
}
void beta() //middle
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double w = glutGet(GLUT_WINDOW_WIDTH);
double h = glutGet(GLUT_WINDOW_HEIGHT);
double ar = w / h;
glOrtho(-360 * ar, 360 * ar, -120, 120, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1,0,0.7);
glTranslatef(z22,5,0);
glPointSize(5);
glColor3f(0.6, 0.3, 0.8);
GLfloat wa=0;
for (GLfloat i22 = -1400; i22<=wa+10000; i22 = i22+4)
{
glBegin(GL_POINTS);
glVertex2f(x22,y22);
x22 = -(float)i22;
if(i22>=9995 && i22 <= 9998) wa = 10000;
else if(i22>=19995 && i22 <= 19998) wa = 20000;
else if(i22>=29995 && i22 <= 29998) wa = 30000;
else if(i22>=39995 && i22<= 39998) wa = 40000;
else if(i22>=49995 && i22<=49998) wa = 60000;
y22 = 5.0 * sin(i22 *(35.284 / 360.0)); //increase 1st increase height,increase 2nd decrease width
glEnd();
}
z22+=1.4;
}
void alpha() //top
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
double w = glutGet(GLUT_WINDOW_WIDTH);
double h = glutGet(GLUT_WINDOW_HEIGHT);
double ar = w / h;
glOrtho(-360 * ar, 360 * ar, -120, 120, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(z33,40,0);
glPointSize(5);
glColor3f(0.9, 0., 0.4);
for (GLfloat i33 = -1400; i33<=80200; i33 = i33+4)
{
glBegin(GL_POINTS);
glVertex2f(x33,y33);
x33 = -(float)i33;
y33 = 5.0 * sin(i33 *(15.284 / 360.0)); //increase 1st increase height,increase 2nd decrease width
glEnd();
}
z33+=1.6;
}
void molecules()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glClearColor(1,0,0,0);
float ambient[] = { 0.7,0.1,0.1,1 };
float light_pos[] = { 2,8,2,3 };
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glTranslatef(-0.7,0.3,0.075);
glutSolidSphere(0.08,100,100);
float ambient1[] = { 0.1,0.3,1.0,1 };
float light_pos1[] = { 27,8,2,3 };
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos1);
glTranslatef(0,-0.3,0);
glutSolidSphere(0.06,100,100);
float ambient2[] = { 0.1,1.0,0.1,1 };
float light_pos2[] = { 27,8,2,3 };
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos2);
glTranslatef(0,-0.4,0);
glutSolidSphere(0.09,100,100);
}
void specialkeyboard(int key,int x,int y)
{
switch(key)
{
case GLUT_KEY_DOWN:
{
tmw=-0.1;// go meddile object and check
break;
}
case GLUT_KEY_LEFT:
{
tlw=-0.1;// go leftwall object and check
break;
}
case GLUT_KEY_RIGHT:
{
trw=0.05;//go right wall object and check
break;
}
case GLUT_KEY_END:
{
trw=1.45;
break;
}
case GLUT_KEY_PAGE_DOWN:
{
tmw=1.4;
break;
}
case GLUT_KEY_PAGE_UP:
{
tlw=1.4;
break;
}
}
}
void getCompnentsDiscxn()
{
char comp_paper[]="PAPER";
char comp_alm[]="ALLUMINIUM";
char comp_lead[]="LEAD";
char al[]="Alpha Ray";
char be[]="Beta Ray";
char ga[]="Gamma Ray";
char ml[]="Molecules";
char rp[]="Radio-active Elements";
char pr[]="I hope you have enjoyed with is app; ";
char pr_task[]="Please SUBSCRIBE, Comment, Like and Share Azzonika Tutorials Youtube channal!";
char tp[]="";
char tpp[]="";
char by[]=" ";
char usn[]=" ";
glDisable(GL_LIGHTING);
glColor3f(1,1,1);
glRasterPos2f(0.33,-0.35);
for(int iqa=0;iqa<strlen(comp_paper);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,comp_paper[iqa]);
}
glRasterPos2f(0.67,-0.35);
for(int iqa=0;iqa<strlen(comp_alm);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,comp_alm[iqa]);
}
glRasterPos2f(1.18,-0.25);
for(int iqa=0;iqa<strlen(comp_lead);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,comp_lead[iqa]);
}
glRasterPos2f(-0.3,0.7);
for(int iqa=0;iqa<strlen(al);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,al[iqa]);
}
glRasterPos2f(-0.3,0.37);
for(int iqa=0;iqa<strlen(be);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,be[iqa]);
}
glRasterPos2f(-0.3,-0.01);
for(int iqa=0;iqa<strlen(ga);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,ga[iqa]);
}
glRasterPos2f(-0.1,0.83);
for(int iqa=0;iqa<strlen(ml);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,ml[iqa]);
}
glRasterPos2f(0.6,0.95);
for(int iqa=0;iqa<strlen(rp);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,rp[iqa]);
}
glColor3f(0,0,0.2);
glRasterPos2f(0.0,-0.47);
for(int iqa=0;iqa<strlen(pr);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,pr[iqa]);
}
glColor3f(1,0,0);
glRasterPos2f(0,-0.55);
for(int iqa=0;iqa<strlen(pr_task);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,pr_task[iqa]);
}
glRasterPos2f(1.24,-0.5);
for(int iqa=0;iqa<strlen(tp);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,tp[iqa]);
}
glRasterPos2f(1.38,-0.6);
for(int iqa=0;iqa<strlen(tpp);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,tpp[iqa]);
}
glRasterPos2f(1.24,-0.2);
for(int iqa=0;iqa<strlen(by);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,by[iqa]);
}
glRasterPos2f(1.24,-0.3);
for(int iqa=0;iqa<strlen(usn);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,usn[iqa]);
}
}
//The getHow2Operate Function displays ' how to operate?' instruction
void getHow2Operate()
{
char InxnVarb[]={"How to Operate?"};
char acxnKey[]={"==>To Activate Paper, Aluminum or Lead:-"};
char pressAcxnKey[]={" Press <-,DownArrow or -> button, respectively."};
char deacxnKey[]={"==>To Deactivate Paper, Aluminum or Lead:-"};
char pressDeacxnKey[]={" Press PGUP,PGDN or ENG button, respectively."};
char HelpeText[]={"## For More Information:-Please refer to description box! "};
glColor3f(1,0.5,0);
glRasterPos2f(-0.2,1.3);
for(int iqa=0;iqa<strlen(InxnVarb);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,InxnVarb[iqa]);
}
glColor3f(0,0,0);
glRasterPos2f(-0.3,1.23);
for(int iqa=0;iqa<strlen(acxnKey);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,acxnKey[iqa]);
}
glRasterPos2f(-0.3,1.18);
for(int iqa=0;iqa<strlen(pressAcxnKey);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pressAcxnKey[iqa]);
}
glRasterPos2f(-0.3,1.11);
for(int iqa=0;iqa<strlen(deacxnKey);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,deacxnKey[iqa]);
}
glRasterPos2f(-0.3,1.05);
for(int iqa=0;iqa<strlen(pressDeacxnKey);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pressDeacxnKey[iqa]);
}
glColor3f(1,0,0);
glRasterPos2f(-0.3,1.0);
for(int iqa=0;iqa<strlen(HelpeText);iqa++)
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,HelpeText[iqa]);
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
double w = glutGet(GLUT_WINDOW_WIDTH);
double h = glutGet(GLUT_WINDOW_HEIGHT);
glViewport(200,0,w,h);
gamma();
if(tlw!=-0.1)
{
glViewport(200,0,w,h);
alpha();
}
else
{
glViewport(200,0,w-1000,h);
alpha();
}
if(tmw!=-0.1)
{
glViewport(200,0,w,h);
beta();
}else
{
glViewport(200,0,w-700,h);
beta();
}
glViewport(0,0,w,h);
rwall();
mwall();
lwall();
molecules();
getCompnentsDiscxn();
getHow2Operate();
floor();
glFlush();
}
void keybordfunc(unsigned char key,GLint xmouse,GLint ymouse)
{
switch(key)
{
case'n':
exit(0);
break;
}
}
void update(int value)
{
glutPostRedisplay();
glutTimerFunc(1, update, 0);
}
int main(int argc, char **argv)
{
x[0] = 1;
y[0] = 1;
glutInit(&argc, argv);
glutInitWindowSize(1400, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow("Demonstration of Radio-active Elements");
init();
glutDisplayFunc(display);
glutTimerFunc(0, update, 0);
glutSpecialFunc(specialkeyboard);
glutKeyboardFunc(keybordfunc);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}