我正在尝试画出下面的三个箭头。我可以正确地绘制顶部,但我无法正确地绘制另外两个箭头头部。我正在使用HTML5 Canvas来绘制这些箭头。
问题出现在我的arcTo调用中。由于某种原因,我无法获得正确的曲线。也许我应该使用Bezier曲线?有谁能告诉我我应该使用哪些HTML5/Javascript函数来产生上面的箭头头部?
你能提供一个如何实现上述箭头头部的示例吗?
这是JSFiddle显示了错误的链接:http://jsfiddle.net/hJX8X/
<canvas id="testCanvas" width="400px" height="400px">
</canvas>
<script type="text/javascript">
<!--
var canvas = document.getElementById("testCanvas");
var dc = canvas.getContext("2d");
// Points which are correct (when I draw straight lines its a perfect arrow
var width = 400;
var height = 100;
var arrowW = 0.35 * width;
var arrowH = 0.75 * height;
var p1 = {x: 0, y: (height-arrowH)/2};
var p2 = {x: (width-arrowW), y: (height-arrowH)/2};
var p3 = {x: (width-arrowW), y: 0};
var p4 = {x: width, y: height/2};
var p5 = {x: (width-arrowW), y: height};
var p6 = {x: (width-arrowW), y: height-((height-arrowH)/2)};
var p7 = {x: 0, y: height-((height-arrowH)/2)};
dc.clearRect(0, 0, canvas.width, canvas.height);
dc.fillStyle = "#FF0000";
dc.beginPath();
dc.moveTo(p1.x, p1.y);
dc.lineTo(p2.x, p2.y);
dc.lineTo(p3.x, p3.y);
dc.moveTo(p3.x, p3.y);
dc.arcTo(p3.x, p3.y, p4.x, p4.y, 50);
dc.moveTo(p4.x, p4.y);
dc.arcTo(p4.x, p4.y, p5.x, p5.y, 50);
dc.moveTo(p5.x, p5.y);
dc.lineTo(p6.x, p6.y);
dc.lineTo(p7.x, p7.y);
dc.closePath();
dc.fill();
/* Draw arrow without curves
dc.moveTo(p1.x, p1.y);
dc.lineTo(p2.x, p2.y);
dc.lineTo(p3.x, p3.y);
dc.lineTo(p4.x, p4.y);
dc.lineTo(p5.x, p5.y);
dc.lineTo(p6.x, p6.y);
dc.lineTo(p7.x, p7.y);
*/
-->
</script>