Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from swampy.World import World
- class Shape():
- def __init__(self, w, bg, size):
- # define a square canvas which our methods will then use
- # Use the size and colors passed from main code
- self.canvas = w.ca(width=size, height=size, background=bg)
- def draw_rectangle(self, points, colour):
- self.canvas.rectangle(points, width=0, fill=colour)
- def draw_triangle(self, points, colour):
- self.canvas.polygon(points, fill=colour)
- world = World()
- czech = Shape(world, 'grey', 500) # create a square grey canvas
- # draw, a white rectangle for the upper half of the flag
- czech.draw_rectangle([[-250, 0], [250, 150]], 'white')
- # draw a red rectangle for the lower half of the flag
- czech.draw_rectangle([[-250, -150], [250, 0]], 'red')
- # draw a blue triangle at the left side of the flag. It will overlay parts of the 2 rectangles
- czech.draw_triangle([[-250, -150], [-50, 0], [-250, 150]], 'blue')
- world.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement