Javascript 如何使画布绘制流畅逼真
我正在使用以下代码为画布着色。但这条线并不平坦。在边缘,它更像一个盒子,而不是一个光滑的边缘。我怎样才能使它平滑和真实Javascript 如何使画布绘制流畅逼真,javascript,html,Javascript,Html,我正在使用以下代码为画布着色。但这条线并不平坦。在边缘,它更像一个盒子,而不是一个光滑的边缘。我怎样才能使它平滑和真实 function touchStartHandler(e) { var touch = e.changedTouches[0]; drawPath[touch.identifier] = touch; context.fillStyle = strokeColor; context.beginPath();
function touchStartHandler(e) {
var touch = e.changedTouches[0];
drawPath[touch.identifier] = touch;
context.fillStyle = strokeColor;
context.beginPath();
context.arc(drawPath[touch.identifier].pageX - content.offsetLeft,
drawPath[touch.identifier].pageY - content.offsetTop,
strokeWidth / 2, 0, Math.PI * 2, true);
context.closePath();
context.fill();
}
function touchMoveHandler(e) {
var touches = e.changedTouches, touchesLength = touches.length, currentDrawPath = null, i = 0;
context.lineWidth = strokeWidth;
context.strokeStyle = strokeColor;
context.lineJoin = 'round';
for (i = 0; i < touchesLength; i += 1) {
currentDrawPath = drawPath[touches[i].identifier];
if (currentDrawPath !== undefined) {
context.beginPath();
context.moveTo(currentDrawPath.pageX - content.offsetLeft,
currentDrawPath.pageY - content.offsetTop);
context.lineTo(touches[i].pageX - content.offsetLeft,
touches[i].pageY - content.offsetTop);
context.closePath();
context.stroke();
drawPath[touches[i].identifier] = touches[i];
}
}
e.preventDefault();
}
function touchEndHandler(e) {
var touch = e.changedTouches[0];
xposition = drawPath[touch.identifier].pageX;
delete drawPath[touch.identifier];
}`
函数touchStartHandler(e){
var touch=e.changedtouchs[0];
绘图路径[touch.identifier]=触摸;
context.fillStyle=strokeColor;
context.beginPath();
context.arc(绘图路径[touch.identifier].pageX-content.offsetLeft,
绘图路径[touch.identifier].pageY-content.offsetTop,
冲程宽度/2,0,Math.PI*2,真);
closePath();
context.fill();
}
函数touchMoveHandler(e){
var touchs=e.changedtouchs,touchesLength=touchs.length,currentDrawPath=null,i=0;
context.lineWidth=strokeWidth;
context.strokeStyle=strokeColor;
context.lineJoin='round';
对于(i=0;i提前谢谢