Drawing to canvas like in paint

前端 未结 3 1577
小蘑菇
小蘑菇 2021-01-27 02:41

I have three arrys:

 clickX = [],
    clickY = [],
    clickDrag = [];

this is what happens when you click down:

$(\'#canvasCur         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 03:13

    Do not store painting to array
    It slows down drawing critically. Just draw the latest line without clearing canvas. That way lineWeight changes does not affect to before drawings. So remove ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); and for loop. You also might want to change context styles (lineWidth etc.) only when changes occur, not every time you run redraw() function.

    Undo support
    Making different canvas for every mouse down session and drawing them together you can easily make undo feature. By pressing undo it simply splices latest canvas out of canvases array. Google to learn more about drawing to temporary canvas.

提交回复
热议问题