The CanvasRenderingContext2D
.ellipse()
method of the Canvas 2D API adds an elliptical arc to the current sub-path.
void ctx.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle [, anticlockwise]);
The ellipse()
method creates an elliptical arc centered at (x, y)
with the radii radiusX
and radiusY
. The path starts at startAngle
and ends at endAngle
, and travels in the direction given by anticlockwise
(defaulting to clockwise).
x
y
radiusX
radiusY
rotation
startAngle
endAngle
anticlockwise
Optional
Boolean
which, if true
, draws the ellipse anticlockwise (counter-clockwise). The default value is false
(clockwise).This example draws an ellipse at an angle of π/4 radians (45°). To make a full ellipse, the arc begins at an angle of 0 radians (0°), and ends at an angle of 2π radians (360°).
<canvas id="canvas" width="200" height="200"></canvas>
const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); // Draw the ellipse ctx.beginPath(); ctx.ellipse(100, 100, 50, 75, Math.PI / 4, 0, 2 * Math.PI); ctx.stroke(); // Draw the ellipse's line of reflection ctx.beginPath(); ctx.setLineDash([5, 5]); ctx.moveTo(0, 200); ctx.lineTo(200, 0); ctx.stroke();
This example creates three elliptical paths with vaying properties.
<canvas id="canvas"></canvas>
const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); ctx.fillStyle = 'red'; ctx.beginPath(); ctx.ellipse(60, 75, 50, 30, Math.PI * .25, 0, Math.PI * 1.5); ctx.fill(); ctx.fillStyle = 'blue'; ctx.beginPath(); ctx.ellipse(150, 75, 50, 30, Math.PI * .25, 0, Math.PI); ctx.fill(); ctx.fillStyle = 'green'; ctx.beginPath(); ctx.ellipse(240, 75, 50, 30, Math.PI * .25, 0, Math.PI, true); ctx.fill();
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'CanvasRenderingContext2D.ellipse' in that specification. | Living Standard |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 31 | 13 | 48 | No | 18 | 9 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | No | Yes | Yes | Yes | No | Yes | Yes |
CanvasRenderingContext2D
CanvasRenderingContext2D.arc()
to draw a circular arc
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse