小编Ber*_*ric的帖子

Javascript画布箭头 - 箭头未指向行尾

我正在使用此代码在画布上绘制箭头:

var arrowCanvas = document.getElementById("arrowCanvas");
var ctx = arrowCanvas.getContext("2d");
drawArrow(ctx, 30, 10, 30, 100);

function drawArrow(ctx, fromx, fromy, tox, toy){
    //variables to be used when creating the arrow
    var headlen = 10;
    ctx.strokeStyle = "#cc0000";
    ctx.fillStyle = "#cc0000";
    ctx.lineWidth = 10;
    var angle = Math.atan2(toy-fromy,tox-fromx);

    //starting path of the arrow from the start square to the end square and drawing the stroke
    ctx.beginPath();
    ctx.moveTo(fromx, fromy);
    ctx.lineTo(tox, toy);
    ctx.stroke();

    //starting a new path from the head of the arrow to one …
Run Code Online (Sandbox Code Playgroud)

html javascript canvas

1
推荐指数
1
解决办法
853
查看次数

标签 统计

canvas ×1

html ×1

javascript ×1