path.bounds 속성에는 회전 한 경우에도 개체의 경계가 포함됩니다. 이것은 당신이 그린 것을 바로 구현할 수있게합니다. 아래에서 만든 예제를 참조하십시오.
// Create an empty project and a view for the canvas:
paper.setup(document.getElementById('myCanvas'));
// Make the paper scope global, by injecting it into window:
paper.install(window);
// Create the original rectagle
var point = new Point(20, 20);
var size = new Size(60, 60);
var rect = new Path.Rectangle(point, size);
rect.fillColor = new paper.Color(1, 0, 0)
rect.rotation = 15;
// Create the bounds rectangle
var boundsPath = new Path.Rectangle(rect.bounds);
boundsPath.strokeColor = new Color(0, 0, 0);
// Make a nice little animation:
function onFrame(event) {
// Every frame, rotate the path by 2 degrees
rect.rotate(2);
// Recreate the bounds rectangle
boundsPath.remove();
boundsPath = new Path.Rectangle(rect.bounds);
boundsPath.strokeColor = new Color(0, 0, 0);
}
view.draw();
view.onFrame = onFrame;
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.9.22/paper-full.min.js"></script>
</head>
<body>
<canvas id="myCanvas" resize></canvas>
</body>
</html>