Méthode HTML canvas arc()
Exemple
Créer un cercle :
JavaScript :
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(100, 75, 50, 0, 2 * Math.PI);
ctx.stroke();
Prise en charge du navigateur
Les nombres dans le tableau indiquent la première version du navigateur qui prend entièrement en charge la méthode.
Method | |||||
---|---|---|---|---|---|
arc() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Définition et utilisation
La méthode arc() crée un arc/courbe (utilisé pour créer des cercles ou des parties de cercles).
Astuce : Pour créer un cercle avec arc() : Définissez l'angle de départ sur 0 et l'angle de fin sur 2*Math.PI.
Astuce : Utilisez la méthode stroke() ou fill() pour dessiner l'arc sur le canevas.
Centre
arc( 100, 75 , 50, 0 * Math.PI, 1.5 * Math.PI)Angle de départ
arc(100, 75, 50, 0 , 1.5 * Math.PI)Angle final
arc(100, 75, 50, 0 * Math.PI, 1.5 * Math.PI )
Syntaxe JavaScript : | contexte .arc( x, y, r, sAngle, eAngle, antihoraire ); |
---|
Valeurs des paramètres
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. |
❮ Objet de toile