The following example demonstrates using a path to draw a triangle and fill it.
1, draw attention to the following two places:
(1) After the path has been drawn, call Closepath () to explicitly close the path.
(2) Look at the following code I actually only painted two edges, because Closepath () will automatically draw a line between the last drawing point and the start of the drawing.
(3) It is best to fill the color first, then draw the outline, otherwise the contour line will be partially covered by the fill color.
var canvas = document.getElementById ("MyCanvas");
var context = Canvas.getcontext ("2d");
Draw Path
Context.moveto (200, 50);
Context.lineto (100, 150);
Context.lineto (300,150);
Context.closepath ();
padding Internal
Context.fillstyle = "Orange";
Context.fill ();
Draw outline
Context.linewidth = 10;
Context.strokestyle = "#cd2828";
Context.stroke ();
2, set the LineJoin property of the drawing context to specify the shape of the segment intersection
(1) Mitre: Sharp angle chamfering (default value)
(2) Round: Round Head
Context.linejoin = "Round";
(3) Bevel: Flat head oblique cut
Context.linejoin = "Bevel";