Advertisement
Guest User

My

a guest
Apr 24th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. from PIL import ImageDraw
  2.  
  3.  
  4. class ImageDrawer(ImageDraw.ImageDraw):
  5.     def horizontal_trapezium(self, xy, width, height, fill=None, outline=None):
  6.         x, y = xy
  7.  
  8.         up = (width[0] - width[-1]) // 2
  9.         if width[0] > width[-1]:
  10.             self.polygon([(x, y), (x + width[0], y), (x + width[-1] + up, height + y), (x + up, height + y)],
  11.                          fill=fill, outline=outline)
  12.         else:
  13.             self.polygon([(x + -up, y), (x + width[0] + -up, y), (x + width[-1], y + height), (x, y + height)],
  14.                          fill=fill, outline=outline)
  15.  
  16.     def vertical_trapezium(self, xy, width, height, fill=None, outline=None):
  17.         x, y = xy
  18.         up = (max(height) - min(height)) // 2
  19.         if height[0] > height[-1]:
  20.             self.polygon([(x, y), (x, y + height[0]), (x + width, y + up + height[-1]), (x + width, y + up)],
  21.                          fill=fill, outline=outline)
  22.         else:
  23.             self.polygon([(x, y + up), (x, y + height[0] + up), (x + width, y + height[-1]), (x + width, y)],
  24.                          fill=fill, outline=outline)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement