from PIL import Image
IMAGESIZE = 200
IMAGECOLOR = (0x30, 0xD5, 0xC8)
LINECOLOR = (0x00, 0x31, 0x53)
LINEWIDTH = 3
def draw_point(image, x, y, r, color):
for i in range(-r, r):
for j in range(-r, r):
if x+i<0 or y+j<0 or x+i>=IMAGESIZE or y+j>=IMAGESIZE:
continue
if i**2+j**2<=r**2:
image.putpixel((x+i, y+j), color)
def draw_line(image, x1, y1, x2, y2, r, color):
dx = float(x2-x1)/500
dy = float(y2-y1)/500
for i in range(500):
draw_point(image, x1+int(i*dx), y1+int(i*dy),r,color)
im = Image.new('RGB', (IMAGESIZE, IMAGESIZE), IMAGECOLOR)
draw_line(im, 10, 10, 10, 150, LINEWIDTH, LINECOLOR)
draw_line(im, 50, 10, 150, 10, LINEWIDTH, LINECOLOR)
draw_line(im, 50, 10, 50, 50, LINEWIDTH, LINECOLOR)
draw_line(im, 50, 50, 150, 50, LINEWIDTH, LINECOLOR)
draw_line(im, 150, 50, 150, 150, LINEWIDTH, LINECOLOR)
draw_line(im, 150, 150, 50, 150, LINEWIDTH, LINECOLOR)
im.show()
Click Run or press shift + ENTER to run code