Python 所谓的艺术操作

Posted on 2020-10-11 10:49  黑炽  阅读(204)  评论(0编辑  收藏  举报
 1 import pygame, sys, random
 2 
 3 pygame.init()
 4 screen = pygame.display.set_mode([640, 480])#显示对象
 5 #[640, 480]是窗口大小,单位像素
 6 screen.fill([255, 255, 255])#用白色填充窗口背景
 7 
 8 for i in range(100):
 9     width = random.randint(0, 250)
10     height = random.randint(0, 100)
11     top = random.randint(0, 400)
12     left = random.randint(0, 500)
13     pygame.draw.rect(screen, [0, 0, 0], [left, top, width, height], 1)
14 
15 pygame.display.flip()
16 running = True
17 while running:
18     for event in pygame.event.get():
19         if event.type == pygame.QUIT:
20             running = False
21 pygame.quit()