Draw a circle on the HTML5 canvas

Fetches the canvas element. Creates a 2D context. Clears the canvas, then sets the fill style to red and then creates a circle path using the arc method. Finally it fills the circle with the red color.with the selected color.
<!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.clearRect(0, 0, canvas.width, canvas.height);

    ctx.fillStyle = 'red';
    ctx.beginPath(); 
    ctx.arc(70, 75, 50, 0 * Math.PI, 2 * Math.PI); 
    ctx.fill();

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

Responses

0 Replies