<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.lineWidth="5";
ctx.strokeStyle="red"; // 红色路径
ctx.moveTo(0,75);
ctx.lineTo(250,75);
ctx.stroke(); // 进行绘制
ctx.beginPath();
ctx.strokeStyle="blue"; // 蓝色路径
ctx.moveTo(50,0);
ctx.lineTo(150,130);
ctx.stroke(); cxt.fill();
</script>
</body>
</html>
beginPath:beginPath() 方法开始一条路径,或重置当前的路径。
moveTo(x , y):一条路径的开始,x/y分别是起始位置的横纵坐标。
lineTo(x , y) : 添加一个新点,然后创建从该点到画布中最后指定点的线条.
stroke() : 绘制当前路径.
closePath() : 方法关闭一条打开的子路径
11. strokeStyle属性:
和fillStyle 相似,不过fillStyle 是用于整个图形上色,而strokeStyle是给边缘上色。