Html 5 Canvas complete arrowhead

前端 未结 5 1486
鱼传尺愫
鱼传尺愫 2021-01-14 08:47

I\'m using the wPaint plugin and I am attempting to add a few more features. What I need is a drawn line to end with an \"arrowhead\". I have tried just about everything I c

5条回答
  •  鱼传尺愫
    2021-01-14 09:22

    my simple solution

    ctx.beginPath(); 
    ctx.moveTo(ax,ay);
    ctx.lineTo(bx,by);
    ctx.stroke();
    ctx.closePath();
    angle=Math.PI+Math.atan2(by-ay,bx-ax);
    angle1=angle+Math.PI/6;
    angle2=angle-Math.PI/6;
    ctx.beginPath(); 
    ctx.moveTo(bx,by);
    ctx.arc(bx,by,5,angle1,angle2,true);
    ctx.lineTo(bx,by);
    ctx.fill();
    ctx.closePath();
    

提交回复
热议问题