css3d_periodictable.html 12 KB

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