0
感謝上一個答案。 我在畫布上添加了一些更多的圖紙。我還將(*)所有內容都乘以3,以便更好地看到線條。 從頂部到底部有一條直線。 有沒有辦法找出哪裏「var hdr」會擊中那條線? 當hdr + h2命中該行時,需要計算h1。在畫布上查找線條位置
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="500" height="500" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var p1=7.5*3;
var p2=10.25*3;
var lp=16
var max = lp; // how many times
ctx.moveTo(0,0);
for(i=1; i <= max; i++){
ctx.lineTo(p2*(i-1),p1 * i);
ctx.lineTo(p2 * i,p1 * i);
}
ctx.lineTo(p2*lp,p1*lp);
ctx.lineTo(0,0);
ctx.stroke();
var htx = c.getContext("2d");
var h1=100*3//h1 needs to be calculated
var h2=12*3
var h3=3*3
var hdr=80*3
htx.rect(h1,0,h3,h2);
htx.stroke();
ctx.lineTo(h1,h2);
ctx.lineTo(h1,hdr);
ctx.stroke();
</script>
</body>
</html>