css3d_periodictable.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>three.js css3d - periodic table</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. html, body {
  9. height: 100%;
  10. }
  11. body {
  12. background-color: #000000;
  13. margin: 0;
  14. font-family: Helvetica, sans-serif;;
  15. overflow: hidden;
  16. }
  17. a {
  18. color: #ffffff;
  19. }
  20. #info {
  21. position: absolute;
  22. width: 100%;
  23. color: #ffffff;
  24. padding: 5px;
  25. font-family: Monospace;
  26. font-size: 13px;
  27. font-weight: bold;
  28. text-align: center;
  29. z-index: 1;
  30. }
  31. #menu {
  32. position: absolute;
  33. bottom: 20px;
  34. width: 100%;
  35. text-align: center;
  36. }
  37. .element {
  38. width: 120px;
  39. height: 160px;
  40. box-shadow: 0px 0px 12px rgba(0,255,255,0.5);
  41. border: 1px solid rgba(127,255,255,0.25);
  42. text-align: center;
  43. cursor: default;
  44. }
  45. .element:hover {
  46. box-shadow: 0px 0px 12px rgba(0,255,255,0.75);
  47. border: 1px solid rgba(127,255,255,0.75);
  48. }
  49. .element .number {
  50. position: absolute;
  51. top: 20px;
  52. right: 20px;
  53. font-size: 12px;
  54. color: rgba(127,255,255,0.75);
  55. }
  56. .element .symbol {
  57. position: absolute;
  58. top: 40px;
  59. left: 0px;
  60. right: 0px;
  61. font-size: 60px;
  62. font-weight: bold;
  63. color: rgba(255,255,255,0.75);
  64. text-shadow: 0 0 10px rgba(0,255,255,0.95);
  65. }
  66. .element .details {
  67. position: absolute;
  68. bottom: 15px;
  69. left: 0px;
  70. right: 0px;
  71. font-size: 12px;
  72. color: rgba(127,255,255,0.75);
  73. }
  74. button {
  75. color: rgba(127,255,255,0.75);
  76. background: transparent;
  77. outline: 1px solid rgba(127,255,255,0.75);
  78. border: 0px;
  79. padding: 5px 10px;
  80. cursor: pointer;
  81. }
  82. button:hover {
  83. background-color: rgba(0,255,255,0.5);
  84. }
  85. button:active {
  86. color: #000000;
  87. background-color: rgba(0,255,255,0.75);
  88. }
  89. </style>
  90. </head>
  91. <body>
  92. <script src="../build/three.js"></script>
  93. <script src="js/libs/tween.min.js"></script>
  94. <script src="js/controls/TrackballControls.js"></script>
  95. <script src="js/renderers/CSS3DRenderer.js"></script>
  96. <div id="container"></div>
  97. <div id="info"><a href="http://threejs.org" target="_blank">three.js css3d</a> - periodic table. <a href="https://plus.google.com/113862800338869870683/posts/QcFk5HrWran" target="_blank">info</a>.</div>
  98. <div id="menu">
  99. <button id="table">TABLE</button>
  100. <button id="sphere">SPHERE</button>
  101. <button id="helix">HELIX</button>
  102. <button id="grid">GRID</button>
  103. </div>
  104. <script>
  105. var table = [
  106. "H", "Hydrogen", "1.00794", 1, 1,
  107. "He", "Helium", "4.002602", 18, 1,
  108. "Li", "Lithium", "6.941", 1, 2,
  109. "Be", "Beryllium", "9.012182", 2, 2,
  110. "B", "Boron", "10.811", 13, 2,
  111. "C", "Carbon", "12.0107", 14, 2,
  112. "N", "Nitrogen", "14.0067", 15, 2,
  113. "O", "Oxygen", "15.9994", 16, 2,
  114. "F", "Fluorine", "18.9984032", 17, 2,
  115. "Ne", "Neon", "20.1797", 18, 2,
  116. "Na", "Sodium", "22.98976...", 1, 3,
  117. "Mg", "Magnesium", "24.305", 2, 3,
  118. "Al", "Aluminium", "26.9815386", 13, 3,
  119. "Si", "Silicon", "28.0855", 14, 3,
  120. "P", "Phosphorus", "30.973762", 15, 3,
  121. "S", "Sulfur", "32.065", 16, 3,
  122. "Cl", "Chlorine", "35.453", 17, 3,
  123. "Ar", "Argon", "39.948", 18, 3,
  124. "K", "Potassium", "39.948", 1, 4,
  125. "Ca", "Calcium", "40.078", 2, 4,
  126. "Sc", "Scandium", "44.955912", 3, 4,
  127. "Ti", "Titanium", "47.867", 4, 4,
  128. "V", "Vanadium", "50.9415", 5, 4,
  129. "Cr", "Chromium", "51.9961", 6, 4,
  130. "Mn", "Manganese", "54.938045", 7, 4,
  131. "Fe", "Iron", "55.845", 8, 4,
  132. "Co", "Cobalt", "58.933195", 9, 4,
  133. "Ni", "Nickel", "58.6934", 10, 4,
  134. "Cu", "Copper", "63.546", 11, 4,
  135. "Zn", "Zinc", "65.38", 12, 4,
  136. "Ga", "Gallium", "69.723", 13, 4,
  137. "Ge", "Germanium", "72.63", 14, 4,
  138. "As", "Arsenic", "74.9216", 15, 4,
  139. "Se", "Selenium", "78.96", 16, 4,
  140. "Br", "Bromine", "79.904", 17, 4,
  141. "Kr", "Krypton", "83.798", 18, 4,
  142. "Rb", "Rubidium", "85.4678", 1, 5,
  143. "Sr", "Strontium", "87.62", 2, 5,
  144. "Y", "Yttrium", "88.90585", 3, 5,
  145. "Zr", "Zirconium", "91.224", 4, 5,
  146. "Nb", "Niobium", "92.90628", 5, 5,
  147. "Mo", "Molybdenum", "95.96", 6, 5,
  148. "Tc", "Technetium", "(98)", 7, 5,
  149. "Ru", "Ruthenium", "101.07", 8, 5,
  150. "Rh", "Rhodium", "102.9055", 9, 5,
  151. "Pd", "Palladium", "106.42", 10, 5,
  152. "Ag", "Silver", "107.8682", 11, 5,
  153. "Cd", "Cadmium", "112.411", 12, 5,
  154. "In", "Indium", "114.818", 13, 5,
  155. "Sn", "Tin", "118.71", 14, 5,
  156. "Sb", "Antimony", "121.76", 15, 5,
  157. "Te", "Tellurium", "127.6", 16, 5,
  158. "I", "Iodine", "126.90447", 17, 5,
  159. "Xe", "Xenon", "131.293", 18, 5,
  160. "Cs", "Caesium", "132.9054", 1, 6,
  161. "Ba", "Barium", "132.9054", 2, 6,
  162. "La", "Lanthanum", "138.90547", 4, 9,
  163. "Ce", "Cerium", "140.116", 5, 9,
  164. "Pr", "Praseodymium", "140.90765", 6, 9,
  165. "Nd", "Neodymium", "144.242", 7, 9,
  166. "Pm", "Promethium", "(145)", 8, 9,
  167. "Sm", "Samarium", "150.36", 9, 9,
  168. "Eu", "Europium", "151.964", 10, 9,
  169. "Gd", "Gadolinium", "157.25", 11, 9,
  170. "Tb", "Terbium", "158.92535", 12, 9,
  171. "Dy", "Dysprosium", "162.5", 13, 9,
  172. "Ho", "Holmium", "164.93032", 14, 9,
  173. "Er", "Erbium", "167.259", 15, 9,
  174. "Tm", "Thulium", "168.93421", 16, 9,
  175. "Yb", "Ytterbium", "173.054", 17, 9,
  176. "Lu", "Lutetium", "174.9668", 18, 9,
  177. "Hf", "Hafnium", "178.49", 4, 6,
  178. "Ta", "Tantalum", "180.94788", 5, 6,
  179. "W", "Tungsten", "183.84", 6, 6,
  180. "Re", "Rhenium", "186.207", 7, 6,
  181. "Os", "Osmium", "190.23", 8, 6,
  182. "Ir", "Iridium", "192.217", 9, 6,
  183. "Pt", "Platinum", "195.084", 10, 6,
  184. "Au", "Gold", "196.966569", 11, 6,
  185. "Hg", "Mercury", "200.59", 12, 6,
  186. "Tl", "Thallium", "204.3833", 13, 6,
  187. "Pb", "Lead", "207.2", 14, 6,
  188. "Bi", "Bismuth", "208.9804", 15, 6,
  189. "Po", "Polonium", "(209)", 16, 6,
  190. "At", "Astatine", "(210)", 17, 6,
  191. "Rn", "Radon", "(222)", 18, 6,
  192. "Fr", "Francium", "(223)", 1, 7,
  193. "Ra", "Radium", "(226)", 2, 7,
  194. "Ac", "Actinium", "(227)", 4, 10,
  195. "Th", "Thorium", "232.03806", 5, 10,
  196. "Pa", "Protactinium", "231.0588", 6, 10,
  197. "U", "Uranium", "238.02891", 7, 10,
  198. "Np", "Neptunium", "(237)", 8, 10,
  199. "Pu", "Plutonium", "(244)", 9, 10,
  200. "Am", "Americium", "(243)", 10, 10,
  201. "Cm", "Curium", "(247)", 11, 10,
  202. "Bk", "Berkelium", "(247)", 12, 10,
  203. "Cf", "Californium", "(251)", 13, 10,
  204. "Es", "Einstenium", "(252)", 14, 10,
  205. "Fm", "Fermium", "(257)", 15, 10,
  206. "Md", "Mendelevium", "(258)", 16, 10,
  207. "No", "Nobelium", "(259)", 17, 10,
  208. "Lr", "Lawrencium", "(262)", 18, 10,
  209. "Rf", "Rutherfordium", "(267)", 4, 7,
  210. "Db", "Dubnium", "(268)", 5, 7,
  211. "Sg", "Seaborgium", "(271)", 6, 7,
  212. "Bh", "Bohrium", "(272)", 7, 7,
  213. "Hs", "Hassium", "(270)", 8, 7,
  214. "Mt", "Meitnerium", "(276)", 9, 7,
  215. "Ds", "Darmstadium", "(281)", 10, 7,
  216. "Rg", "Roentgenium", "(280)", 11, 7,
  217. "Cn", "Copernicium", "(285)", 12, 7,
  218. "Uut", "Unutrium", "(284)", 13, 7,
  219. "Fl", "Flerovium", "(289)", 14, 7,
  220. "Uup", "Ununpentium", "(288)", 15, 7,
  221. "Lv", "Livermorium", "(293)", 16, 7,
  222. "Uus", "Ununseptium", "(294)", 17, 7,
  223. "Uuo", "Ununoctium", "(294)", 18, 7
  224. ];
  225. var camera, scene, renderer;
  226. var controls;
  227. var objects = [];
  228. var targets = { table: [], sphere: [], helix: [], grid: [] };
  229. init();
  230. animate();
  231. function init() {
  232. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
  233. camera.position.z = 3000;
  234. scene = new THREE.Scene();
  235. // table
  236. for ( var i = 0; i < table.length; i += 5 ) {
  237. var element = document.createElement( 'div' );
  238. element.className = 'element';
  239. element.style.backgroundColor = 'rgba(0,127,127,' + ( Math.random() * 0.5 + 0.25 ) + ')';
  240. var number = document.createElement( 'div' );
  241. number.className = 'number';
  242. number.textContent = (i/5) + 1;
  243. element.appendChild( number );
  244. var symbol = document.createElement( 'div' );
  245. symbol.className = 'symbol';
  246. symbol.textContent = table[ i ];
  247. element.appendChild( symbol );
  248. var details = document.createElement( 'div' );
  249. details.className = 'details';
  250. details.innerHTML = table[ i + 1 ] + '<br>' + table[ i + 2 ];
  251. element.appendChild( details );
  252. var object = new THREE.CSS3DObject( element );
  253. object.position.x = Math.random() * 4000 - 2000;
  254. object.position.y = Math.random() * 4000 - 2000;
  255. object.position.z = Math.random() * 4000 - 2000;
  256. scene.add( object );
  257. objects.push( object );
  258. //
  259. var object = new THREE.Object3D();
  260. object.position.x = ( table[ i + 3 ] * 140 ) - 1330;
  261. object.position.y = - ( table[ i + 4 ] * 180 ) + 990;
  262. targets.table.push( object );
  263. }
  264. // sphere
  265. var vector = new THREE.Vector3();
  266. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  267. var phi = Math.acos( -1 + ( 2 * i ) / l );
  268. var theta = Math.sqrt( l * Math.PI ) * phi;
  269. var object = new THREE.Object3D();
  270. object.position.x = 800 * Math.cos( theta ) * Math.sin( phi );
  271. object.position.y = 800 * Math.sin( theta ) * Math.sin( phi );
  272. object.position.z = 800 * Math.cos( phi );
  273. vector.copy( object.position ).multiplyScalar( 2 );
  274. object.lookAt( vector );
  275. targets.sphere.push( object );
  276. }
  277. // helix
  278. var vector = new THREE.Vector3();
  279. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  280. var phi = i * 0.175 + Math.PI;
  281. var object = new THREE.Object3D();
  282. object.position.x = 900 * Math.sin( phi );
  283. object.position.y = - ( i * 8 ) + 450;
  284. object.position.z = 900 * Math.cos( phi );
  285. vector.x = object.position.x * 2;
  286. vector.y = object.position.y;
  287. vector.z = object.position.z * 2;
  288. object.lookAt( vector );
  289. targets.helix.push( object );
  290. }
  291. // grid
  292. for ( var i = 0; i < objects.length; i ++ ) {
  293. var object = new THREE.Object3D();
  294. object.position.x = ( ( i % 5 ) * 400 ) - 800;
  295. object.position.y = ( - ( Math.floor( i / 5 ) % 5 ) * 400 ) + 800;
  296. object.position.z = ( Math.floor( i / 25 ) ) * 1000 - 2000;
  297. targets.grid.push( object );
  298. }
  299. //
  300. renderer = new THREE.CSS3DRenderer();
  301. renderer.setSize( window.innerWidth, window.innerHeight );
  302. renderer.domElement.style.position = 'absolute';
  303. document.getElementById( 'container' ).appendChild( renderer.domElement );
  304. //
  305. controls = new THREE.TrackballControls( camera, renderer.domElement );
  306. controls.rotateSpeed = 0.5;
  307. controls.minDistance = 500;
  308. controls.maxDistance = 6000;
  309. controls.addEventListener( 'change', render );
  310. var button = document.getElementById( 'table' );
  311. button.addEventListener( 'click', function ( event ) {
  312. transform( targets.table, 2000 );
  313. }, false );
  314. var button = document.getElementById( 'sphere' );
  315. button.addEventListener( 'click', function ( event ) {
  316. transform( targets.sphere, 2000 );
  317. }, false );
  318. var button = document.getElementById( 'helix' );
  319. button.addEventListener( 'click', function ( event ) {
  320. transform( targets.helix, 2000 );
  321. }, false );
  322. var button = document.getElementById( 'grid' );
  323. button.addEventListener( 'click', function ( event ) {
  324. transform( targets.grid, 2000 );
  325. }, false );
  326. transform( targets.table, 2000 );
  327. //
  328. window.addEventListener( 'resize', onWindowResize, false );
  329. }
  330. function transform( targets, duration ) {
  331. TWEEN.removeAll();
  332. for ( var i = 0; i < objects.length; i ++ ) {
  333. var object = objects[ i ];
  334. var target = targets[ i ];
  335. new TWEEN.Tween( object.position )
  336. .to( { x: target.position.x, y: target.position.y, z: target.position.z }, Math.random() * duration + duration )
  337. .easing( TWEEN.Easing.Exponential.InOut )
  338. .start();
  339. new TWEEN.Tween( object.rotation )
  340. .to( { x: target.rotation.x, y: target.rotation.y, z: target.rotation.z }, Math.random() * duration + duration )
  341. .easing( TWEEN.Easing.Exponential.InOut )
  342. .start();
  343. }
  344. new TWEEN.Tween( this )
  345. .to( {}, duration * 2 )
  346. .onUpdate( render )
  347. .start();
  348. }
  349. function onWindowResize() {
  350. camera.aspect = window.innerWidth / window.innerHeight;
  351. camera.updateProjectionMatrix();
  352. renderer.setSize( window.innerWidth, window.innerHeight );
  353. render();
  354. }
  355. function animate() {
  356. requestAnimationFrame( animate );
  357. TWEEN.update();
  358. controls.update();
  359. }
  360. function render() {
  361. renderer.render( scene, camera );
  362. }
  363. </script>
  364. </body>
  365. </html>