monoteen

Orbit

Nov 23rd, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>TODO supply a title</title>
  5.         <meta charset="UTF-8">
  6.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.         <script>
  8.             window.onload = function () {
  9.                 var sun = document.getElementById('sun');
  10.                 var earth = document.getElementById('earth');
  11.                 var moon = document.getElementById('moon');
  12.                
  13.                 sun.style.position = 'absolute';
  14.                 earth.style.position = 'absolute';
  15.                 moon.style.position = 'absolute';
  16.  
  17.                 sun.style.left = 250 + 'px';
  18.                 sun.style.top = 200 + 'px';
  19.                
  20.                 var earthAngle = 0;
  21.                 var moonAngle = 0;
  22.  
  23.                 setInterval(function () {
  24.                     var earthLeft = 250 + 150 * Math.cos(earthAngle);
  25.                     var earthTop = 200 + 150 * Math.sin(earthAngle);
  26.                     var moonLeft = earthLeft + 50 * Math.cos(moonAngle);
  27.                     var moonTop = earthTop + 50 * Math.sin(moonAngle);
  28.  
  29.                     earth.style.left = earthLeft + 'px';
  30.                     earth.style.top = earthTop + 'px';
  31.                     moon.style.left = moonLeft + 'px';
  32.                     moon.style.top = moonTop + 'px';
  33.                    
  34.                     earthAngle += 0.1;
  35.                     moonAngle += 0.3;
  36.                 }, 1000 / 30);
  37.             };
  38.         </script>
  39.     </head>
  40.     <body>
  41.         <h1 id="sun"></h1>
  42.         <h1 id="earth"></h1>
  43.         <h1 id="moon"></h1>
  44.     </body>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment