-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_Squares.py
37 lines (29 loc) · 1019 Bytes
/
make_Squares.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 12 15:59:40 2023
@author: Stephen
"""
from PIL import Image, ImageDraw
def generate_image(image_size, square_size, output_file):
# Create a new image with a white background
image = Image.new('RGB', image_size, 'white')
draw = ImageDraw.Draw(image)
# Define square colors
colors = ['red', 'green', 'blue', 'yellow']
# Define square positions
positions = [
(0, 0),
(image_size[0] - square_size, 0),
(0, image_size[1] - square_size),
(image_size[0] - square_size, image_size[1] - square_size)
]
# Draw the squares
for color, position in zip(colors, positions):
draw.rectangle([position, (position[0] + square_size, position[1] + square_size)], fill=color)
# Save the image to a file
image.save(output_file)
if __name__ == "__main__":
image_size = (400, 400)
square_size = 50
output_file = "squares_image.png"
generate_image(image_size, square_size, output_file)