Answer To: Assignment1b-BrokenTiles IFB104 Building IT Systems Semester 2, 2019 Assignment 1, Part B: Broken...
Yogesh answered on Sep 06 2021
# -----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 function, "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.
#
#...