pygame画雪人_函数与图形示例.py

"""pygame画雪人_函数与图形示例.py
"""
 
# 导入pygame模块
import pygame
  
def draw_snowman(screen, x, y):
    """ --- 定义函数在x,y坐标画三个椭圆形.
    """
    pygame.draw.ellipse(screen, WHITE, [35 + x, 0 + y, 25, 25])
    pygame.draw.ellipse(screen, WHITE, [23 + x, 20 + y, 50, 50])
    pygame.draw.ellipse(screen, WHITE, [0 + x, 65 + y, 100, 100])
 
# 初始化pygame引擎
pygame.init()
 
# 定义全局颜色常量
BLACK = [0, 0, 0]
WHITE = [255, 255, 255]
 
# 设置屏幕大小与创建屏幕对象
size = [400, 500]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("画雪人_函数与图形示例.py")
 
# 用来结束while循环的逻辑变量.
done = False
clock = pygame.time.Clock() # 设置fps的clock对象
 
while not done:
 
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
 
    # 画背景为黑色
    screen.fill(BLACK)
 
    # 在(10,10)坐标画一个雪人
    draw_snowman(screen, 10, 10)   
    draw_snowman(screen, 300, 10)   
    draw_snowman(screen, 10, 300)
 
    # 更新显示
    pygame.display.flip()
 
    # 设置fps为60
    clock.tick(60)
 
 
# 友好的退出到IDLE
pygame.quit()