mamatthew
mamatthew

Reputation: 1

Defining rectangle position relative to existing rectangle in paper.js

I have created a rectangle in Paper.js and I would like to create a second rectangle. More specifically, I want to position the second rectangle so that it is right beside the first rectangle. However, I can't seem to do that. With my current code, I only get a single yellow rectangle:

var rect1 = new Path.Rectangle(view.center, new Size(50, 50));
rect1.fillColor = "yellow";


var rect2 = new Path.Rectangle(rect1.point + new Point(rect1.width, 0), new Size(50,50))
rect2.fillColor = "red";

The problem seems to be that defining rect2's position using rect1.point is not allowed. However, rect1.point is just the top left point of rect1, so rect1.point + new Point(rect1.width, 0) should give me another point.

Any help is appreciated!

Upvotes: 0

Views: 313

Answers (1)

sasensi
sasensi

Reputation: 4650

A convenient way of doing this kind of things is using the information contained into item.bounds. Here is a sketch demonstrating a possible solution to your case:

var rect1 = new Path.Rectangle(view.center, new Size(50, 50));
rect1.fillColor = "yellow";


var rect2 = new Path.Rectangle(rect1.bounds.bottomLeft, new Size(50,50))
rect2.fillColor = "red";

Upvotes: 1

Related Questions