How do you draw a ellipse or oval on HTML5 canvas?

Use HTML5 canvas' bezierCurveTo method in JavaScript:


  • Move to the top center of the ellipse (A1).
  • Draw a béizer curve to bottom center of the ellipse (A2) with controls points at the right corners (C1 and C2).
  • Draw a béizer curve back to top center of the ellipse (A1)with controls points at the left corners (C3 and C4).

Steps for drawing an ellipse or oval

function drawEllipse(centerX, centerY, width, height) {
	
  context.beginPath();
  
  context.moveTo(centerX, centerY - height/2); // A1
  
  context.bezierCurveTo(
    centerX + width/2, centerY - height/2, // C1
    centerX + width/2, centerY + height/2, // C2
    centerX, centerY + height/2); // A2

  context.bezierCurveTo(
    centerX - width/2, centerY + height/2, // C3
    centerX - width/2, centerY - height/2, // C4
    centerX, centerY - height/2); // A1
 
  context.fillStyle = "red";
  context.fill();
  context.closePath();	
}