启动一次绘制
设置画笔起点
设置起点,绘制线段;如果不设置起点,绘制点。
设置画笔终点
执行绘制
const ctx = canvas.getContext("2d")
let lock = false
const canvasDown = () => {
lock = true
ctx.beginPath()
ctx.strokeStyle = options.color
ctx.shadowBlur = options.scale
ctx.shadowColor = options.color
}
const canvasMove = ({ offsetX, offsetY }) => {
if (!lock) return
ctx.lineTo(offsetX, offsetY)
ctx.stroke()
}
const canvasUp = () => {
lock = false
}
canvas.addEventListener("mousedown", canvasDown)
canvas.addEventListener("mousemove", canvasMove)
canvas.addEventListener("mouseup", canvasUp)