雖然Alex的答案可能是比較正確的,
我想通了這個解決方案,我在XPOS/yPos那肯定會對應一個網格線佈局創建網格。
所以yPos/xPos
有現在correctedBoundingRectLeft
和correctedBoundingRectTop
從
吸引他們的計算代碼:
var drawGrid = function(boundingRect, cellSize) {
var vCellsNum = boundingRect.height/cellSize;
var hCellsNum = boundingRect.width/cellSize;
for (var i = 0; i <= hCellsNum; i++) {
var offsetXPos = Math.ceil(boundingRect.left/cellSize) * cellSize;
var xPos = offsetXPos + i * cellSize;
var topPoint = new paper.Point(xPos, boundingRect.top);
var bottomPoint = new paper.Point(xPos, boundingRect.bottom);
var line = new paper.Path.Line(topPoint, bottomPoint);
line.strokeColor = '#968d8d';
}
for (var i = 0; i <= vCellsNum; i++) {
var offsetYPos = Math.ceil(boundingRect.top/cellSize) * cellSize;
var yPos = offsetYPos + i * cellSize;
var leftPoint = new paper.Point(boundingRect.left, yPos);
var rightPoint = new paper.Point(boundingRect.right, yPos);
var line = new paper.Path.Line(leftPoint, rightPoint);
line.strokeColor = '#968d8d';
}
}
// where `30` is the cell width/height in px
drawGrid(paper.view.bounds, 30);
而一個Paper Sketch for the above
+1 paperjs問題上的SO。希望很多人都會效仿這個例子。 –