我正在为 HMTL 5 2D 画布绘制五条水平线:
var canvas_ctx = my_canvas.getContext("2d");
canvas_ctx.lineWidth = 0.5;
canvas_ctx.strokeStyle = "black";
{
let line_x = 0;
let line_length = canvas_ctx.width;
let offset = 5;
let numLines = 5;
let numYincrement = 10;
for (let i=0;i<numLines * numYincrement;i+=numYincrement) {
//canvas_ctx.beginPath();
canvas_ctx.moveTo(line_x,i + offset);
canvas_ctx.lineTo(line_length,i + offset);
canvas_ctx.stroke();
//canvas_ctx.closePath();
}
}
理想情况下,这应该会产生 5 条黑线。相反,线条的颜色似乎随着每条新线条而褪色(好像它是一个渐变!),因此第 5 行是灰色的。如果我取消注释canvas_ctx.beginPath();
and canvas_ctx.closePath();
,所有行都变成灰色。为什么会这样??