class Point(object): """represents a point in 2-D space""" class Rectangle(object): """represent a rectangle. attributes: width, height, corner (lower left), color. """ class Circle(object): """represents a circle. attributes: center, radius, color. """ class Polygon(object): """attributes: a list of points and a color""" def draw_polygon(canvas, p): """Draws p on canvas.""" canvas.polygon ([[pt.x, pt.y] for pt in p.points], fill= p.color) def draw_rectangle(canvas, r): """Draws r on canvas.""" bbox = [[r.corner.x, r.corner.y], [r.corner.x + r.width, r.corner.y + r.height]] canvas.rectangle(bbox, outline='black', width=2, fill=r.color) def draw_circle(canvas, c): """draws c on canvas.""" canvas.circle([c.center.x,c.center.y], c.radius, outline=None, fill=c.color) from World import World def flagOfBangladesh(): w = World() canvas = w.ca(width=500, height=500, background='white') rect = Rectangle() rect.color = 'green4' ll = Point() ll.x = -150 ll.y = -100 rect.corner = ll rect.height = 200 rect.width = 300 draw_rectangle(canvas, rect) c = Circle() c.radius = 70 c.color = 'red' c.center = Point() c.center.x = -25 c.center.y = 0 draw_circle(canvas, c) w.mainloop() def flagOfCzechRepublic(): w = World() canvas = w.ca(width=500, height=500, background='white') rect = Rectangle() rect.color = 'red' ll = Point() ll.x = -150 ll.y = -100 rect.corner = ll rect.height = 200 rect.width = 300 draw_rectangle(canvas, rect) rect.color = 'white' ll.y = 0 rect.height = 100 draw_rectangle(canvas, rect) triangle = Polygon() p1 = Point() p1.x = -150 p1.y = -100 p2 = Point() p2.x = -150 p2.y = 100 p3 = Point() p3.x = -85 p3.y = 0 triangle.points = [p1, p2, p3] triangle.color = 'blue' draw_polygon(canvas,triangle) w.mainloop()