import pygame
import random
import math
WIDTH = 500
HEIGHT = 500
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
running = True
x = 250
y = 250
delta = 25
def construct_figure():
screen.fill((0,0,0))
for i in range(0,5):
delta = random.randint(5,50)
pygame.draw.rect(screen, (255, 255, 255), (x+delta,y-delta,50,50))
pygame.draw.rect(screen, (255, 255, 255), (x-delta,y-delta,50,50))
pygame.draw.rect(screen, (255, 255, 255), (x-delta,y+delta,50,50))
pygame.draw.rect(screen, (255, 255, 255), (x+delta,y+delta,50,50))
pygame.draw.rect(screen, (255, 255, 255), (x,y,50,50))
pygame.display.flip()
construct_figure()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
construct_figure()
pygame.image.save(screen, "image.jpg")
pygame.quit()
|