astrostrings

Untitled

May 20th, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 5.97 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <!-- Code adapted from ESPL: Dances of the Planets http://ensign.editme.com/t43dances -->
  5.     <meta charset="utf-8" />
  6.     <title>Planets</title>
  7.     <script type="text/javascript">
  8.  
  9.  
  10.         function draw_orbits() {
  11.  
  12.             var p = document.getElementById("ddlPlanet1");
  13.             var p1 = p.options[p.selectedIndex].value;
  14.             p = document.getElementById("ddlPlanet2");
  15.             var p2 = p.options[p.selectedIndex].value;
  16.  
  17.             var c;
  18.             var pi = Math.PI;
  19.  
  20.             p = document.getElementById("ddlOrbits");
  21.             var Orbits = p.options[p.selectedIndex].value;
  22.             var p1y = getYear(p1);
  23.             var p2y = getYear(p2);
  24.             var p1r = getOrbit(p1);
  25.             var p2r = getOrbit(p2);
  26.             var Interval = p1y / 75;
  27.             var yBot = 700;
  28.             var yCen = 2 + yBot / 2;
  29.             var xCenter = 50 + yCen;
  30.             var r1 = yCen;
  31.             var r2 = r1 * p2r / p1r;
  32.             var r = 0;
  33.             var rStp = p1y * Orbits;
  34.             var a1 = 0;
  35.             var a1Int = 2 * pi * Interval / p1y;
  36.             var a2 = 0;
  37.             var a2Int = 2 * pi * Interval / p2y;
  38.  
  39.             var canvas = document.getElementById("my-canvas");
  40.             var context = canvas.getContext("2d");
  41.             clearCanvas(context, canvas);
  42.             // set transparency value
  43.             context.globalAlpha = 1.0;
  44.             // lineWidth 1.0 is the default
  45.             context.lineWidth = 1.0;
  46.  
  47.             while (r < rStp) {
  48.                context.beginPath();
  49.                i = Math.floor(r / Interval / 75);
  50.                switch (i) {
  51.                    case 0: c = "#000"; break;
  52.                    case 1: c = "#0000ff"; break;
  53.                    case 2: c = "#ff0000"; break;
  54.                    case 3: c = "#008000"; break;
  55.                    case 4: c = "#800080"; break;
  56.                    case 5: c = "#800000"; break;
  57.                    case 6: c = "#000080"; break;
  58.                    case 7: c = "#8b0000"; break;
  59.                        c = "#ffa500";
  60.                }
  61.  
  62.                a1 = a1 - a1Int;
  63.                a2 = a2 - a2Int;
  64.                x1 = r1 * Math.cos(a1);
  65.                y1 = r1 * Math.sin(a1);
  66.                x2 = r2 * Math.cos(a2);
  67.                y2 = r2 * Math.sin(a2);
  68.  
  69.  
  70.                context.moveTo(x1 + xCenter, y1 + yCen);
  71.                context.lineTo(x2 + xCenter, y2 + yCen);
  72.                context.strokeStyle = c;
  73.                context.stroke();
  74.                r = r + Interval;
  75.  
  76.            }
  77.        }
  78.  
  79.        function getYear(y) {
  80.            switch (y) {
  81.                case "1": return 88;
  82.                case "2": return 224.7;
  83.                case "3": return 365.2;
  84.                case "4": return 687;
  85.                case "5": return 4331;
  86.                case "6": return 10747;
  87.                case "7": return 30589;
  88.                case "8": return 59800;
  89.                case "9": return 90588;
  90.            }
  91.        }
  92.  
  93.        function getOrbit(o) {
  94.            switch (o) {
  95.                case "1": return 57.91;
  96.                case "2": return 108.21;
  97.                case "3": return 149.60;
  98.                case "4": return 227.92;
  99.                case "5": return 778.57;
  100.                case "6": return 1433.5;
  101.                case "7": return 2872.46;
  102.                case "8": return 4495.1;
  103.                case "9": return 5869.7;
  104.            }
  105.        }
  106.         //currently unused
  107.        function getName(n) {
  108.            switch (n) {
  109.                case "1": return 'Mercury'; break;
  110.                case "2": return 'Venus'; break;
  111.                case "3": return 'Earth'; break;
  112.                case "4": return 'Mars'; break;
  113.                case "5": return 'Jupiter'; break;
  114.                case "6": return 'Saturn'; break;
  115.                case "7": return 'Uranus'; break;
  116.                case "8": return 'Neptune'; break;
  117.                case "9": return 'Pluto'; break;
  118.            }
  119.        }
  120.  
  121.        function clearCanvas(context, canvas) {
  122.            context.clearRect(0, 0, canvas.width, canvas.height);
  123.            var w = canvas.width;
  124.            canvas.width = 1;
  125.            canvas.width = w;
  126.        }
  127.  
  128.    </script>
  129. </head>
  130. <body>
  131.     <form method="post" action="index.html" id="form1">
  132.     <p>
  133.         Planet 1 (outer):
  134.         <select id="ddlPlanet1">
  135.             <option value="1">Mercury</option>
  136.             <option value="2">Venus</option>
  137.             <option value="3">Earth</option>
  138.             <option value="4">Mars</option>
  139.             <option value="5">Jupiter</option>
  140.             <option value="6">Saturn</option>
  141.             <option value="7">Uranus</option>
  142.             <option value="8">Neptune</option>
  143.             <option value="9">Pluto</option>
  144.         </select>
  145.         &nbsp;Planet 2 (inner):
  146.         <select id="ddlPlanet2">
  147.             <option value="1">Mercury</option>
  148.             <option value="2">Venus</option>
  149.             <option value="3">Earth</option>
  150.             <option value="4">Mars</option>
  151.             <option value="5">Jupiter</option>
  152.             <option value="6">Saturn</option>
  153.             <option value="7">Uranus</option>
  154.             <option value="8">Neptune</option>
  155.             <option value="9">Pluto</option>
  156.         </select>
  157.         &nbsp; Orbits:
  158.         <select id="ddlOrbits">
  159.             <option value="1">1</option>
  160.             <option value="2">2</option>
  161.             <option value="3">3</option>
  162.             <option value="4">4</option>
  163.             <option value="5">5</option>
  164.             <option value="6">6</option>
  165.             <option value="7">7</option>
  166.             <option value="8">8</option>
  167.             <option value="9">9</option>
  168.         </select></p>
  169.     <input id="btn1" type="button" value="button" onclick="draw_orbits();return false" />
  170.     </form>
  171.     <canvas id="my-canvas" style="float: left" width="800" height="800"></canvas>
  172. </body>
  173. </html>
Advertisement
Add Comment
Please, Sign In to add comment