吴裕雄--天生自然python学习笔记:python 用pygame模块基本绘图

绘制几何图形是游戏包的基本功能,很多游戏角色都是由基本图形组合而成的 。
绘制矩形: pygame.draw.rect
Pygam巳绘制矩形的语法为:

 

 

 

 

 

用基本绘图绘制一个人脸
用基本绘图功能绘制人脸

import pygame

pygame.init()
screen = pygame.display.set_mode((300, 300))
pygame.display.set_caption("基本绘图")

background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((255,255,255))

pygame.draw.circle(background, (0,0,0), (150,150), 130, 4)
pygame.draw.circle(background, (0,0,255), (100,120), 25, 0)
pygame.draw.circle(background, (0,0,255), (200,120), 25, 0)
pygame.draw.ellipse(background, (255,0,255),[135, 130, 30, 80], 0)
pygame.draw.arc(background, (255,0,0), [80, 130, 150, 120], 3.4, 6.1, 9)

screen.blit(background, (0,0))
pygame.display.update()

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
pygame.quit()

原文地址:https://www.cnblogs.com/tszr/p/12036391.html