Advertisement
plarmi

hw_11_2

Oct 25th, 2023 (edited)
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. from PIL import Image, ImageDraw
  2.  
  3. WHITE = (255, 255, 255)
  4. BROWN = (139, 69, 19)
  5. GREEN = (0, 128, 0)
  6.  
  7. def draw_tree(width, height):
  8.     image = Image.new("RGB", (width, height), WHITE)
  9.  
  10.     draw = ImageDraw.Draw(image)
  11.  
  12.     draw.rectangle(((width * 0.45, height * 0.7), (width * 0.55, height * 0.9)), fill=BROWN)
  13.  
  14.     draw.polygon(((width * 0.4, height * 0.3),
  15.                     (width * 0.5, height * 0.1),
  16.                     (width * 0.6, height * 0.3)),
  17.                    GREEN)
  18.  
  19.     draw.polygon(((width * 0.35, height * 0.5),
  20.                     (width * 0.45, height * 0.3),
  21.                     (width * 0.55, height * 0.3),
  22.                     width * 0.65, height * 0.5),
  23.                    GREEN)
  24.     draw.polygon(((width * 0.3, height * 0.7),
  25.                     (width * 0.4, height * 0.5),
  26.                     (width * 0.6, height * 0.5),
  27.                     width * 0.7, height * 0.7),
  28.                    GREEN)
  29.  
  30.     image.save("2.png")
  31.  
  32.     image.show()
  33.  
  34. draw_tree(600, 600)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement