houseX
, and houseW
what is the X value of the center?
houseX
+ houseW/2
doorW
,
what is the X value of the left edge of the door, doorX
?
doorX
= center - doorW/2
= houseX
+ houseW/2
- doorW/2
These calculations can be plugged into the declaration section:
final int width = 350, height = 250;
final int houseX = 50, houseY = 100, houseW = 150, houseH = 100 ;
final int doorY = 150, doorW = 20, doorH = 50 ;
final int lWindX = 75, lWindY = 140, lWindW = 25, lWindH = 40 ;
final int rWindX = 160, rWindY = 140, rWindW = 25, rWindH = 40 ;
final int trunkX = 260, trunkY = 65, trunkW = 10, trunkH = 100 ;
final int doorX = houseX + houseW/2 - doorW/2;
The same sort of calculation could be done with other points in the picture. But let's move on to the tree. Look at the graph paper sketch again (click here to see it) and estimate the location of the upper left corner, the width, and the height of the rectangle that contains the tree's foliage,
Fill in the blanks with values for the rectangle that bounds the tree's foliage.