あなたが望むすべての行の場合:あなたは、各矩形は個々の長方形のためのhitTestに別のパスになりたい場合は
var drawGridLines = function(num_rectangles_wide, num_rectangles_tall, boundingRect) {
var width_per_rectangle = boundingRect.width/num_rectangles_wide;
var height_per_rectangle = boundingRect.height/num_rectangles_tall;
for (var i = 0; i <= num_rectangles_wide; i++) {
var xPos = boundingRect.left + i * width_per_rectangle;
var topPoint = new paper.Point(xPos, boundingRect.top);
var bottomPoint = new paper.Point(xPos, boundingRect.bottom);
var aLine = new paper.Path.Line(topPoint, bottomPoint);
aLine.strokeColor = 'black';
}
for (var i = 0; i <= num_rectangles_tall; i++) {
var yPos = boundingRect.top + i * height_per_rectangle;
var leftPoint = new paper.Point(boundingRect.left, yPos);
var rightPoint = new paper.Point(boundingRect.right, yPos);
var aLine = new paper.Path.Line(leftPoint, rightPoint);
aLine.strokeColor = 'black';
}
}
drawGridLines(4, 4, paper.view.bounds);
:
var drawGridRects = function(num_rectangles_wide, num_rectangles_tall, boundingRect) {
var width_per_rectangle = boundingRect.width/num_rectangles_wide;
var height_per_rectangle = boundingRect.height/num_rectangles_tall;
for (var i = 0; i < num_rectangles_wide; i++) {
for (var j = 0; j < num_rectangles_tall; j++) {
var aRect = new paper.Path.Rectangle(boundingRect.left + i * width_per_rectangle, boundingRect.top + j * height_per_rectangle, width_per_rectangle, height_per_rectangle);
aRect.strokeColor = 'white';
aRect.fillColor = 'black';
}
}
}
drawGridRects(4, 4, paper.view.bounds);
これは奇妙な質問のように思える、紙から.jsはベクターグラフィックスを描画するライブラリであり、特定のグラフィックを描画する方法を尋ねています。 moveTo、lineTo、moveTo、lineTo、...でパスを作成しようとしましたか? –
別のCanvasを使って、PaperJSの下に配置するだけで解決できます(z-indexはトリックを行います)。ジェームズが提案したようにグリッドをレンダリングします。 –