Advertisement
476179

M. C updated

Jan 16th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.53 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="utf-8">
  6.     <title>MOON LANDING</title>
  7. </head>
  8.  
  9. <body>
  10.     <canvas id="canvas1" width="640" height="480" style="border: 1px solid black; position:absolute; left:0; top 0; z-index: 1,"></canvas>
  11.    
  12.     <canvas id="canvas2" width="640" height="480" style="border: 1px solid black;position: absolute; left: 0; top 0; z-index: 2;"></canvas>
  13.    
  14.     <canvas id="canvas3" width="640" height="480" style="border: 1px solid black;position: absolute; left: 0; top 0; z-index: 4;"></canvas>
  15.    
  16.     <canvas id="canvas4" width="640" height="480" style="border: 1px solid black;position: absolute; left: 0; top 0; z-index: 3;"></canvas>
  17.    
  18.     <canvas id="canvas5" width="640" height="480" style="border: 1px solid black;position: absolute; left: 0; top 0; z-index: 4;"></canvas>
  19. <script>
  20.    
  21. var layer1 = document.getElementById("canvas1");
  22. var dt1 = layer1.getContext("2d");
  23. var layer2 = document.getElementById("canvas2");
  24. var dt2 = layer2.getContext("2d");
  25. var layer3 = document.getElementById("canvas3");
  26. var dt3 = layer3.getContext("2d");
  27. var layer4 = document.getElementById("canvas4");
  28. var dt4 = layer4.getContext("2d");
  29. var layer5 = document.getElementById("canvas5");
  30. var dt5 = layer5.getContext("2d");
  31.    /*
  32.    alert("You are about to witness a moon landing created by Matthew Grech!")
  33.     var rc= (prompt("First, lets chose the colour of the rocket that will appear! Pick from this list of avalible paint jobs." +  "1 = Red"+ ", 2 = Blue" + ", 3 = Purple" + ", 4 = White"))
  34.     alert("Great choice! See you on the moon with a" + rc + "spaceship flying above!")
  35.    
  36.     if (rc==="1")
  37.     {
  38.         var spaceship="red"
  39.     }
  40.    
  41.     else if (rc==="2")
  42.     {
  43.         var spaceship="blue"
  44.     }
  45.    
  46.     else if (rc==="3")
  47.     {
  48.         var spaceship="purple"
  49.     }
  50.    
  51.     else if (rc==="4")
  52.     {
  53.         var spaceship="white"
  54.     }
  55.    
  56.     else
  57.         {
  58.             alert("Sorry! We seem to be out of that paint. I'll fix you up with a fresh red paint job!")
  59.         }
  60.         */
  61.     //black background
  62.     dt1.fillStyle = "black";
  63.     dt1.fillRect(0, 0, 640, 480);
  64.    
  65.    //draw moon
  66.     dt1.fillStyle = "rgb(64, 64, 64)";
  67.     dt1.beginPath()
  68.     dt1.arc(320, 980, 600, 0, Math.PI/1, true)
  69.     dt1.stroke()
  70.     dt1.fill()
  71.     //draw details of moon
  72.     dt1.strokeStyle="rgb(179, 179, 179)"
  73.     dt1.fillStyle="rgb(179, 179, 179)"
  74.     dt1.beginPath()
  75.     dt1.arc(300, 460, 20, 0, 2*Math.PI);
  76.     dt1.stroke();
  77.     dt1.fill();
  78.    
  79.     dt1.strokeStyle="rgb(179, 179, 179)"
  80.     dt1.fillStyle="rgb(179, 179, 179)"
  81.     dt1.beginPath()
  82.     dt1.arc(200, 420, 23, 0, 2*Math.PI);
  83.     dt1.stroke();
  84.     dt1.fill();
  85.    
  86.     dt1.strokeStyle="rgb(179, 179, 179)"
  87.     dt1.fillStyle="rgb(179, 179, 179)"
  88.     dt1.beginPath()
  89.     dt1.arc(500, 450, 17, 0, 2*Math.PI);
  90.     dt1.stroke();
  91.     dt1.fill();
  92.    
  93.     dt1.strokeStyle="rgb(179, 179, 179)"
  94.     dt1.fillStyle="rgb(179, 179, 179)"
  95.     dt1.beginPath()
  96.     dt1.arc(100, 460, 13, 0, 2*Math.PI);
  97.     dt1.stroke();
  98.     dt1.fill();
  99.    
  100.     dt1.strokeStyle="rgb(179, 179, 179)"
  101.     dt1.fillStyle="rgb(179, 179, 179)"
  102.     dt1.beginPath()
  103.     dt1.arc(400, 430, 30, 0, 2*Math.PI);
  104.     dt1.stroke();
  105.     dt1.fill();
  106.    
  107.     //star input
  108. document.addEventListener("click", runFunc);
  109.  
  110.  //fuction for stars
  111. function runFunc()
  112. {
  113.   dt2.clearRect(0, 0, canvas2.width, canvas2.height)
  114.  
  115.     for(var i = 1; i <= 40; i++)//number of stars that appear on canvas
  116. {
  117.     star (Math.floor(Math.random()*640), (Math.random()*200)); //positioning of stars
  118. }
  119.    
  120. }
  121.  
  122.   //drawing the stars
  123.   function star(xPos, yPos)
  124.   {
  125.   dt2.strokeStyle = "black";
  126.   dt2.fillStyle = "yellow";
  127.   dt2.lineJoin = "miter";
  128.   dt2.beginPath();
  129.   dt2.moveTo(xPos,yPos);
  130.   dt2.lineTo(xPos+5,yPos+10);
  131.   dt2.lineTo(xPos+15,yPos+10);
  132.   dt2.lineTo(xPos+7,yPos+15);
  133.   dt2.lineTo(xPos+10,yPos+23);
  134.   dt2.lineTo(xPos,yPos+19);
  135.   dt2.lineTo(xPos-10,yPos+23);
  136.   dt2.lineTo(xPos-7,yPos+15);
  137.   dt2.lineTo(xPos-15,yPos+10);
  138.   dt2.lineTo(xPos-5,yPos+10);
  139.   dt2.lineTo(xPos,yPos);
  140.   dt2.stroke();
  141.   dt2.closePath()
  142.   dt2.fill()
  143.   }
  144.  
  145. //animation of spaceship  
  146. var rectXPos = 0;
  147. var speed = 5;
  148. var y = 50
  149.  
  150. setInterval(draw, 30);
  151.  
  152. //draws the spaceship and the trail behind it
  153. function draw()
  154. {
  155.   spaceship();
  156.   trail()
  157. }
  158.  
  159.    //function for spaceship
  160. function spaceship()
  161. {
  162.    
  163.    //body of spaceship
  164.   dt3.clearRect(0, 0, layer3.width, layer3.height);
  165.   dt3.fillStyle = 'red';
  166.   dt3.strokeStyle = "black";
  167.   dt3.fillRect(rectXPos, y, 75, 50);
  168.   dt3.strokeRect(rectXPos, y, 75, 50);
  169.    
  170.    //upper wing
  171.    dt3.strokeStyle = "darkRed";
  172.    dt3.fillStyle = "darkRed"
  173.    dt3.lineWidth = 5;
  174.    dt3.beginPath();
  175.    dt3.moveTo(rectXPos, y);
  176.    dt3.quadraticCurveTo(rectXPos-30, y-40, rectXPos+80, y);
  177.    dt3.stroke();
  178.    dt3.fill();
  179.    
  180.   //lower wing
  181.    dt3.strokeStyle = "darkRed";
  182.    dt3.fillStyle = "darkRed"
  183.    dt3.lineWidth = 5;
  184.    dt3.beginPath();
  185.    dt3.moveTo(rectXPos+80, y+50);
  186.    dt3.quadraticCurveTo(rectXPos-30, y+100, rectXPos, y+50);
  187.    dt3.stroke();
  188.    dt3.fill();
  189.  
  190.   //window
  191.    dt3.fillStyle= "white"
  192.    dt3.beginPath();
  193.    dt3.arc(rectXPos+30, y+20, 4, 0, 2*Math.PI);
  194.    dt3.stroke();
  195.    dt3.fill();
  196.  
  197.    rectXPos = rectXPos + speed;
  198.    
  199.  
  200.  
  201.   //keeps spaceship from going off canvas and never coming back
  202.   if (rectXPos <0 || rectXPos >640)
  203.         {
  204.             rectXPos = 0;
  205.             y=Math.random()*410+1
  206.             dt5.clearRect(0, 0, canvas5.width, canvas5.height)
  207.         }
  208.  
  209. }
  210.    
  211.    
  212.     //input to cause particles to activate is a mouse move
  213.    document.addEventListener("mousemove", runFunc1);
  214.  
  215.  
  216. function runFunc1()
  217. {
  218.     dt4.clearRect(0, 0, canvas4.width, canvas4.height)//clears canvas
  219.  
  220.     for(var i = 1; i <= 60; i++)//counts number of particles on canvas
  221. {
  222.     particle (Math.floor(Math.random()*640), (Math.random()*250) +25);//postions particles
  223. }
  224. }
  225.  
  226.  
  227.  
  228.   function particle(xPos, yPos)
  229.  
  230.   {
  231.       dt4.fillStyle = "white"
  232.       dt4.beginPath();
  233.       dt4.arc(xPos, yPos, 2, 0, 2*Math.PI);
  234.       dt4.fill();
  235.   }
  236.  
  237.   function trail()
  238.    {
  239.   dt5.fillStyle = "#ffffff";
  240.   dt5.fillRect(rectXPos, y+20, 5, 5);
  241.   dt5.fillRect(rectXPos, y+40, 5, 5);
  242.   dt5.fillStyle = "red";
  243.   dt5.fillRect(rectXPos, y+30, 5, 5);
  244.   dt5.fillRect(rectXPos, y+10, 5, 5);
  245.        rectXPos = rectXPos +speed;
  246.    }
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254. </script>
  255.  
  256. </body>
  257.    
  258. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement