Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QUESTION Using the below code as a template (bottom of the page) develop a Python 3 program which processes data stored in a list to

QUESTION

Using the below code as a template (bottom of the page) develop a Python 3 program which processes data stored in a list to display a specific arrangement of sheets on a billboard. You must develop the code to draw this logo across four billboard sheets.

image text in transcribed

THE PEPSI LOGO MUST BE DRAWN ACROSS FOUR SHEETS LIKE THIS:

image text in transcribed

Each sheet must be a rectangle measuring 200 x 500 pixels. The centerpoint of each location has been marked to help you position your images as you develop your program. Your sheets must fit precisely into the four locations indicated.

OTHER INFORMATION:

1. The provided template file also contains several data sets, in the form of lists, which specify how you must arrange the sheets when drawing them. These instruction lists each contain two types of data:

2. The template file also contains a dummy function definition, paste_up. Your task is to complete this function definition so that when called with a data set as its argument it draws the sheets at the locations and in the orientations specified. The function must work for any of the given data sets or any other similar data sets in the same format.

3. Your program must be able to draw four distinct sheets, each containing part of a single overall picture. Each sheet must be a 200 500 pixel rectangle and must be of a reasonable degree of complexity, involving multiple shapes and colours. The entire rectangle must be filled in with colour. Each sheet must be clearly distinct so that the viewer can tell which one has been drawn. It must be easy for the viewer to distinguish each sheet from its neighbours when they are side-by-side, either through the use of a visible margin or by contrasting background colours. Each sheet must be clearly different from all the others, regardless of their orientation, and the image on each sheet must be asymmetric so that it is easy to tell whether it is being displayed upright or upside down.

4. When pasted up correctly, as per the final two data sets provided, the separate parts of the image must align perfectly to produce a single, clearly recognisable, non-trivial picture. The title of the drawing canvas must describe the picture drawn.

5. Your code must be capable of drawing each of the four sheets at any of the four marked locations. The sheets must fit precisely into each of the locations marked on the billboards backing, with the entire area being filled and no parts of the drawing protruding. The sheets must be sufficiently different that it is easy to distinguish which one is being drawn in each location. The images on the sheets must preserve their integrity no matter where they are drawn. Your solution for relocating the sheets must work for all of the provided data sets and any other data sets in the same format. You cannot hardwire your code for specific data sets and you may not change the data sets provided.

6. Your code must be capable of drawing each of the four sheets in either of the two possible orientations, upright or upside down. The images on each sheet must be suffiently asymmetric that it is easy to tell one orientation from the other. The images on the sheets must preserve their integrity no matter how they are oriented. Your solution for reorienting the sheets must work for all of the provided data sets and any other data sets in the same format. You cannot hardwire your code for specific data sets and you may not change the data sets provided.

7. Code must be presented professionally. In particular, given the obscure and repetitive nature of IFB104 Building IT Systems Semester 2, 2017 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 letter M, Draw red oval, etc.

8. You must complete the billboard logo using basic Turtle graphics and maths functions only. You may not import any additional modules or files into your program other than those already included in the given billboard.py template. In particular, you may not import any image files for use in creating your picture.

THE GIVEN TEMPLATE IS BELOW:

#-----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.

from turtle import * from math import *

# Define constant values used in the main program that sets up # the drawing canvas. Do not change any of these values.

sheet_width = 200 # pixels sheet_height = 500 # pixels backing_margin = 20 # pixels backing_width = sheet_width * 4 + backing_margin * 2 backing_height = sheet_height + backing_margin * 2 canvas_top_and_bottom_border = 150 # pixels canvas_left_and_right_border = 300 # pixels canvas_width = (backing_width + canvas_left_and_right_border) canvas_height = (backing_height + canvas_top_and_bottom_border)

# #--------------------------------------------------------------------#

#-----Functions for Creating the Drawing Canvas----------------------# # # The functions in this section are called by the main program to # set up 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(mark_center_points = True):

# Set up the drawing canvas setup(canvas_width, canvas_height)

# Draw as fast as possible tracer(False)

# Colour the sky blue bgcolor('sky blue')

# Draw the ground as a big green rectangle (sticking out of the # bottom edge of the drawing canvas slightly) overlap = 5 # pixels grass_height = 100 # pixels penup() goto(-(canvas_width // 2 + overlap), -(canvas_height // 2 + overlap)) # start at the bottom-left fillcolor('pale green') begin_fill() setheading(90) # face north forward(grass_height + overlap) right(90) # face east forward(canvas_width + overlap * 2) right(90) # face south forward(grass_height + overlap) end_fill()

# Draw a nice warm sun peeking into the image penup() goto(-canvas_width // 2, canvas_height // 2) color('yellow') dot(350)

# Draw a big fluffy white cloud in the sky goto(canvas_width // 3, canvas_height // 3) color('white') dot(200) setheading(200) forward(100) dot(180) setheading(0) forward(200) dot(160)

# Draw the billboard's wooden backing as four frames # and some highlighted coordinates # # Outer rectangle goto(- backing_width // 2, - backing_height // 2) # bottom left pencolor('sienna'); fillcolor('tan'); width(3) begin_fill() pendown() setheading(90) # face north forward(backing_height) right(90) # face east forward(backing_width) right(90) # face south forward(backing_height) right(90) # face west forward(backing_width) end_fill()

# Inner rectangle penup() goto(- backing_width // 2 + backing_margin, - backing_height // 2 + backing_margin) # bottom left fillcolor('gainsboro') begin_fill() pendown() setheading(90) # face north forward(backing_height - backing_margin * 2) right(90) # face east forward(backing_width - backing_margin * 2) right(90) # face south forward(backing_height - backing_margin * 2) right(90) # face west forward(backing_width - backing_margin * 2) end_fill()

# Draw lines separating the locations where the sheets go width(1); pencolor('dim grey') for horizontal in [-sheet_width, 0, sheet_width]: penup() goto(horizontal, sheet_height // 2) pendown() setheading(270) # point south forward(sheet_height) # Mark the center points of each sheet's location, if desired if mark_center_points: penup() points = [[[round(-sheet_width * 1.5), 0], 'Location 1'], [[round(-sheet_width * 0.5), 0], 'Location 2'], [[round(sheet_width * 0.5), 0], 'Location 3'], [[round(sheet_width * 1.5), 0], 'Location 4']] for center_point, label in points: goto(center_point) dot(4) write(' ' + label + ' (' + str(center_point[0]) + ', 0)', font = ('Arial', 12, 'normal')) # Reset everything ready for the student's solution color('black') width(1) penup() home() setheading(0) tracer(True)

# End the program by hiding the cursor and releasing the canvas def release_drawing_canvas(): tracer(True) hideturtle() done() # #--------------------------------------------------------------------#

#-----Test Data------------------------------------------------------# # # The list in this section contains the data sets you will use to # test your code. Each of the data sets is a list specifying the # way in which sheets are pasted onto the billboard: # # 1. The name of the sheet, from 'Sheet A' to 'Sheet D' # 2. The location to paste the sheet, from 'Location 1' to # 'Location 4' # 3. The sheet's orientation, either 'Upright' or 'Upside down' # # Each data set does not necessarily mention all four sheets. # # In addition there is an extra value, either 'X' or 'O' at the # start of each data set. The purpose of this value will be # revealed only in Part B of the assignment. You should ignore it # while completing Part A. # # You can create further data sets, but do not change any of the # given ones below because they will be used to test your submission. # # Note that your solution must work for all the data sets below # AND ANY OTHER DATA SETS IN THE SAME FORMAT! #

data_sets = [ # These two initial data sets don't put any sheets on the billboard # Data sets 0 - 1 ['O'], ['X'], # These data sets put Sheet A in all possible locations and orientations # Data sets 2 - 9 ['O', ['Sheet A', 'Location 1', 'Upright']], ['O', ['Sheet A', 'Location 2', 'Upright']], ['O', ['Sheet A', 'Location 3', 'Upright']], ['O', ['Sheet A', 'Location 4', 'Upright']], ['O', ['Sheet A', 'Location 1', 'Upside down']], ['O', ['Sheet A', 'Location 2', 'Upside down']], ['O', ['Sheet A', 'Location 3', 'Upside down']], ['O', ['Sheet A', 'Location 4', 'Upside down']], # These data sets put Sheet B in all possible locations and orientations # Data sets 10 - 17 ['O', ['Sheet B', 'Location 1', 'Upright']], ['O', ['Sheet B', 'Location 2', 'Upright']], ['O', ['Sheet B', 'Location 3', 'Upright']], ['O', ['Sheet B', 'Location 4', 'Upright']], ['O', ['Sheet B', 'Location 1', 'Upside down']], ['O', ['Sheet B', 'Location 2', 'Upside down']], ['O', ['Sheet B', 'Location 3', 'Upside down']], ['O', ['Sheet B', 'Location 4', 'Upside down']], # These data sets put Sheet C in all possible locations and orientations # Data sets 18 - 25 ['O', ['Sheet C', 'Location 1', 'Upright']], ['O', ['Sheet C', 'Location 2', 'Upright']], ['O', ['Sheet C', 'Location 3', 'Upright']], ['O', ['Sheet C', 'Location 4', 'Upright']], ['O', ['Sheet C', 'Location 1', 'Upside down']], ['O', ['Sheet C', 'Location 2', 'Upside down']], ['O', ['Sheet C', 'Location 3', 'Upside down']], ['O', ['Sheet C', 'Location 4', 'Upside down']], # These data sets put Sheet D in all possible locations and orientations # Data sets 26 - 33 ['O', ['Sheet D', 'Location 1', 'Upright']], ['O', ['Sheet D', 'Location 2', 'Upright']], ['O', ['Sheet D', 'Location 3', 'Upright']], ['O', ['Sheet D', 'Location 4', 'Upright']], ['O', ['Sheet D', 'Location 1', 'Upside down']], ['O', ['Sheet D', 'Location 2', 'Upside down']], ['O', ['Sheet D', 'Location 3', 'Upside down']], ['O', ['Sheet D', 'Location 4', 'Upside down']], # These data sets place two sheets in various locations and orientations # Data sets 34 - 38 ['O', ['Sheet D', 'Location 2', 'Upright'], ['Sheet C', 'Location 4', 'Upright']], ['O', ['Sheet A', 'Location 3', 'Upright'], ['Sheet B', 'Location 1', 'Upright']], ['O', ['Sheet D', 'Location 1', 'Upside down'], ['Sheet C', 'Location 4', 'Upright']], ['O', ['Sheet A', 'Location 3', 'Upright'], ['Sheet B', 'Location 2', 'Upside down']], ['X', ['Sheet C', 'Location 1', 'Upright'], ['Sheet B', 'Location 2', 'Upside down']], # These data sets place three sheets in various locations and orientations # Data sets 39 - 43 ['O', ['Sheet A', 'Location 4', 'Upright'], ['Sheet B', 'Location 3', 'Upright'], ['Sheet C', 'Location 2', 'Upright']], ['O', ['Sheet C', 'Location 1', 'Upright'], ['Sheet A', 'Location 3', 'Upright'], ['Sheet D', 'Location 4', 'Upright']], ['O', ['Sheet C', 'Location 1', 'Upside down'], ['Sheet D', 'Location 3', 'Upside down'], ['Sheet A', 'Location 4', 'Upright']], ['O', ['Sheet B', 'Location 4', 'Upright'], ['Sheet D', 'Location 2', 'Upside down'], ['Sheet C', 'Location 1', 'Upside down']], ['X', ['Sheet A', 'Location 4', 'Upright'], ['Sheet D', 'Location 3', 'Upside down'], ['Sheet C', 'Location 2', 'Upright']], # These data sets place four sheets in various locations and orientations # Data sets 44 - 48 ['O', ['Sheet C', 'Location 1', 'Upright'], ['Sheet B', 'Location 2', 'Upright'], ['Sheet A', 'Location 3', 'Upright'], ['Sheet D', 'Location 4', 'Upright']], ['O', ['Sheet C', 'Location 2', 'Upright'], ['Sheet B', 'Location 3', 'Upright'], ['Sheet D', 'Location 1', 'Upright'], ['Sheet A', 'Location 4', 'Upright']], ['O', ['Sheet C', 'Location 1', 'Upside down'], ['Sheet B', 'Location 2', 'Upright'], ['Sheet A', 'Location 3', 'Upright'], ['Sheet D', 'Location 4', 'Upside down']], ['O', ['Sheet C', 'Location 2', 'Upright'], ['Sheet B', 'Location 3', 'Upside down'], ['Sheet D', 'Location 1', 'Upside down'], ['Sheet A', 'Location 4', 'Upright']], ['X', ['Sheet C', 'Location 1', 'Upright'], ['Sheet B', 'Location 2', 'Upside down'], ['Sheet A', 'Location 3', 'Upright'], ['Sheet D', 'Location 4', 'Upside down']], # These data sets draw the entire image upside down # Data sets 49 - 50 ['X', ['Sheet A', 'Location 4', 'Upside down'], ['Sheet B', 'Location 3', 'Upside down'], ['Sheet C', 'Location 2', 'Upside down'], ['Sheet D', 'Location 1', 'Upside down']], ['O', ['Sheet A', 'Location 4', 'Upside down'], ['Sheet B', 'Location 3', 'Upside down'], ['Sheet C', 'Location 2', 'Upside down'], ['Sheet D', 'Location 1', 'Upside down']], # These are the final, 'correct' arrangements of sheets # Data sets 51 - 52 ['X', ['Sheet A', 'Location 1', 'Upright'], ['Sheet B', 'Location 2', 'Upright'], ['Sheet C', 'Location 3', 'Upright'], ['Sheet D', 'Location 4', 'Upright']], ['O', ['Sheet A', 'Location 1', 'Upright'], ['Sheet B', 'Location 2', 'Upright'], ['Sheet C', 'Location 3', 'Upright'], ['Sheet D', 'Location 4', 'Upright']] ]

# #--------------------------------------------------------------------#

#-----Student's Solution---------------------------------------------# # # Complete the assignment by replacing the dummy function below with # your own "paste_up" function. #

# Paste the sheets onto the billboard as per the provided data set def paste_up(dummy_parameter): pass

# #--------------------------------------------------------------------#

#-----Main Program---------------------------------------------------# # # This main program sets up the background, ready for you to start # drawing your billboard. Do not change any of this code except # where indicated by comments marked '*****'. #

# Set up the drawing canvas # ***** Change the default argument to False if you don't want to # ***** display the center points of each sheet on the backing create_drawing_canvas()

# Control the drawing speed # ***** Modify the following argument if you want to adjust # ***** the drawing speed speed('fastest')

# Decide whether or not to show the drawing being done step-by-step # ***** Set the following argument to False if you don't want to wait # ***** while the cursor moves around the screen tracer(True)

# Give the drawing canvas a title # ***** Replace this title with one that describes the image # ***** displayed on your billboard when the sheets are pasted # ***** correctly title("Describe your billboard's image here")

### Call the student's function to display the billboard ### ***** Change the number in the argument to this function ### ***** to test your code with a different data set paste_up(data_sets[0])

# Exit gracefully release_drawing_canvas()

# #--------------------------------------------------------------------#

I HAD TO CHANGE 9 'CENTRE' WORDS TO 'CENTER' WITHIN THE CODE AS IT WOULD NOT LET ME POST THE QUESTION WITH 'CENTRE' IN THE CODE

PERs

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

4 How can you create a better online image for yourself?

Answered: 1 week ago