【发布时间】:2016-06-02 03:23:46
【问题描述】:
我有这段代码可以在 html 画布上显示风向:
var x, y, r, ctx, radians;
ctx = window.compass.getContext("2d");
radians = 0.0174533 * (10 - 90);
x = ctx.canvas.width / 2;
y = ctx.canvas.height / 2;
r = x * 0.8;
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height );
ctx.beginPath();
ctx.strokeStyle = "red"
ctx.fillStyle = "rgba(255,0,0,0.5)";
ctx.lineCap = 'square';
ctx.shadowOffsetX = 4;
ctx.shadowOffsetY = 4;
ctx.shadowBlur = 2;
ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
ctx.lineWidth = 10;
ctx.moveTo(x, y);
ctx.lineTo(x + r * Math.cos(radians), y + r * Math.sin(radians));
ctx.stroke();
我想在线条的起点添加箭头,即
x = ctx.canvas.width / 2; y = ctx.canvas.height / 2;
我该怎么做?
【问题讨论】:
-
参见this answer 作为参考。只需按照说明围绕头部旋转并用箭头替换圆圈即可。
-
在 html 画布中太难了
-
似乎是这样.. 我能想到的最好的办法是在我的起点画一个圆圈,它是静态的,不会随着我的线条变化而变化。不是很好的解决方案。
标签: javascript html canvas