# 画图形 import pygame from math import pi pygame.init() screen = pygame.display.set_mode((400, 600)) pygame.display.set_caption('显示图形') # 设置背景颜色 screen.fill((255, 255, 255)) # ================显示图形================ # 1.画直线 # line(画在哪儿,线的颜色,线的起点,线的终点,线宽=1) pygame.draw.line(screen, (255, 0, 0), (50, 20), (350, 20)) # 2.画折线 # lines(画在哪儿,线的颜色,是否闭合,多个点,线宽=1) points = [(10, 300), (100, 160), (180, 260), (250, 100)] pygame.draw.lines(screen, (255, 255, 0), False, points, 5 ) # 3.画圆 # circle(画在哪儿,线的颜色,圆心坐标,半径,线宽=0) (默认线宽0表示填充) pygame.draw.circle(screen, (0, 0, 255), (300, 100), 50, 2) # 4.画矩形 # rect(画在哪儿,线的颜色,矩形范围,线宽=0) 矩形范围(x坐标,y坐标,宽度,高度) pygame.draw.rect(screen,(120, 20, 60), (50, 300, 200, 100), 5) # 5.画椭圆 # ellipse(画在哪儿,线的颜色,矩形范围,线宽=0) 矩形的内切 pygame.draw.ellipse(screen, (150, 200, 0), (50, 300, 200, 100), 3) # 6.画弧线 # arc(画在哪儿,线的颜色,矩形范围,起始弧度,终止弧度,线宽=1) 注意此处是弧度,不是角度 pygame.draw.arc(screen, (0, 0, 0), (50, 300, 200, 100), 0, pi, 4 ) pygame.display.flip() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: exit()