Erasing previously drawn lines on an HTML5 canvas

后端 未结 5 1683
臣服心动
臣服心动 2020-12-03 07:36

To play around with HTML5 canvas, I decided to make an app which draws an analogue clockface. Everything\'s fine, except that old lines don\'t get erased in the way that I w

5条回答
  •  醉酒成梦
    2020-12-03 08:00

    The reason you can't just redraw the line in white and hope for it to erase the old line is because there might be some anti-aliasing/bleeding. You'll also notice that a straight horizontal line drawn on a pixel versus a half-pixel looks very different because of this.

    When you do your white "erase" lines, try drawing them with a larger lineWidth by about 3 or 4. That should work for your case.

    You should also draw all of the white lines first, then all of the black lines, in case they intersect.

提交回复
热议问题