2948 explained code solutions for 75 technologies


python-pillowHow to draw a triangle


from PIL import Image, ImageDraw
  
im = Image.new("RGB", (400, 300))  
dr = ImageDraw.Draw(im)
dr.polygon([(50,50), (350,150), (200, 250)], outline="white")
im.show()ctrl + c
PIL

import Pillow package modules

Image.new

create new PIL image object

ImageDraw.Draw

create drawing object

.polygon(

draws polygon from given coordinates (with any number of dots)

(50,50), (350,150), (200, 250)

triangle dots coordinates

.show()

displays resulting image