canvas 绘制多条不同颜色的折线 使用beginPath
绘制多条不同颜色的折线
注意:
需使用beginPath 创建一个新的路径
stroke 根据当前的画线样式,绘制已存在的路径
不使用beginPath ,stroke将会重新绘制路径,覆盖之前的颜色
var canvas=document.getElementById('canvas');
var context=canvas.getContext('2d');
context.lineWidth=10;
context.beginPath();
context.lineTo(50,100);
context.lineTo(150,200);
context.lineTo(50,300);
context.strokeStyle="red";
context.stroke();
context.beginPath();
context.lineTo(150,100);
context.lineTo(250,200);
context.lineTo(150,300);
context.strokeStyle="blue";
context.stroke();
