Run the application program villagesW. Now the houses have a door and windows.
Open the project villages. and run it. Only the first house appears. Look at the source code villages.cp.
Two More Houses
(1) Add code to twoMoreHouses to create a large house in the lower left of the drawing window and a small house
in the upper left of the drawing window. These do not have to be the same sizes
or in the same positions as the ones in the application program villages .
First Village
(2) Add code to firstVillage to create sixteen identical houses in four rows of four houses. This should be done with a pair of nested for loops. The width and height should be the same for all the houses, somewhere between 20 and 45.
Make sure you get this working correctly before you go on.
(3) First Village was pretty dull with its rows of identical houses. In your
second village, you will use a random number generator to alter the width and height
of the houses. Do not
alter the function house. You should start by using select
, copy
,
and paste
to copy the body of the function
FirstVillage into function
SecondVillage.
Don't let the houses get too small or too big. Try something like:
More Town Houses
(5) Use RandomLong to add a little more variety to your houses. Add code to the function
moreTownHouses to make a row of houses, across the middle of the drawing window with random width between 15 and 25, random height between 40 and 90. Draw only those houses that fit entirely in the Drawing window,
i.e. houses that satisfy: x + width <= 200.
This task is different than the last one in two ways. The x coordinate for each house depends on the width and position of the last house and you must decide whether a house is going to fit before you draw it. Use a while loop.
Random Houses - the Last Village
(6) Generate and draw ten random houses. You should use one
for loop in which all four parameters are set to random values in suitable ranges.
These are better houses; see below.
Better Houses
Up to this point, you should not have altered the function house. No matter what size or shape or position your houses had, they all had black bottoms
and white tops and no windows or doors or chimneys. Now it's time to build a better
house. Only the function house should be changed. You may add windows or doors or chimneys or trees of steps...
You may make the houses flat roofed with windows on one or more stories. The number
of stories could depend on the height. Use your imagination.
(7) Make some improvement in the house design.
Make a screen dump
of your last village with your new and improved houses and add it to your lab report.
Turn in:
A printed copy of your source code.
A print of your screen dump.
A diskette with
your source code (villages.cp)
your project (villages. )
your application (villages).