你必须创建一个元组列表:
POLYGONS = [
((255, 0, 0), [(100, 50), (50, 150), [150, 150]], True),
((0, 0, 255), [(100, 150), (50, 50), [150, 50]], True)
]
你必须用asterisk (*) operator解压缩元组:
for poly in POLYGONS:
pygame.draw.polygon(window, *poly)
小例子:
import pygame
pygame.init()
window = pygame.display.set_mode((200, 200))
clock = pygame.time.Clock()
POLYGONS = [
((255, 0, 0), [(100, 50), (50, 150), [150, 150]], True),
((0, 0, 255), [(100, 150), (50, 50), [150, 50]], True)
]
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
window_center = window.get_rect().center
window.fill(0)
for poly in POLYGONS:
pygame.draw.polygon(window, *poly)
pygame.display.flip()
clock.tick(60)
pygame.quit()
exit()