48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import sys
|
|
import random
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
def create_avatar(size):
|
|
# Erstelle ein neues Plot-Fenster
|
|
fig, ax = plt.subplots()
|
|
fig.set_size_inches(size/100, size/100) # Größe des Fensters festlegen
|
|
|
|
# Generiere zufällige Farben für Hintergrund und Formen
|
|
bg_color = (random.random(), random.random(), random.random())
|
|
shape_color = (random.random(), random.random(), random.random())
|
|
|
|
# Setze den Hintergrund
|
|
ax.set_facecolor(bg_color)
|
|
|
|
# Zeichne zufällige Formen
|
|
num_shapes = random.randint(3, 6)
|
|
for _ in range(num_shapes):
|
|
shape_type = random.choice(['circle', 'rectangle'])
|
|
if shape_type == 'circle':
|
|
x = random.randint(0, size)
|
|
y = random.randint(0, size)
|
|
radius = random.randint(0, size // 2)
|
|
circle = plt.Circle((x, y), radius, fc=shape_color)
|
|
ax.add_patch(circle)
|
|
elif shape_type == 'rectangle':
|
|
x = random.randint(0, size)
|
|
y = random.randint(0, size)
|
|
width = random.randint(0, size // 2)
|
|
height = random.randint(0, size // 2)
|
|
rectangle = plt.Rectangle((x, y), width, height, fc=shape_color)
|
|
ax.add_patch(rectangle)
|
|
|
|
# Verstecke Achsenbeschriftungen
|
|
ax.axis("off")
|
|
|
|
# Speichere das Bild
|
|
plt.savefig("random_avatar.png", dpi=100)
|
|
plt.close()
|
|
|
|
|
|
# Beispielaufruf
|
|
create_avatar(400)
|
|
|
|
print("hello")
|