Draw a quadratic curve on the HTML5 canvas

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

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

     ctx.beginPath();
     ctx.moveTo(100, 250);
     ctx.quadraticCurveTo(250, 100, 400, 250);
     ctx.lineWidth = 5;

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

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

Responses

0 Replies