-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
464 lines (425 loc) · 23.2 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ElementsVR</title>
<meta name="description" content="ElementsVR">
<script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-layout-component.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-event-set-component.min.js"></script>
<script src="https://rawgit.com/protyze/aframe-curve-component/master/dist/aframe-curve-component.min.js"></script>
<script src="https://rawgit.com/protyze/aframe-alongpath-component/master/dist/aframe-alongpath-component.min.js"></script>
<script src="https://rawgit.com/rdub80/aframe-gui/master/dist/aframe-gui.min.js"></script>
<script src="https://unpkg.com/aframe-animation-component@^4.1.2/dist/aframe-animation-component.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="src/js/components/group-spheres.js"></script>
<script src="src/js/components/element-box.js"></script>
<script src="src/js/components/atom.js"></script>
<script src="src/js/components/background-atom.js"></script>
<script type="text/javascript">
const elementData = {
"group1": {"color": "#E52D2D",
"name": "Alkalai Metals",
"elements": [
{number: "3", symbol:"Li", name:"Lithium", weight:"6.941"},
{number: "11", symbol:"Na", name:"Sodium", weight:"22.98976..."},
{number: "19", symbol:"K", name:"Potassium", weight:"39.948"},
{number: "37", symbol:"Rb", name:"Rubidium", weight:"85.4678"},
{number: "55", symbol:"Cs", name:"Caesium", weight:"132.9054"},
{number: "87", symbol:"Fr", name:"Francium", weight:"(223)"}
]
},
"group2": {"color": "#DA8E00",
"name": "Alkaline Earth Metals",
"elements": [
{number: "4", symbol:"Be", name:"Beryllium", weight:"9.012182"},
{number: "12", symbol:"Mg", name:"Magnesium", weight:"24.305"},
{number: "20", symbol:"Ca", name:"Calcium", weight:"40.078"},
{number: "38", symbol:"Sr", name:"Strontium", weight:"87.62"},
{number: "54", symbol:"Ba", name:"Barium", weight:"132.9054"},
{number: "88", symbol:"Ra", name:"Radium", weight:"(226)"}
]
},
"group3": {"color": "#2FA732",
"name": "Lanthanides",
"elements": [
{number: "57", symbol:"La", name:"Lanthanum", weight:"138.90547"},
{number: "58", symbol:"Ce", name:"Cerium", weight:"140.116"},
{number: "59", symbol:"Pr", name:"Praseodymium", weight:"140.90765"},
{number: "60", symbol:"Nd", name:"Neodymium", weight:"144.242"},
{number: "61", symbol:"Pm", name:"Promethium", weight:"(145)"},
{number: "62", symbol:"Sm", name:"Samarium", weight:"150.36"},
{number: "63", symbol:"Eu", name:"Europium", weight:"151.964"},
{number: "64", symbol:"Gd", name:"Gadolinium", weight:"157.25"},
{number: "65", symbol:"Tb", name:"Terbium", weight:"158.92535"},
{number: "66", symbol:"Dy", name:"Dysprosium", weight:"162.5"},
{number: "67", symbol:"Ho", name:"Holmium", weight:"164.93032"},
{number: "68", symbol:"Er", name:"Erbium", weight:"167.259"},
{number: "69", symbol:"Tm", name:"Thulium", weight:"168.93421"},
{number: "70", symbol:"Yb", name:"Ytterbium", weight:"173.054"},
{number: "71", symbol:"Lu", name:"Lutetium", weight:"174.9668"}
]
},
"group4": {"color": "#2D4FE5",
"name": "Actinides",
"elements": [
{number: "89", symbol:"Ac", name:"Actinium", weight:"(227)"},
{number: "90", symbol:"Th", name:"Thorium", weight:"232.03806"},
{number: "91", symbol:"Pa", name:"Protactinium", weight:"231.0588"},
{number: "92", symbol:"U", name:"Uranium", weight:"238.02891"},
{number: "93", symbol:"Np", name:"Neptunium", weight:"(237)"},
{number: "94", symbol:"Pu", name:"Plutonium", weight:"(244)"},
{number: "95", symbol:"Am", name:"Americium", weight:"(243)"},
{number: "96", symbol:"Cm", name:"Curium", weight:"(247)"},
{number: "97", symbol:"Bk", name:"Berkelium", weight:"(247)"},
{number: "98", symbol:"Cf", name:"Californium", weight:"(251)"},
{number: "99", symbol:"Es", name:"Einstenium", weight:"(252)"},
{number: "100", symbol:"Fm", name:"Fermium", weight:"(257)"},
{number: "101", symbol:"Md", name:"Mendelevium", weight:"(258)"},
{number: "102", symbol:"No", name:"Nobelium", weight:"(259)"},
{number: "105", symbol:"Lr", name:"Lawrencium", weight:"(262)"}
]
},
"group5": {"color": "#972CA7",
"name": "Transition Metals",
"elements": [
{number: "21", symbol:"Sc", name:"Scandium", weight:"44.955912"},
{number: "22", symbol:"Ti", name:"Titanium", weight:"47.867"},
{number: "23", symbol:"V", name:"Vanadium", weight:"50.9415"},
{number: "24", symbol:"Cr", name:"Chromium", weight:"51.9961"},
{number: "25", symbol:"Mn", name:"Manganese", weight:"54.938045"},
{number: "26", symbol:"Fe", name:"Iron", weight:"55.845"},
{number: "27", symbol:"Co", name:"Cobalt", weight:"58.933195"},
{number: "28", symbol:"Ni", name:"Nickel", weight:"58.6934"},
{number: "29", symbol:"Cu", name:"Copper", weight:"63.546"},
{number: "30", symbol:"Zn", name:"Zinc", weight:"65.38"},
{number: "39", symbol:"Y", name:"Yttrium", weight:"88.90585"},
{number: "40", symbol:"Zr", name:"Zirconium", weight:"91.224"},
{number: "41", symbol:"Nb", name:"Niobium", weight:"92.90628"},
{number: "42", symbol:"Mo", name:"Molybdenum", weight:"95.96"},
{number: "43", symbol:"Tc", name:"Technetium", weight:"(98)"},
{number: "44", symbol:"Ru", name:"Ruthenium", weight:"101.07"},
{number: "45", symbol:"Rh", name:"Rhodium", weight:"102.9055"},
{number: "46", symbol:"Pd", name:"Palladium", weight:"106.42"},
{number: "47", symbol:"Ag", name:"Silver", weight:"107.8682"},
{number: "48", symbol:"Cd", name:"Cadmium", weight:"112.411"},
{number: "72", symbol:"Hf", name:"Hafnium", weight:"178.49"},
{number: "73", symbol:"Ta", name:"Tantalum", weight:"180.94788"},
{number: "74", symbol:"W", name:"Tungsten", weight:"183.84"},
{number: "75", symbol:"Re", name:"Rhenium", weight:"186.207"},
{number: "76", symbol:"Os", name:"Osmium", weight:"190.23"},
{number: "77", symbol:"Ir", name:"Iridium", weight:"192.217"},
{number: "78", symbol:"Pt", name:"Platinum", weight:"195.084"},
{number: "79", symbol:"Au", name:"Gold", weight:"196.966569"},
{number: "80", symbol:"Hg", name:"Mercury", weight:"200.59"},
{number: "104", symbol:"Rf", name:"Rutherfordium", weight:"(267)"},
{number: "105", symbol:"Db", name:"Dubnium", weight:"(268)"},
{number: "106", symbol:"Sg", name:"Seaborgium", weight:"(271)"},
{number: "107", symbol:"Bh", name:"Bohrium", weight:"(272)"},
{number: "108", symbol:"Hs", name:"Hassium", weight:"(270)"},
{number: "112", symbol:"Cn", name:"Copernicium", weight:"(285)"}
]
},
"group6": {"color": "#0078D1",
"name": "Post Transiton Metals",
"elements": [
{number: "13", symbol:"Al", name:"Aluminium", weight:"26.9815386"},
{number: "31", symbol:"Ga", name:"Gallium", weight:"69.723"},
{number: "49", symbol:"In", name:"Indium", weight:"114.818"},
{number: "50", symbol:"Sn", name:"Tin", weight:"118.71"},
{number: "81", symbol:"Tl", name:"Thallium", weight:"204.3833"},
{number: "82", symbol:"Pb", name:"Lead", weight:"207.2"},
{number: "83", symbol:"Bi", name:"Bismuth", weight:"208.9804"},
{number: "84", symbol:"Po", name:"Polonium", weight:"(209)"}
]
},
"group7": {"color": "#74643C",
"name": "Metalloid",
"elements": [
{number: "5", symbol:"B", name:"Boron", weight:"10.811"},
{number: "14", symbol:"Si", name:"Silicon", weight:"28.0855"},
{number: "32", symbol:"Ge", name:"Germanium", weight:"72.63"},
{number: "33", symbol:"As", name:"Arsenic", weight:"74.9216"},
{number: "51", symbol:"Sb", name:"Antimony", weight:"121.76"},
{number: "52", symbol:"Te", name:"Tellurium", weight:"127.6"}
]
},
"group8": {"color": "#E76DC2",
"name": "Non Metals",
"elements": [
{number: "1", symbol: "H", name:'Hydrogen', weight: "1.00794"},
{number: "6", symbol:"C", name:"Carbon", weight:"12.0107"},
{number: "7", symbol:"N", name:"Nitrogen", weight:"14.0067"},
{number: "8", symbol:"O", name:"Oxygen", weight:"15.9994"},
{number: "15", symbol:"P", name:"Phosphorus", weight:"30.973762"},
{number: "16", symbol:"S", name:"Sulfur", weight:"32.065"},
{number: "34", symbol:"Se", name:"Selenium", weight:"78.96"}
]
},
"group9": {"color": "black",
"name": "Halogens",
"elements": [
{number: "9", symbol:"F", name:"Fluorine", weight:"18.9984032"},
{number: "17", symbol:"Cl", name:"Chlorine", weight:"35.453"},
{number: "35", symbol:"Br", name:"Bromine", weight:"79.904"},
{number: "53", symbol:"I", name:"Iodine", weight:"126.90447"},
{number: "85", symbol:"At", name:"Astatine", weight:"(210)"},
]
},
"group10": {"color": "#8DAF78",
"name": "Noble Gases",
"elements": [
{number: "2", symbol:"He", name:"Helium", weight:"4.002602"},
{number: "10", symbol:"Ne", name:"Neon", weight:"20.1797"},
{number: "18", symbol:"Ar", name:"Argon", weight:"39.948"},
{number: "36", symbol:"Kr", name:"Krypton", weight:"83.798"},
{number: "54", symbol:"Xe", name:"Xenon", weight:"131.293"},
{number: "86", symbol:"Rn", name:"Radon", weight:"(222)"},
]
},
"group11": {"color": "#FF07FE",
"name": "Unknown Properties",
"elements": [
{number: "109", symbol:"Mt", name:"Meitnerium", weight:"(276)"},
{number: "110", symbol:"Ds", name:"Darmstadium", weight:"(281)"},
{number: "111", symbol:"Rg", name:"Roentgenium", weight:"(280)"},
{number: "113", symbol:"Uut", name:"Unutrium", weight:"(284)"},
{number: "114", symbol:"Fl", name:"Flerovium", weight:"(289)"},
{number: "115", symbol:"Uup", name:"Ununpentium", weight:"(288)"},
{number: "116", symbol:"Lv", name:"Livermorium", weight:"(293)"},
{number: "117", symbol:"Uus", name:"Ununseptium", weight:"(294)"},
{number: "118", symbol:"Uuo", name:"Ununoctium", weight:"(294)"}
]
}
};
function createBoxes(periodicGroupName) {
if (periodicGroupName === "Transition Metals") {
let transitionMetals = elementData["group5"]
let color = transitionMetals["color"];
let elements = transitionMetals["elements"];
let firstHalf = elements.slice(0, elements.length / 2);
let secondHalf = elements.slice(elements.length / 2, 34);
for (let element in firstHalf) {
let elementBox = document.createElement('a-box');
elementBox.setAttribute('element-box-info', {
color: color,
number: firstHalf[element]["number"],
symbol: firstHalf[element]["symbol"],
name: firstHalf[element]["name"],
weight: firstHalf[element]["weight"],
groupName: periodicGroupName,
});
document.getElementById('menuOne').appendChild(elementBox);
}
for (element in secondHalf) {
let elementBox = document.createElement('a-box');
elementBox.setAttribute('element-box-info', {
color: color,
number: secondHalf[element]["number"],
symbol: secondHalf[element]["symbol"],
name: secondHalf[element]["name"],
weight: secondHalf[element]["weight"],
groupName: periodicGroupName,
});
document.getElementById('menuTwo').appendChild(elementBox);
}
} else {
for (let property in elementData) {
if (elementData[property]["name"] === periodicGroupName) {
let color = elementData[property]["color"];
let elementList = elementData[property]["elements"];
for (element in elementList) {
let elementBox = document.createElement('a-box');
elementBox.setAttribute('element-box-info', {
color: color,
number: elementList[element]["number"],
symbol: elementList[element]["symbol"],
name: elementList[element]["name"],
weight: elementList[element]["weight"],
groupName: periodicGroupName,
});
document.getElementById('menuOne').appendChild(elementBox);
}
}
}
}
}
function destroyEntities(parentEntity) {
while (parentEntity.firstChild) {
parentEntity.removeChild(parentEntity.firstChild);
}
}
function hideElement(elementToHide) {
elementToHide.setAttribute('visible', false);
}
function clearGoogleInfo() {
let googlePanel = document.getElementById('googlePanel');
destroyEntities(googlePanel);
}
function clearAtomScene() {
document.getElementById('atom').parentNode.removeChild(atom.parentNode.firstChild);
let curveContainer = document.getElementById('shell1').parentNode;
let electronContainer = document.querySelectorAll('.electron')[0].parentNode;
destroyEntities(curveContainer);
destroyEntities(electronContainer);
}
function clearElementBoxScene() {
let menuOneEntity = document.getElementById('menuOne');
if (menuOneEntity.children.length > 1) {
destroyEntities(menuOneEntity.children[0].parentNode);
}
let menuTwoEntity = document.getElementById('menuTwo');
if (menuTwoEntity.children.length > 1) {
destroyEntities(menuTwoEntity.children[0].parentNode);
}
}
function returnElementBoxSelection() {
let sceneEl = document.querySelector('a-scene');
let periodicGroupName = document.querySelector('a-sphere').className;
// Clear the atom Scen
clearAtomScene();
//Clear google panel information
clearGoogleInfo();
//Hide the google panel
hideElement(document.getElementById('googlePanel'));
//Hide the back button
hideElement(document.getElementById('backMenuButton'));
// Reset the menu
let menuPanel = document.getElementById('menuPanel');
menuPanel.setAttribute('animation__rotate', {property: 'rotation', dur: 1000, easing: "easeInSine", loop: false, to: {x:0, y:0, z:0}});
menuPanel.setAttribute('animation__position', {property: 'position', dur: 1000, easing: "easeInSine", loop: false, to: {x:0, y:-1, z:-7}});
renderBackground(sceneEl);
createBoxes(periodicGroupName);
}
function renderMainMenu() {
let sceneEl = document.querySelector('a-scene');
//Clear the scene of the atom
if (document.getElementById('atom') !== null) {
clearAtomScene();
}
// Destroy element boxes if they are present
clearElementBoxScene();
//Render the backGround spheres if it is not present
if (document.getElementById('backgroundScene').children[0] === undefined) {
renderBackground();
}
// Clear the google panel of API information
clearGoogleInfo();
//Hide the google Panel
hideElement(document.getElementById('googlePanel'));
//Hide the Menu Panel
hideElement(document.getElementById('menuPanel'));
let menuPanel = document.getElementById('menuPanel');
menuPanel.setAttribute('animation__rotate', {property: 'rotation', dur: 1000, easing: "easeInSine", loop: false, to: {x:0, y:0, z:0}});
menuPanel.setAttribute('animation__position', {property: 'position', dur: 1000, easing: "easeInSine", loop: false, to: {x:0, y:-1, z:-7}});
//Hide the 'Back button'
hideElement(document.getElementById('backMenuButton'));
//Render the main menu spheres
let menuContainer = document.getElementById('mainScene');
for (let property in elementData) {
let sphere = document.createElement('a-sphere');
sphere.setAttribute('background-atom','');
sphere.setAttribute('group-spheres',{color: elementData[property]["color"],
groupName: elementData[property]["name"],
elements: elementData[property]["elements"]});
sphere.setAttribute('info-capture', '');
menuContainer.appendChild(sphere);
}
}
function renderBackground() {
counter = 0;
do {
let backgroundAtom = document.createElement('a-sphere');
backgroundAtom.className = 'backgroundAtom';
backgroundAtom.setAttribute('background-atom','');
document.getElementById('backgroundScene').appendChild(backgroundAtom);
counter = counter + 1;
} while (counter < 20);
}
</script>
</head>
<body>
<a-scene background="color: white">
<a-assets>
<audio id="buttonPress" src="https://ucarecdn.com/ac58410f-49a3-4d75-81de-336c6d28e8af/" preload></audio>
<img id="atom-image" src="https://ucarecdn.com/9cf7730a-5b3f-4335-8aef-1d25472c45f8/">
<img id="github" src="https://ucarecdn.com/d3d87fb1-48cf-46ba-addc-38496f82f7c6/">
</a-assets>
<a-sound src="https://ucarecdn.com/ac58410f-49a3-4d75-81de-336c6d28e8af/"></a-sound>
<!--Set up the scene entities -->
<!-- Background scene -->
<a-entity id="backgroundScene" layout="type: dodecahedron; radius: 15" position="0 0 0"></a-entity>
<!-- Main Scene -->
<a-entity id="mainScene" layout="type: dodecahedron; radius: 7" position="0 0 -0.5"></a-entity>
<!-- Box Menu Scene -->
<a-entity id="boxScene">
<a-entity id="menuOne" layout="type: circle; radius: 1.25" position="0 0 -0.8"></a-entity>
<a-entity id="menuTwo" layout="type: circle; radius: 1.75" position="0 0 -0.8"></a-entity>
</a-entity>
<!-- Atom Scene -->
<a-entity id="atomScene"></a-entity>
<!-- Credit Panel-->
<a-plane id="creditPanel" color="#33ccff" height="3" width="4" position="0 -2.5 7" rotation="-45 180 0">
<a-text value="Created by Daniel Rubio" position="0 1 0" align="center"></a-text>
<a-image src="#github" position="-1 0.5 0" scale="0.5 0.5 0.5"></a-image>
<a-text value="drubio1989" position="0 0.5 0" align="center"></a-text>
<a-text value="Github Icon made by Dave Gandy from www.flaticon.com" position="0 -0.5 0" align="center"></a-text>
<a-text value="Atom Icon made by Freepik from www.flaticon.com" position="0 -1 0" align="center"></a-text>
</a-plane>
<!--Google Info Panel-->
<a-entity>
<a-plane id="googlePanel" visible="false" height="5" width="5" position="-5 0 -5" rotation="0 45 0" color="#33ccff"></a-plane>
</a-entity>
<!-- Dynamic Menu Panel -->
<a-entity>
<a-gui-flex-container id='menuPanel' visible="true" flex-direction="column" justify-content="center"
align-items="center" component-padding="0.1" opacity="1"
width="4" height="2" position="0 -1 -7" rotation="0 0 0" panel-color="#33ccff">
<a-animation attribute="scale" from="0 1 1" to="1 1 1" dur="750" delay="400"
fill="backwards"></a-animation>
<a-gui-label
width="4" height="3"
value="ElementsVR"
font-family="monospace"
font-size="150px"
margin="1 0 0 0"
font-color="#ffffff"
background-color="#33ccff"
>
<a-image src="#atom-image" position="0 0.8 0"></a-image>
<a-gui-button id="mainMenuButton" position="0 -1 0"
width="2.5" height="0.75"
onclick="renderMainMenu"
value="Main Menu"
font-color="#ffffff"
font-family="monospace"
margin="0 0 0 0"
hover-color="#00cc66"
>
</a-gui-button>
<a-gui-button id="backMenuButton" position="0 -2 0"
visible="false"
width="2.5" height="0.75"
onclick="returnElementBoxSelection"
value="Back"
font-color="#ffffff"
font-family="monospace"
margin="0 0 0 0"
hover-color="#00cc66"
>
</a-gui-button>
</a-gui-label>
</a-gui-flex-container>
</a-entity>
<!-- Camera -->
<a-entity position="0 0 0" rotation="0 0 0">
<a-camera>
<a-cursor material="color: black;" fuse="true" fuseTimeOut="200"></a-cursor>
</a-camera>
</a-entity>
</a-scene>
</body>
<script type="text/javascript">
renderBackground();
</script>
</html>