Наши волонтёры ещё не перевели данную статью на Русский. Присоединяйтесь к нам и помогите закончить эту работу!
This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The CanvasRenderingContext2D
.ellipse()
method of the Canvas 2D API adds an ellipse to the path which is centered at (x, y) position with the radii radiusX and radiusY starting at startAngle and ending at endAngle going in the given direction by anticlockwise (defaulting to clockwise).
Syntax
void ctx.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
Parameters
x
- The x axis of the coordinate for the ellipse's center.
y
- The y axis of the coordinate for the ellipse's center.
radius
X- The ellipse's major-axis radius.
radius
Y- The ellipse's minor-axis radius.
rotation
- The rotation for this ellipse, expressed in radians.
startAngle
- The starting point, measured from the x axis, from which it will be drawn, expressed in radians.
endAngle
- The end ellipse's angle to which it will be drawn, expressed in radians.
anticlockwise
Optional- An optional
Boolean
which, iftrue
, draws the ellipse anticlockwise (counter-clockwise), otherwise in a clockwise direction.
Examples
Using the ellipse
method
This is just a simple code snippet drawing an ellipse.
HTML
<canvas id="canvas"></canvas>
JavaScript
var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.ellipse(100, 100, 50, 75, 45 * Math.PI/180, 0, 2 * Math.PI); ctx.stroke();
Edit the code below and see your changes update live in the canvas (check your Browser support in the compatibility table, if no ellipse is drawn):
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of 'CanvasRenderingContext2D.ellipse' in that specification. |
Living Standard |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Edge | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | 48 (48) | No support | 13 | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | (Yes) | 48.0 (48) | No support | No support | (Yes) |
See also
- The interface defining it,
CanvasRenderingContext2D