Java Reference
In-Depth Information
Figure 3G.16
Desired Pyramids Output
that widen toward the bottom, with black outlines around each stair. Table 3G.6 lists
the attributes of each pyramid.
Table 3G.6
Pyramid Attributes
Fill color
Top-left corner
Number of stairs
Height of each stair
white
(0, 0)
10 stairs
10 pixels
red
(80, 140)
5 stairs
20 pixels
blue
(220, 50)
20 stairs
5 pixels
Unstructured Partial Solution
When trying to solve a larger and more complex problem like this, it's important to
tackle it piece by piece and make iterative enhancements toward a final solution.
Let's begin by trying to draw the top-left white pyramid correctly.
Each stair is centered horizontally within the pyramid. The top stair is 10 pixels
90
2
wide. Therefore, it is surrounded by
or 45 pixels of empty space on either side.
That means that the 10
×
10 rectangle's top-left corner is at (45, 0). The second stair
80
2
is 20 pixels wide, meaning that it's surrounded by
or 40 pixels on each side:
(0, 0)
45
10
20
45
40
10
40
 
 
Search WWH ::




Custom Search