HTML canvas arc() Metoda
Příklad
Vytvořte kruh:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(100, 75, 50, 0, 2 * Math.PI);
ctx.stroke();
Podpora prohlížeče
Čísla v tabulce určují první verzi prohlížeče, která tuto metodu plně podporuje.
Method | |||||
---|---|---|---|---|---|
arc() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Definice a použití
Metoda arc() vytváří oblouk/křivku (používá se k vytváření kružnic nebo částí kružnic).
Tip: Chcete-li vytvořit kruh pomocí arc(): Nastavte počáteční úhel na 0 a koncový úhel na 2*Math.PI.
Tip: Pomocí metody stroke() nebo fill() skutečně nakreslete oblouk na plátno.
Centrum
oblouk( 100, 75 , 50, 0 * Math.PI, 1,5 * Math.PI)Počáteční úhel
oblouk(100, 75, 50, 0 , 1,5 * Math.PI)Koncový úhel
arc(100, 75, 50, 0 * Math.PI, 1,5 * Math.PI )
Syntaxe JavaScriptu: | kontext .arc( x, y, r, sAngle, eAngle, proti směru hodinových ručiček ); |
---|
Hodnoty parametrů
Parameter | Description | Play it |
---|---|---|
x | The x-coordinate of the center of the circle | |
y | The y-coordinate of the center of the circle | |
r | The radius of the circle | |
sAngle | The starting angle, in radians (0 is at the 3 o'clock position of the arc's circle) | |
eAngle | The ending angle, in radians | |
counterclockwise | Optional. Specifies whether the drawing should be counterclockwise or clockwise. False is default, and indicates clockwise, while true indicates counter-clockwise. |
❮ Objekt plátna