Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Class Canvas represents a collection of Rectangles. It has 8 methods. In additio

ID: 3769078 • Letter: C

Question

Class Canvas represents a collection of Rectangles. It has 8 methods. In addition, to the constructor (i.e. __init__ method) and two methods that override python's object methods (and make your class user friendly as suggested by the test cases), your class should contain 5 more methods: add_one_rectangle, count_same_color, total_perimeter, min_enclosing_rectangle, and common_point. Here is a description of those methods whose job may not be obvious from the test cases. * The method total_perimeter: returns the sum of the perimeters of all the rectangles in the calling canvas. To compute total perimeter do not compute a perimeter of an individual rectangle in the body of total_perimeter method. Instead use get_perimeter method from the Rectangle class. * Method min_enclosing_rectangle: calculates the minimum enclosing rectangle that contains all the rectangles in the calling canvas. It returns an object of type Rectangle of any colour you prefer. To find minimum enclosing rectangle you will need to find the minimum x coordinate of all rectangles, the maximum x coordinate for all rectangles, the minimum y coordinate and the maximum y coordinate of all rectangles. * Method common_point: returns True if there exists a point that intersects all rectangles in the calling canvas. To test this (for axis parallel rectangles like ours), it is enough to test if every pair of rectangles intersects (according to a Helly’s theorem http://en.wikipedia.org/wiki/Helly's_theorem).

Explanation / Answer

i am not sure just treid..

from tkinter import *

canvas_width = 200
canvas_height = 100

colours = ("#476042", "green")
box=[]

for ratio in ( 0.2, 0.35 ):
box.append( (canvas_width * ratio,
canvas_height * ratio,
canvas_width * (1 - ratio),
canvas_height * (1 - ratio) ) )

master = Tk()

w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()

for k in range(2):
w.create_rectangle(box[i][0], box[k][1],box[k][2],box[k][3], fill=colours[k])

w.create_line(0, 0, # this is canvas origon
box[0][0], box[0][1], # coordinates of the box
fill=colours[0],
width=3)
w.create_line(0, canvas_height, # lower left corner
box[0][0], box[0][3], # lower left corner
fill=colours[0],
width=3)
w.create_line(box[0][2],box[0][1], # right upper corner
canvas_width, 0, # right upper corner
fill=colours[0],
width=3)
w.create_line(box[0][2], box[0][3], # lower right corner
canvas_width, canvas_height, # lower right corner
fill=colours[0], width=3)

w.create_text(canvas_width / 2,
canvas_height / 2,
text="Python")
mainloop()