demo.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
canvas {
border: 1px solid red;
}
</style>
</head>
<body>
<canvas id="cvs" width="500" height="500"></canvas>
<script>
var cvs = document.getElementById('cvs');
var ctx = cvs.getContext('2d');
/*
* 闭合路径:
* 最后一个描点与最开始的描点自动连接起来。
* ctx.closePath()
* */
// 绘制一个等腰三角形的路径
ctx.moveTo( 110, 10 );
ctx.lineTo( 160, 60 );
ctx.lineTo( 60, 60 );
// 使用闭合路径解决锯齿(自动将起点和结束点连接起来)
ctx.closePath();
// 颜色设置,必须放在绘制之前
ctx.strokeStyle = 'yellow';
// 线宽设置,必须放在绘制之前
ctx.lineWidth = 6;
ctx.stroke();
</script>
</body>
</html>