jianghh-canvas
Version:
canvas画板,支持笔写、手写、鼠标流畅绘图,自动保存,撤销重做
18 lines (17 loc) • 588 B
JavaScript
const e = {
pointerdown({ offsetX: i, offsetY: s }) {
this.ctx.beginPath(), this.points.push({ x: i, y: s });
},
pointermove({ offsetX: i, offsetY: s }) {
if (this.points.push({ x: i, y: s }), this.points.length < 3)
return;
const t = this.points.slice(-2), n = t[0], o = {
x: (t[0].x + t[1].x) / 2,
y: (t[0].y + t[1].y) / 2
};
this.ctx.beginPath(), this.ctx.moveTo(this.beginPoint.x, this.beginPoint.y), this.ctx.quadraticCurveTo(n.x, n.y, o.x, o.y), this.ctx.stroke(), this.ctx.closePath(), this.beginPoint = o;
}
};
export {
e as Pen
};