acclivity

pyFlagsWithSwampy

Dec 8th, 2021
973
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from swampy.World import World
  2.  
  3. class Shape():
  4.     def __init__(self, w, bg, size):
  5.         # define a square canvas which our methods will then use
  6.         # Use the size and colors passed from main code
  7.         self.canvas = w.ca(width=size, height=size, background=bg)
  8.  
  9.     def draw_rectangle(self, points, colour):
  10.         self.canvas.rectangle(points, width=0, fill=colour)
  11.  
  12.     def draw_triangle(self, points, colour):
  13.         self.canvas.polygon(points, fill=colour)
  14.  
  15. world = World()
  16. czech = Shape(world, 'grey', 500)        # create a square grey canvas
  17.  
  18. # draw, a white rectangle for the upper half of the flag
  19. czech.draw_rectangle([[-250, 0], [250, 150]], 'white')
  20.  
  21. # draw a red rectangle for the lower half of the flag
  22. czech.draw_rectangle([[-250, -150], [250, 0]], 'red')
  23.  
  24. # draw a blue triangle at the left side of the flag. It will overlay parts of the 2 rectangles
  25. czech.draw_triangle([[-250, -150], [-50, 0], [-250, 150]], 'blue')
  26.  
  27. world.mainloop()
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
RAW Paste Data