我正嘗試創建一個重疊形狀的數組。但是我很難阻止那些堆疊在一起的形狀。如何使用畫布創建重疊 - 不堆疊 - 形狀?
我想我想讓它們齧合在一起,如果有意義的話?
下面的代碼:
var overlap_canvas = document.getElementById("overlap");
var overlap_context = overlap_canvas.getContext("2d");
var x = 200;
var y = x;
var rectQTY = 4 // Number of rectangles
overlap_context.translate(x,y);
for (j=0;j<rectQTY;j++){ // Repeat for the number of rectangles
// Draw a rectangle
overlap_context.beginPath();
overlap_context.rect(-90, -100, 180, 80);
overlap_context.fillStyle = 'yellow';
overlap_context.fill();
overlap_context.lineWidth = 7;
overlap_context.strokeStyle = 'blue';
overlap_context.stroke();
// Degrees to rotate for next position
overlap_context.rotate((Math.PI/180)*360/rectQTY);
}
而且這裏是我的jsfiddle: http://jsfiddle.net/Q8yjP/
這裏就是我想要實現:
任何幫助或指導將非常感謝!
和下投票是爲了什麼? – K3N
謝謝。這是一個很大的幫助,非常感謝您的意見。 – Mattarn