3
我試圖創建一個等分爲五個部分的環。我的方法可能是非正統的,因爲我是JS/JQuery的新手。 下面是我的代碼:我試圖使用ctx.clip如何在畫布中剪下戒指?
var c=document.getElementById("c");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.arc(430,430,300,0,2*Math.PI,true);//x-y-r-angle-PI-rotation(clockwise vs anti//
ctx.closePath();
ctx.strokeStyle="#000";
ctx.stroke();
ctx.save();
ctx.beginPath();
ctx.arc(430,430,200,0,2*Math.PI);
ctx.closePath();
ctx.strokeStyle="#000";
ctx.stroke();
ctx.clip();
var drawAngledLine = function(x, y, length, angle) {
var radians = angle/180 * Math.PI;
var endX = x + length * Math.cos(radians);
var endY = y - length * Math.sin(radians);
ctx.beginPath();
ctx.moveTo(x, y)
ctx.lineTo(endX, endY);
ctx.closePath();
ctx.stroke();
}
ctx.strokeStyle = "#000";
ctx.lineWidth = "1";
drawAngledLine(430, 430, 300, -90);
drawAngledLine(430, 430, 300, -162);
drawAngledLine(430, 430, 300, -234);
drawAngledLine(430, 430, 300, -306);
drawAngledLine(430, 430, 300, -18);
ctx.restore();
ctx.beginPath();
ctx.arc(430,430,200,0,2*Math.PI,true);
ctx.strokeStyle="#000";
ctx.stroke();
(); 但它剪輯線的內部,我想它掩蓋內部,只顯示內部圈和外部圈之間的連接線。這很難解釋沒有圖像...
請有人可以幫忙。 提前歡呼。
Loktar IZ塔bezt –