The maprectangle( function maps the position and size of a rectangle within a template rectangle into the same relative position and size within a goal rectangle.
This function has five parameters:
original – The rectangle to be positioned.
template – The template rectangle.
goal – The rectangle that the original rectangle will be positioned inside of.
elasticv – Vertical elastic slider position, see discussion in text below (this parameter is optional).
elastich – Horizontal elastic slider position, see discussion in text below (this parameter is optional).
This function maps the position and size of a rectangle within a template rectangle into the the same relative position and size in a second rectangle. It will scale and shift the original rectangle as necessary to achieve this.
To illustrate this, we’ll start with three local variables that we will fill with rectangles.
We’ll start with a frame rectangle that is 100 high by 100 wide.
originalFrame=rectanglesize(50, 50, 100, 100)
The second rectangle is 30 high by 40 wide. It is inset inside the first rectangle, 10 down and 10 across from the upper left hand corner of the first rectangle.
testRectangle=rectanglesize(60, 60, 30, 40)
Next is another frame rectangle that is twice as big as the original one: 200 by 200.
newFrame=rectanglesize(50, 300, 200, 200)
Finally we calculate the position of a new rectangle that occupies the same relative spot in newFrame that the testRectangle occupied in originalFrame. Since newFrame is twice as big, the new rectangle is also twice as big, and it is also twice as far from the top left corner of the new frame.
maprectangle(testRectangle, originalFrame, newFrame) ☞ 70, 320, 60, 80
If you add two extra parameters the maprectangle( function morphs by sliding individual points instead of by proportional resizing. The extra parameters divide the template rectangle, originalFrame, into four quadrants. Each corner of the original rectangle is checked to see which quadrant it is in. If it is in the upper left quadrant, the corner doesn’t move. If it is in the upper right quadrant, it moves horizontally. If it is in the lower left quadrant, it moves vertically. If it is in the lower right quadrant, it moves diagonally. This is very similar to the way that elastic forms work.
Assuming the same values as above for testRectangle, originalFrame and newFrame, this example moves the right edge of testRectangle to the right, but the left edge stays in position at 10 points from the left edge of the new frame.
maprectangle(testRectangle, originalFrame, newFrame, 50, 30) ☞ 60, 310, 30, 140
By swapping the last two parameters now only the bottom right corner of testRectangle moves, the other 3 stay locked in place.
maprectangle(testRectangle, originalFrame, newFrame, 30, 50) ☞ 60, 310, 130, 140
|10.0||New||New in this version.|