HTML Canvas Space ship with thrust

Description

HTML Canvas Space ship with thrust

View in separate window

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ship Thrust</title>

</head>/*  w  ww .j ava 2  s. c om*/
<body>
<div style="position: absolute; top: 50px; left: 50px;">
<canvas id="canvas" width="200" height="200">
 Your browser does not support the HTML 5 Canvas. 
</canvas>
</div>
<script type="text/javascript">
  let theCanvas = document.getElementById('canvas');
    let context = theCanvas.getContext('2d');
  drawScreen();

  function drawScreen() {
    // draw background and text 
    context.fillStyle = '#000000';
      context.fillRect(0, 0, 200, 200);
    context.fillStyle    = '#ffffff';
    context.font         = '20px sans-serif';
    context.textBaseline = 'top';
    context.fillText  ("Player Ship - Thrust", 0, 180);

    //drawShip
    context.strokeStyle = '#ffffff';
    context.beginPath();
    context.moveTo(10,0); 
    context.lineTo(19,19);
    context.lineTo(10,9);
    context.moveTo(9,9); 
    context.lineTo(0,19);
    context.lineTo(9,0);
    
    //draw thrust
    context.moveTo(8,13); 
    context.lineTo(11,13);
    context.moveTo(9,14);
    context.lineTo(9,18);
    context.moveTo(10,14);
    context.lineTo(10,18);
    
    context.stroke();
    context.closePath();
   }


</script> 
</body>
</html>



PreviousNext

Related