Starting from:

$29.99

IFB104 Assignment 1, Part A: Cityscapes Solution

Overview
This is the first part of a two-part assignment. This part is worth 20% of your final grade for IFB104. Part B will be worth a further 5%. Part B is intended as a last-minute extension to the assignment, thereby testing the maintainability of your code, and the instructions for completing it will not be released until Week 7. Whether or not you complete Part B you will submit only one file, and receive only one assessment, for the whole 25% assignment.
Motivation
One of the most basic functions of any IT system is to process a given data set to produce some form of human-readable output. This assignment requires you to produce a visual image by following instructions stored in a list. It tests your abilities to:
• Process lists of data values;
• Design a solution to a highly-repetitive computational problem;
• Display information in a visual form; and
• Produce maintainable, reusable code.
In particular, because this task is highly-repetitive it would be extremely tedious to solve it in a “brute-force” manner using lots of duplicated code. Instead you will need to think carefully about how to reuse parts of your solution, via well-planned function definitions and the use of iterative code, to make your own workload lighter and the resulting program more concise and easier to understand and maintain.
Goal
Working at QUT’s inner-city Gardens Point campus gives us a good view of Brisbane’s cityscape, consisting of numerous high-rise buildings in many different styles and of many different heights. In this assignment you are required to use Python’s Turtle graphics module to draw such a cityscape. To do so you must follow a set of instructions, in the form of a Python list, which specify where each building is to be placed, the specific style of the building, and the number of floors. Most importantly, this “city plan” will be generated randomly, so your solution must be sufficiently general that it can work correctly for any possible plan in this format.
Resources provided
A template Python 3 program, cityscapes.py, is provided with these instructions. When run it creates a drawing canvas and displays a simple background image on which you will draw your buildings. The default image drawn by the provided template appears as shown overleaf. It consists of a simple image of the greenfield location where the newly planned city will be built.

Note that in this template “home” coordinate (0, 0) is set low down in the “grassy” area, rather than the usual default of the drawing canvas’s centre. Also shown are the x and y axes (measured in pixels) and ten pre-determined “building sites”, from Site 1 to Site 10. The coordinates for the centre of each site are marked. This grid of coordinates is designed to help you position and size the drawings of your buildings. (To produce an uncluttered image you can disable drawing of the coordinate grid by setting the parameter to function create_drawing_canvas to False in the template’s main program.)
Your task is to extend this template file so that it can draw cityscapes on this empty field. To do so you must design four entirely distinct styles of building which can be drawn on any site and at any height from one floor to ten. Your code will consist of a function called build_city (and any auxiliary functions you create to support it). This function takes a single argument, which is a list of instructions specifying which buildings to draw and where. This “city plan” is created by a provided function called random_plan which randomly generates the instructions, so your code must work correctly for any possible city plan!
Data format
The random_plan function which will be used to assess your solution returns “city plans” as a list of building specifications. Each specification consists of the following parts:
1. The site on which to erect the building, from Site 1 to 10.
2. The style of building to be erected on that site, from style ‘A’ to ‘D’.
3. The number of floors to be constructed, from 1 to 10.
4. An extra value, either ‘X’ or ‘O’, whose purpose will be revealed only in Part B of the assignment. You should ignore it while completing Part A.
After you have run the template file you can call ‘random_plan()’ in IDLE’s shell window to see the kinds of data it returns. Your build_city function must accept any such value and follow the instructions it contains to draw the corresponding cityscape. (By default function random_plan both returns and prints the city plan, but you can disable printing of the plan by supplying False as its optional argument.)
For instance, a typical list returned by function random_plan is as follows.
[[2, 'D', 6, 'X'],
[3, 'C', 5, 'O'],
[5, 'D', 8, 'O'],
[6, 'C', 2, 'X'],
[7, 'A', 1, 'O']]
This list tells us to draw: a building on Site 2, of Style D, 6 stories high; a building on Site 3 of Style C, 5 stories high; a building on Site 5, also of Style D, 8 stories high; etc.
In addition to the random_plan function, the template file also contains a number of
“fixed” data sets. These are provided to help you develop your code, so that you can work with a known city plan while debugging your code. However, the “fixed” data sets will not be used for assessing your solution. Your build_city function must work for any city plan randomly generated by function random_plan.
Building designs
To complete this assignment you must design four entirely distinct styles of building, corresponding to the styles ‘A’ to ‘D’ in the city plans generated by function random_plan. You have a free choice in the visual design of your buildings and you are strongly encouraged to be imaginative! Ideally the individual buildings should fit some unified theme for the city as a whole.
Each building must have two basic features:
o A series of stories or floors, which can be varied in number from 1 to 10, as dictated by the building specification. Each story must consist of several Turtle graphics shapes representing windows, doors, ledges, fire escapes, air conditioning units or anything else you deem necessary to produce a realistic image. All the floors can be the same for a particular building style, but the floors for each building style must be clearly distinct from all the others, involving different Turtle graphics shapes.
o A roof structure, which caps the building regardless of the number of stories. Each of the four styles of building must have a distinct roof structure, and each roof structure must comprise multiple Turtle graphics shapes. Each building style must have a roof structure which is clearly different from all the others, involving different Turtle graphics shapes. Features you could incorporate into the roof structures include domes, spires, aerials, satellite dishes, advertising signs, chimneys, exhaust pipes, helipads, revolving restaurants, etc.
You also have a free choice of the dimensions for the individual building styles. The best visual effect for the overall cityscape will be achieved if each style has different dimensions.
Also, we assume the city council has imposed some constraints on the maximum size of the buildings:
o Buildings cannot be wider than 250 pixels (which is the maximum space available at each building site).
o Each story of each building should not be more than about 50 pixels high (because a building of 10 stories, excluding the roof structure, would then be 500 pixels high, which is close to the maximum legal building height shown in the grid).
At the other extreme, of course, each building must be wide and high enough to make all of its individual features easily visible.
Illustrative example
To illustrate the requirements we developed a solution which uses famous buildings from science-fiction films and comics as its theme. (You should not copy our example! Develop your own idea! Be imaginative!) We developed code to draw the four following distinct styles of building.
Style A: Style B:
Style C: Style D:
Each of the building styles has been shown at a height of 5 stories above, but our solution allows each of them to be drawn at any height from 1 to 10 stories, inclusive. Each building has clearly distinct floors and roof structures and distinct vertical and horizontal dimensions. (The four images above are all reproduced at the same scale.) The four building styles we created are as follows:
A. The Gotham City Police headquarters from Batman. Each floor has multiple windows, except the ground floor which has doors. The roof contains signage and the Batsignal, ready to summon the Caped Crusader and the Boy Wonder to action.
B. The Daily Planet building from Superman. Here the floors are all the same but taper in width as we go up. Reporters are shown looking anxiously out the windows for Metropolis’ hero. (The people are placed in the windows randomly and have random skin tones.) The roof contains the famous Daily Planet logo consisting of a ringed planet.
C. The converted firehouse from Ghostbusters (which is a real building in New York). Again the ground floor has been made different from the others, to show the roller door for the Ectomobile. The roof contains the Ghostbusters’ logo (although in the movie this sign actually hangs above the door).
D. The clock tower from Back to the Future. Here we have used columns that span all the stories as the distinctive shape of each floor, except the ground floor which is a plinth containing stairs. The roof structure contains the clock, which is stopped at precisely 10:04pm, the time it was struck by lightning in 1955.
Note that our demonstration solution is more elaborate than necessary. Random elements (the people looking out of the Daily Planet’s windows) are not necessary, and all the floors can be the same in each style of building, including the ground floor (although this does not produce the most realistic looking image), provided they are reasonably complex.
From this basis, our implementation of the build_city function can draw any city plan generated by function random_plan. For instance, consider the following city plan:
[[1, 'A', 4, 'O'],
[3, 'C', 2, 'O'],
[4, 'C', 5, 'O'],
[5, 'B', 7, 'O'],
[6, 'B', 10, 'O'],
[8, 'A', 3, 'O'],
[10, 'D', 2, 'O']]
This requires us to erect buildings of style A (the Gotham City Police HQ) on sites 1 and 8, of heights 4 stories and 3 stories, respectively. We are also required to put a copy of building style D (the clock tower), only two floors high, on site 10. Buildings of style B (the Daily Planet) of different heights are specified for sites 5 and 6, and so on.
The resulting image is shown overleaf. Notice in each case that a building of the appropriate style and number of floors is drawn precisely centred on the specified building site.

As another example, consider the following data set:
[[3, 'C', 6, 'O'], [4, 'D', 8, 'O'], [5, 'C', 3, 'O'],
[6, 'B', 6, 'O'], [7, 'A', 9, 'O'], [8, 'B', 4, 'O'], [9, 'A', 1, 'O'], [10, 'C', 1, 'O']].
The cityscape drawn in this case is as follows, again following precisely the building specifications.

Once we are fully satisfied with our solution, we can change the argument to the create_drawing_canvas function to omit the grid, to produce a more attractive picture. The cityscape below was created for the following dataset, with the grid switched off.
[[1, 'D', 10, 'O'], [2, 'B', 5, 'O'], [3, 'B', 7, 'O'],
[4, 'A', 9, 'O'], [5, 'D', 5, 'O'], [6, 'C', 6, 'O'],
[7, 'B', 2, 'O'], [8, 'A', 4, 'O'], [9, 'C', 7, 'O'],
[10, 'D', 8, 'O']]

To complete this part of the assignment you are required to extend the provided cityscapes.py Python file by completing function build_city so that it can draw buildings at the sites and heights specified by the data sets generated by the random_plan function. Your build_city function must work correctly for any values returned by the random_plan function.
Your submitted solution will consist of a single Python 3 file, and must satisfy the following criteria. Percentage marks available are as shown.
1. Drawing four entirely distinct building styles (5%). Your program must be able to draw four distinct styles of building, each consisting of multiple floors and a roof structure, such that each building is clearly distinct in all elements from the other styles of building. Each floor and roof structure must be of a reasonable degree of complexity, involving multiple Turtle shapes. It must be easy to distinguish each floor from those above and/or below it, so that the number of floors in any particular building can be counted. Similarly, the roof structures must be clearly distinct from
the floors below. Also, the buildings must be made sufficiently distinct, either by drawing borders and/or varying their colours, so that they can be distinguished from one another even when they overlap on the canvas.
Beyond these requirements you are free to add other variations to your building designs, such as varying the width of the floors, making the ground floor different from the others, adding different features for different floors, etc.
2. Positioning buildings (5%). Your code must be capable of drawing each of the four styles of building at any of the marked building sites, as dictated by the data set provided to function build_city. The buildings must be centred precisely on the specified coordinates. The drawings of the buildings must preserve their integrity no matter where they are drawn, with no spurious additional or missing lines. Your solution for relocating the buildings must work correctly for any values returned by the random_plan function.
3. Resizing buildings (5%). Your code must be capable of drawing each of the four building styles at any height, as specified by the number of floors in the data set provided to function build_city. The correct number of floors must be drawn and always be topped by the appropriate roof structure. The individual parts of the building must preserve their integrity no matter how tall or short it is, with no spurious additional or missing lines. Your solution for resizing the buildings must work correctly for any values returned by the random_plan function.
4. Code quality and presentation (5%). Your program code, for both Parts A and B of the assignment, must be presented in a professional manner. See the coding guidelines in the IFB104 Code Presentation Guide (on Blackboard under Assessment) for suggestions on how to achieve this. In particular, given the obscure and repetitive nature of the code needed to draw complex images using Turtle graphics, each significant code segment must be clearly commented to say what it does, e.g., “Draw door”, “Draw ghost’s head”, etc. Similarly, the names of your functions and variables should be indicative of their purpose, not just “i”, “j”, etc. Also, you must use function definitions and loops to avoid unnecessary duplication of similar or identical code segments.
Finally, you are not required to copy the example shown in this document. Instead you are strongly encouraged to be creative in the design of your buildings. Surprise us!
Artistic merit – The Hall of Fame!
Development hints
• If you are unable to complete the whole task, just submit whatever you can get working. You will receive partial marks for incomplete solutions.
• To help you debug your code for the individual building styles we have provided some “fixed” datasets. Feel free to use these when developing your program, and add additional ones if you like, but keep in mind that these datasets will not be used for assessing your solution. Your build_city function must work for any value that can be returned by function random_plan.
• Part B of this assignment will require you to change your solution slightly in a short space of time. You are therefore encouraged to keep code maintainability in mind while developing your solution to Part A. Make sure your code is neat and wellcommented so that you will find it easy to modify when the instructions for Part B are released.
Deliverable
You must develop your solution by completing and submitting the provided Python 3 file cityscapes.py as follows.
1. Complete the “statement” at the beginning of the Python file to confirm that this is your own individual work by inserting your name and student number in the places indicated. We will assume that submissions without a completed statement are not your own work!
3. Submit a single Python file containing your solution for marking. Do not submit multiple files. Only a single file will be accepted, so you cannot accompany your solution with other files or pre-defined images. Do not submit any other files! Submit only a single Python 3 file!
Apart from working correctly your program code must be well-presented and easy to understand, thanks to (sparse) commenting that explains the purpose of significant code segments and helpful choices of variable and function names. Professional presentation of your code will be taken into account when marking this assignment.

If you are unable to solve the whole problem, submit whatever parts you can get working. You will receive partial marks for incomplete solutions.
How to submit your solution

Appendix: Some standard Turtle graphics colours you can use

More products