-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1757775600.py
More file actions
34 lines (29 loc) · 1.26 KB
/
Copy path1757775600.py
File metadata and controls
34 lines (29 loc) · 1.26 KB
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
import random
from PIL import Image, ImageDraw
def generate_ellipse_image():
"""Generates an image with random ellipses and saves it to a file."""
image_size = (480, 480)
background_color = (255, 255, 255)
img = Image.new("RGB", image_size, background_color)
draw = ImageDraw.Draw(img)
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 255, 255), (255, 0, 255), (255, 255, 0)]
center_coords_options = [i for i in range(0, 481, 32)]
size_options = [i for i in range(256, 481, 16)]
num_ellipses = random.randint(1, 6)
selected_colors = random.sample(colors, num_ellipses)
for _ in range(num_ellipses):
fill_color = selected_colors.pop()
center_x = random.choice(center_coords_options)
center_y = random.choice(center_coords_options)
width = random.choice(size_options)
height = random.choice(size_options)
x1 = center_x - width // 2
y1 = center_y - height // 2
x2 = center_x + width // 2
y2 = center_y + height // 2
draw.ellipse([x1, y1, x2, y2], outline=fill_color, width=16)
output_filename = "generated_ellipses.png"
img.save(output_filename)
print(f"Generated image '{output_filename}'.")
if __name__ == "__main__":
generate_ellipse_image()