HTML5 Game - Canvas Shape Play button

Description

Play button

Demo

ResultView the demo in separate window

<!doctype html>
<html>
  <head>
    <title>Drawing a spaceship</title>
  </head>//from   www.  j  a  v a 2s .c  om
  <body>
    <h1>Drawing a spaceship</h1>
    <canvas id="balls" width="400" height="400"></canvas>
    <script>
let context = document.getElementById("balls").getContext("2d");


function draw_ship(ctx, radius, options) {
  options = options || {};
  ctx.save();

    ctx.strokeStyle = "white";
    ctx.fillStyle = "rgba(0, 0, 0, 0.25)";
    ctx.lineWidth = 0.5;
    ctx.beginPath();
    ctx.arc(0, 0, radius, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.fill();

  ctx.lineWidth = options.lineWidth || 2;
  ctx.strokeStyle = options.stroke || "white";
  ctx.fillStyle = options.fill || "black";
  let angle = (options.angle || 0.5 * Math.PI) / 2;
  ctx.beginPath();
  ctx.moveTo(radius, 0);
  ctx.lineTo(
    Math.cos(Math.PI - angle) * radius,
    Math.sin(Math.PI - angle) * radius
  );
  ctx.lineTo(
    Math.cos(Math.PI + angle) * radius,
    Math.sin(Math.PI + angle) * radius
  );
  ctx.closePath();
  ctx.fill();
  ctx.stroke();
  ctx.restore();
}


context.translate(300, 300);
draw_ship(context, 100);
    </script>
  </body>
</html>