go to previous page   go to home page   go to next page

Answer:

If the frame is doubled in width (from 350 to 700), how should every X dimension in the drawing be scaled?

Every X dimension should be multiplied by 1/2, (new width)/(old width)
For example, the width of the house, which was 150, should now be 150*0.5 = 75.

If the frame is reduced in height by 3/5 (from 250 to 150), how should every Y dimension in the drawing be scaled?

Every X dimension should be multiplied by 3/5, (new height)/(old height)
For example, Y coordinate of the house rectangle, which was 100, should now be 100*3/5 = 60.

Scaling

The program can calculate the scale factors using the methods getWidth() and getHeight() of the panel:

double xScale = ((double)getWidth()) /width;
double yScale = ((double)getHeight())/height;

You need to pay attention to integer division, or else you might get a scale factor of zero!


QUESTION 10:

Here is the statement from the original program that drew the rectangle for the house: Using the scale factors, modify the statement to draw a scaled rectangle:


Hint: drawRect() expects int parameters.