Assignment1b-BrokenTiles IFB104 Building IT Systems Semester 2, 2019 Assignment 1, Part B: Broken Tiles (4%, due 11:59pm Sunday, September 8th, end of Week 7) Overview This is the second part of a...

1 answer below »
Bachelor level python assignment


Assignment1b-BrokenTiles IFB104 Building IT Systems Semester 2, 2019 Assignment 1, Part B: Broken Tiles (4%, due 11:59pm Sunday, September 8th, end of Week 7) Overview This is the second part of a two-part assignment. This part is worth 4% of your final grade for IFB104. Part A which preceded it was worth 21%. This part is intended as a last-minute extension to the assignment, thereby testing the maintainability of your code from Part A and your ability to work under time presssure. If you have a neat, clear solution to Part A you will find completing Part B easy. For the whole assignment you will submit only one file, containing your combined solution to both Parts A and B, and you will receive one grade for the whole 25% assignment. Motivation One of the most common tasks in “Building IT Systems” is modifying some existing code. In practice, computer programs are written only once but are subsequently modified and ex- tended many times during their operational lifetime. Code changes may be required in re- sponse to internal factors, such as the need to correct design flaws or coding errors, or exter- nal factors, such as changes in consumer requirements. A common situation is where some new feature must be added to an existing program. This is the scenario simulated in this part of the assignment. This task requires you to extend your solution to Part A of the assignment by adding an additional feature. It tests: • Your ability to work under time pressure; and • The quality and clarity of your code for Part A, because a well-written solution to Part A will make completing this part of the assignment easy. Goal In Part A of this assignment you were required to develop a program which could follow in- structions, encoded as a randomly-generated Python list, to draw a pattern of differently- shaped tiles that precisely filled a rectangular area. However, one of the frustrations of “tes- sellation” using real ceramic tiles is that they can become cracked or broken, spoiling the pat- tern. In this part of the assignment you will simulate this annoying, but realistic, situation. Specifically: • For each of your four different types of tiles you must develop a “broken” version; and • You must draw a broken tile for any instruction in the pattern that ends with an ‘X’. To complete this additional task you must extend your solution to Part A. No additional Py- thon template file is supplied for this part. As per Part A, your Part B solution must work for any randomly-generated pattern that can be returned by the provided function ran- dom_pattern. IFB104 Building IT Systems Semester 2, 2019 Illustrative example To illustrate the requirement we’ll continue our example from the Part A instructions. Recall that we developed a solution which drew four kinds of tiles celebrating the first Moon land- ing. To meet the extended requirements of Part B we therefore developed additional code to draw “broken” versions of the four tiles, each with multiple cracks and a large triangular sec- tion missing, exposing the grey surface underneath. (To save ourselves effort we used the same Python code to deface all four tiles, but you can use a different pattern of cracks for each tile type.) One of these “broken” tiles must be drawn in place of the corresponding intact tile for any instruction that ends with an ‘X’. For instance, consider the following data set, generated by calling function random_pattern. [['C4', 'C5', 'O'], ['J5', 'X'], ['G7', 'H7', 'O'], ['I1', 'J1', 'O'], ['G3', 'X'], ['D2', 'O'], ['G6', 'O'], ['I2', 'I3', 'O'], ['I5', 'O'], ['J2', 'O'], ['F1', 'F2', 'O'], ['B3', 'B4', 'O'], ['J3', 'J4', 'X'], IFB104 Building IT Systems Semester 2, 2019 ['E5', 'F5', 'E6', 'F6', 'O'], ['H6', 'O'], ['C1', 'X'], ['E7', 'F7', 'X'], ['D7', 'O'], ['C3', 'O'], ['B7', 'O'], ['C6', 'D6', 'O'], ['J6', 'O'], ['A4', 'X'], ['H3', 'O'], ['I4', 'O'], ['A6', 'O'], ['B6', 'X'], ['A1', 'X'], ['A5', 'O'], ['A2', 'X'], ['J7', 'X'], ['A3', 'O'], ['E1', 'O'], ['G4', 'H4', 'G5', 'H5', 'O'], ['B5', 'O'], ['E2', 'O'], ['D3', 'E3', 'D4', 'E4', 'X'], ['C2', 'O'], ['C7', 'O'], ['B1', 'B2', 'O'], ['D1', 'O'], ['F3', 'F4', 'O'], ['A7', 'O'], ['G1', 'H1', 'G2', 'H2', 'O'], ['I6', 'I7', 'O'], ['D5', 'O']] In this case we have been very unlucky and 11 of our tiles are broken in the pattern generat- ed, including one of each shape. For instance, the second tile in the pattern, which is a small one at location J5, is broken. The tall tile at locations J3 and J4 is also broken, as is the wide tile at locations E7 and F7. Also broken is the big tile spanning locations D3, E3, D4 and E4, and so on. The resulting pattern drawn on the grid is as shown overleaf in this case. IFB104 Building IT Systems Semester 2, 2019 Your task is to add code to your solution to “break” your tiles from Part A in a similar way, whenever they are marked with an ‘X’. (This may seem heartbreaking given the effort you have already expended drawing the tiles in Part A. Mercifully, the likelihood of breaking a tile is set to only 8% in the provided code template, so your overall pattern won’t be too bad- ly damaged in general.) Requirements and marking guide To complete this task you are required to extend your Part A tessellation.py file by adding code so that as well as drawing the pattern of tiles and the legend, you show any tiles with an ‘X’ in their broken form. Your submitted solution for both Parts A and B will consist of a single Python file. Your Part B extension must satisfy the following criteria. Marks available are as shown. 1. Drawing broken tiles (2%). All four types of tiles can be drawn in “broken” form, with a realistic image of damage on top of the original image. The damage to each tile must be drawn using basic Turtle graphics shapes and must be of a reasonable de- gree of complexity, involving several lines and not, for instance, just one or two straight lines. The “damage” must be obvious and must cover the majority of the tile’s surface. IFB104 Building IT Systems Semester 2, 2019 2. Tiles marked with an ‘X’ are broken (2%). Your program must draw a broken ver- sion of a tile for every instruction that ends with an ‘X’. All other tiles (those ending with an ‘O’) must be drawn in their unbroken form. You must complete the assignment using basic Turtle graphics and maths functions only. You may not import any additional modules or files into your program other than those al- ready included in the given tessellation.py template. In particular, you may not use any image files in your solution. Development hints • It should be possible to complete this task merely by adding code to your existing so- lution, with little or no change to the code you have already completed. In particular, the “damage” to your tiles can be drawn on top of the original image. • If you are unable to complete the whole task, just submit whatever part you can get working. You will receive partial marks for incomplete solutions. Try to ensure that your program runs when submitted, even if it is incomplete. Portability An important aspect of software development is to ensure that your solution will work cor- rectly on all computing platforms (or at least as many as possible). For this reason you must complete the assignment using standard Turtle graphics, random number and maths functions only. You may not import any additional modules or files into your program other than those already imported by the given template file. In particular, you may not import any image files to help create your drawings or use non-standard image processing modules such as Pillow/PIL. Security warning and plagiarism notice This is an individual assessment item. All files submitted will be subjected to software pla- giarism analysis using the MoSS system (http://theory.stanford.edu/~aiken/moss/). Serious violations of the university’s policies regarding plagiarism will be forwarded to the Science and Engineering Faculty’s Academic Misconduct Committee for formal prosecution. As per QUT rules, you are not permitted to copy or share solutions to individual assessment items. In serious plagiarism cases SEF’s Academic Misconduct Committee prosecutes both the copier and the original author equally. It is your responsibility to keep your solution se- cure. In particular, you must not make your solution visible online via cloud-based code development platforms such as GitHub. Note that free accounts for such platforms are usually public. If you wish to use such a resource, do so only if you are certain you have a private repository that cannot be seen by anyone else. For instance, university students can apply for a free private repository in GitHub to keep their assignments secure (https://education.github.com/pack). However, we recommend
Answered Same DaySep 02, 2021IFB104

Answer To: Assignment1b-BrokenTiles IFB104 Building IT Systems Semester 2, 2019 Assignment 1, Part B: Broken...

Yogesh answered on Sep 06 2021
144 Votes
# -----Statement of Authorship----------------------------------------#
#
# This is an individual assessment item. By submitting this
# code I agree that it represents my own work. I am aware of
# the University rule that a student must not act in a manner
# which constitutes academic dishonesty as stated and explained
# in QUT's Manual of Policies and Procedures, Section C/5.3
# "Academic Integrity" and Section E/2.1 "Student Code of Conduct".
#
# Student no: PUT YOUR STUDENT NUMBER HERE
# Student name: PUT YOUR NAME HERE
#
# NB: Files submitted without a completed copy of this statement
# will not be marked. All files submitted will be subjected to
# software plagiarism analysis using the MoSS system
# (http://theory.stanford.edu/~aiken/moss/).
#
# --------------------------------------------------------------------#
# -----Task Description-----------------------------------------------#
#
# TESSELLATION
#
# This assignment tests your skills at processing data stored in
# lists, creating reusable code and following instructions to display
# a complex visual image. The incomplete Python program below is
# missing a crucial f
unction, "tessellate". You are required to
# complete this function so that when the program is run it fills
# a rectangular space with differently-shaped tiles, using data
# stored in a list to determine which tiles to place and where.
# See the instruction sheet accompanying this file for full details.
#
# Note that this assignment is in two parts, the second of which
# will be released only just before the final deadline. This
# template file will be used for both parts and you will submit
# your final solution as a single Python 3 file, whether or not you
# complete both parts of the assignment.
#
# --------------------------------------------------------------------#
# -----Preamble-------------------------------------------------------#
#
# This section imports necessary functions and defines constant
# values used for creating the drawing canvas. You should not change
# any of the code in this section.
#
# Import the functions needed to complete this assignment. You
# should not need to use any other modules for your solution. In
# particular, your solution must not rely on any non-standard Python
# modules that need to be downloaded and installed separately,
# because the markers will not have access to such modules.
from turtle import *
from math import *
from random import *
# Define constant values used in the main program that sets up
# the drawing canvas. Do not change any of these values.
cell_size = 100 # pixels (default is 100)
grid_width = 10 # squares (default is 10)
grid_height = 7 # squares (default is 7)
x_margin = cell_size * 2.75 # pixels, the size of the margin left/right of the grid
y_margin = cell_size // 2 # pixels, the size of the margin below/above the grid
window_height = grid_height * cell_size + y_margin * 2
window_width = grid_width * cell_size + x_margin * 2
small_font = ('Arial', 18, 'normal') # font for the coords
big_font = ('Arial', 24, 'normal') # font for any other text
# Validity checks on grid size - do not change this code
assert cell_size >= 80, 'Cells must be at least 80x80 pixels in size'
assert grid_width >= 8, 'Grid must be at least 8 squares wide'
assert grid_height >= 6, 'Grid must be at least 6 squares high'
#
# --------------------------------------------------------------------#
# -----Functions for Creating the Drawing Canvas----------------------#
#
# The functions in this section are called by the main program to
# manage the drawing canvas for your image. You should not change
# any of the code in this section.
#
# Set up the canvas and draw the background for the overall image
def create_drawing_canvas(bg_colour='light grey',
line_colour='slate grey',
draw_grid=True, mark_legend=True):
# Set up the drawing canvas with enough space for the grid and
# legend
setup(window_width, window_height)
bgcolor(bg_colour)
# Draw as quickly as possible
tracer(False)
# Get ready to draw the grid
penup()
color(line_colour)
width(2)
# Determine the left-bottom coords of the grid
left_edge = -(grid_width * cell_size) // 2
bottom_edge = -(grid_height * cell_size) // 2
# Optionally draw the grid
if draw_grid:
# Draw the horizontal grid lines
setheading(0) # face east
for line_no in range(0, grid_height + 1):
penup()
goto(left_edge, bottom_edge + line_no * cell_size)
pendown()
forward(grid_width * cell_size)
# Draw the vertical grid lines
setheading(90) # face north
for line_no in range(0, grid_width + 1):
penup()
goto(left_edge + line_no * cell_size, bottom_edge)
pendown()
forward(grid_height * cell_size)
# Draw each of the labels on the x axis
penup()
y_offset = 27 # pixels
for x_label in range(0, grid_width):
goto(left_edge + (x_label * cell_size) + (cell_size // 2), bottom_edge - y_offset)
write(chr(x_label + ord('A')), align='center', font=small_font)
# Draw each of the labels on the y axis
penup()
x_offset, y_offset = 7, 10 # pixels
for y_label in range(0, grid_height):
goto(left_edge - x_offset, bottom_edge + (y_label * cell_size) + (cell_size // 2) - y_offset)
write(str(y_label + 1), align='right', font=small_font)
# Mark centre coordinate (0, 0)
home()
dot(15)
# Optionally mark the spaces for drawing the legend
if mark_legend:
# Left side
goto(-(grid_width * cell_size) // 2 - 75, -25)
### Legend Tiles ###
pos = (-741, 100)
BIG(pos) # BIT Tile
goto(-752, 66)
pencolor("red")
write("GLOBAL WARMING", font=("Times New Roman", 17, 'bold'))
goto(-730, 46)
pencolor("black")
write("A Threat to Human Race", font=("Times New Roman", 12, 'bold', 'italic'))
pos = (-690, -100)
SMALL(pos) #SMALL Tile
goto(-716, -135)
pencolor("green")
write("PLANT TREES", font=("Times New Roman", 17, 'bold'))
# write('Put your\nlegend here LEFT', align='right', font=big_font)
# Right side
goto((grid_width * cell_size) // 2 + 75, -25)
pos = (535, 150)
WIDE(pos) # WIDE Tile
goto(532, 90)
pencolor("orange")
write(" GREENHOUSE\nGASES EMISSION", font=("Times New Roman", 17, 'bold'))
pos = (581, -150)
TALL(pos) # TALL Tile
goto(536, -190)
pencolor("blue")
write("YOU can REDUCE", font=("Times New Roman", 17, 'bold'))
goto(523, -217)
write("GLOBAL WARMING", font=("Times New Roman", 17, 'bold'))
# write('Put your\nlegend here RIGHT', align='left', font=big_font)
# Reset everything ready for the student's solution
pencolor('black')
width(1)
penup()
home()
tracer(True)
# End the program and release the drawing canvas to the operating
# system. By default the cursor (turtle) is hidden when the
# program ends - call the function with False as the argument to
# prevent this.
def release_drawing_canvas(hide_cursor=True):
tracer(True) # ensure any drawing still in progress is displayed
if hide_cursor:
hideturtle()
done()
#
# --------------------------------------------------------------------#
# -----Test Data for Use During Code Development----------------------#
#
# The "fixed" data sets in this section are provided to help you
# develop and test your code. You can use them as the argument to
# the "tesselate" function while perfecting your solution. However,
# they will NOT be used to assess your program. Your solution will
# be assessed using the "random_pattern" function appearing below.
# Your program must work correctly for any data set that can be
# generated by the random_pattern function.
#
# Each of the data sets is a list of instructions, each specifying
# where to place a particular tile. The general form of each
# instruction is
#
# [squares, mystery_value]
#
# where there may be one, two or four squares in the grid listed
# at the beginning. This tells us which grid squares must be
# filled by this particular tile. This information also tells
# us which shape of tile to produce. A "big" tile will occupy
# four grid squares, a "small" tile will occupy one square, a
# "wide" tile will occupy two squares in the same row, and a
# "tall" tile will occupy two squares in the same column. The
# purpose of the "mystery value" will be revealed in Part B of
# the assignment.
#
# Note that the fixed patterns below assume the grid has its
# default size of 10x7 squares.
#
# Some starting points - the following fixed patterns place
# just a single tile in the grid, in one of the corners.
# Small tile
fixed_pattern_0 = [['A1', 'O']]
fixed_pattern_1 = [['J7', 'X']]
# Wide tile
fixed_pattern_2 = [['A7', 'B7', 'O']]
fixed_pattern_3 = [['I1', 'J1', 'X']]
# Tall tile
fixed_pattern_4 = [['A1', 'A2', 'O']]
fixed_pattern_5 = [['J6', 'J7', 'X']]
# Big tile
fixed_pattern_6 = [['A6', 'B6', 'A7', 'B7', 'O']]
fixed_pattern_7 = [['I1', 'J1', 'I2', 'J2', 'X']]
# Each of these patterns puts multiple copies of the same
# type of tile in the grid.
# Small tiles
fixed_pattern_8 = [['E1', 'O'],
['J4', 'O'],
['C5', 'O'],
['B1', 'O'],
['I1', 'O']]
fixed_pattern_9 = [['C6', 'X'],
['I4', 'X'],
['D6', 'X'],
['J5', 'X'],
['F6', 'X'],
['F7', 'X']]
# Wide tiles
fixed_pattern_10 = [['A4', 'B4', 'O'],
['C1', 'D1', 'O'],
['C7', 'D7', 'O'],
['A7', 'B7', 'O'],
['D4', 'E4', 'O']]
fixed_pattern_11 = [['D7', 'E7', 'X'],
['G7', 'H7', 'X'],
['H5', 'I5', 'X'],
['B3', 'C3', 'X']]
# Tall tiles
fixed_pattern_12 = [['J2', 'J3', 'O'],
['E5', 'E6', 'O'],
['I1', 'I2', 'O'],
['E1', 'E2', 'O'],
['D3', 'D4', 'O']]
fixed_pattern_13 = [['H4', 'H5', 'X'],
['F1', 'F2', 'X'],
['E2', 'E3', 'X'],
['C4', 'C5', 'X']]
# Big tiles
fixed_pattern_14 = [['E5', 'F5', 'E6', 'F6', 'O'],
['I5', 'J5', 'I6', 'J6', 'O'],
['C2', 'D2', 'C3', 'D3', 'O'],
['H2', 'I2', 'H3', 'I3', 'O'],
['A3', 'B3', 'A4', 'B4', 'O']]
fixed_pattern_15 = [['G2', 'H2', 'G3', 'H3', 'X'],
['E5', 'F5', 'E6', 'F6', 'X'],
['E3', 'F3', 'E4', 'F4', 'X'],
['B3', 'C3', 'B4', 'C4', 'X']]
# Each of these patterns puts one instance of each type
# of tile in the grid.
fixed_pattern_16 = [['I5', 'O'],
['E1', 'F1', 'E2', 'F2', 'O'],
['J5', 'J6', 'O'],
['G7', 'H7', 'O']]
fixed_pattern_17 = [['G7', 'H7', 'X'],
['B7', 'X'],
['A5', 'B5', 'A6', 'B6', 'X'],
['D2', 'D3', 'X']]
# If you want to create your own test data sets put them here,
# otherwise call function random_pattern to obtain data sets
# that fill the entire grid with tiles.
#
#...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here