Draw a bezier curve on the HTML5 canvas

Fetches the canvas element. Creates a 2D context. Creates the start point of the path, then creates the bezier path. Finally it sets the bezier curve stroke to green.
<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
    </style>
  </head>
  <body>
    <canvas id="myCanvas" width="600" height="300"></canvas>
    <script>

      var canvas = document.getElementById('myCanvas');
      var ctx = canvas.getContext('2d');

      ctx.beginPath();
      ctx.moveTo(188, 130);
      ctx.bezierCurveTo(140, 10, 388, 10, 388, 170);
      ctx.lineWidth = 5;

      ctx.strokeStyle = 'green';
      ctx.stroke();

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

Responses

0 Replies