import pygame
import math
if __name__ == '__main__':
pygame.init()
screen = pygame.display.set_mode((800, 450))
screen.fill((255, 255, 255))
# 头
pygame.draw.circle(screen, (0, 150, 255), (400, 180), 135)
# 脸
pygame.draw.circle(screen, (255, 255, 255), (400, 200), 115)
# 嘴巴
pygame.draw.arc(screen, (0, 0, 0), (320, 160, 160, 100), math.pi, math.pi*2)
# 鼻线
pygame.draw.line(screen, (0, 0, 0), (400, 150), (400, 260))
# 左眼
pygame.draw.ellipse(screen, (255, 255, 255), (340, 60, 60, 70))
pygame.draw.ellipse(screen, (0, 0, 0), (340, 60, 60, 70), 1)
pygame.draw.ellipse(screen, (0, 0, 0), (380, 80, 15, 25))
pygame.draw.ellipse(screen, (255, 255, 255), (385, 87, 5, 5))
# 右眼
pygame.draw.ellipse(screen, (255, 255, 255), (400, 60, 60, 70))
pygame.draw.ellipse(screen, (0, 0, 0), (400, 60, 60, 70), 1)
pygame.draw.ellipse(screen, (0, 0, 0), (440, 80, 15, 25))
pygame.draw.ellipse(screen, (255, 255, 255), (445, 87, 5, 5))
# 鼻子
pygame.draw.circle(screen, (255, 0, 0), (400, 135), 15)
# 身体
pygame.draw.rect(screen, (0, 150, 255), (300, 270, 200, 140))
pygame.draw.rect(screen, (0, 0, 0), (300, 270, 200, 140), 1)
# 围巾
pygame.draw.rect(screen, (255, 0, 0), (300, 270, 200, 15))
# 口袋
pygame.draw.ellipse(screen, (255, 255, 255), (320, 300, 160, 90))
pygame.draw.line(screen, (0, 0, 0), (360, 330), (440, 330))
pygame.draw.arc(screen, (0, 0, 0), (360, 290, 80, 80), math.pi, math.pi*2)
# 左手
# pygame.draw.line(screen, (0, 150, 255), True, [(305, 300), (365, 400), (385, 380), (345, 300)], 0)
pygame.draw.line(screen, (0, 150, 255), (335, 300), (370, 400), 40)
pygame.draw.line(screen, (0, 0, 0), (315, 300), (350, 400), 1)
pygame.draw.line(screen, (0, 0, 0), (355, 300), (390, 400), 1)
pygame.draw.ellipse(screen, (255, 255, 255), (345, 380, 60, 40))
pygame.draw.ellipse(screen, (0, 0, 0), (345, 380, 60, 40), 1)
# 右手
pygame.draw.line(screen, (0, 150, 255), (465, 300), (425, 400), 40)
pygame.draw.line(screen, (0, 0, 0), (445, 300), (405, 400), 1)
pygame.draw.line(screen, (0, 0, 0), (485, 300), (445, 400), 1)
pygame.draw.ellipse(screen, (255, 255, 255), (390, 380, 60, 40))
pygame.draw.ellipse(screen, (0, 0, 0), (390, 380, 60, 40), 1)
# 铃铛
pygame.draw.circle(screen, (230, 255, 0), (400, 290), 15)
pygame.draw.line(screen, (0, 0, 0), (385, 288), (408, 288))
pygame.draw.line(screen, (0, 0, 0), (385, 292), (410, 292))
pygame.draw.line(screen, (0, 0, 0), (400, 292), (400, 305))
# 左jio
pygame.draw.ellipse(screen, (255, 255, 255), (250, 320, 80, 100))
pygame.draw.ellipse(screen, (0, 0, 0), (250, 320, 80, 100), 1)
# 右jio
pygame.draw.ellipse(screen, (255, 255, 255), (470, 320, 80, 100))
pygame.draw.ellipse(screen, (0, 0, 0), (470, 320, 80, 100), 1)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit(0)
添加事件,鼠标移动时,变色:
import pygame
import math
import random
if __name__ == '__main__':
pygame.init()
screen = pygame.display.set_mode((800, 450))
screen.fill((255, 255, 255))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit(0)
if event.type == pygame.MOUSEMOTION:
r = random.randint(1, 255)
g = random.randint(1, 255)
b = random.randint(1, 255)
# 头
pygame.draw.circle(screen, (r, g, b), (400, 180), 135)
# 脸
pygame.draw.circle(screen, (255, 255, 255), (400, 200), 115)
# 嘴巴
pygame.draw.arc(screen, (0, 0, 0), (320, 160, 160, 100), math.pi, math.pi * 2)
# 鼻线
pygame.draw.line(screen, (0, 0, 0), (400, 150), (400, 260))
# 左眼
pygame.draw.ellipse(screen, (255, 255, 255), (340, 60, 60, 70))
pygame.draw.ellipse(screen, (0, 0, 0), (340, 60, 60, 70), 1)
pygame.draw.ellipse(screen, (0, 0, 0), (380, 80, 15, 25))
pygame.draw.ellipse(screen, (255, 255, 255), (385, 87, 5, 5))
# 右眼
pygame.draw.ellipse(screen, (255, 255, 255), (400, 60, 60, 70))
pygame.draw.ellipse(screen, (0, 0, 0), (400, 60, 60, 70), 1)
pygame.draw.ellipse(screen, (0, 0, 0), (440, 80, 15, 25))
pygame.draw.ellipse(screen, (255, 255, 255), (445, 87, 5, 5))
# 鼻子
pygame.draw.circle(screen, (255, 0, 0), (400, 135), 15)
# 身体
pygame.draw.rect(screen, (r, g, b), (300, 270, 200, 140))
pygame.draw.rect(screen, (0, 0, 0), (300, 270, 200, 140), 1)
# 围巾
pygame.draw.rect(screen, (255, 0, 0), (300, 270, 200, 15))
# 口袋
pygame.draw.ellipse(screen, (255, 255, 255), (320, 300, 160, 90))
pygame.draw.line(screen, (0, 0, 0), (360, 330), (440, 330))
pygame.draw.arc(screen, (0, 0, 0), (360, 290, 80, 80), math.pi, math.pi * 2)
# 左手
pygame.draw.line(screen, (r, g, b), (335, 300), (370, 400), 40)
pygame.draw.line(screen, (0, 0, 0), (315, 300), (350, 400), 1)
pygame.draw.line(screen, (0, 0, 0), (355, 300), (390, 400), 1)
pygame.draw.ellipse(screen, (255, 255, 255), (345, 380, 60, 40))
pygame.draw.ellipse(screen, (0, 0, 0), (345, 380, 60, 40), 1)
# 右手
pygame.draw.line(screen, (r, g, b), (465, 300), (425, 400), 40)
pygame.draw.line(screen, (0, 0, 0), (445, 300), (405, 400), 1)
pygame.draw.line(screen, (0, 0, 0), (485, 300), (445, 400), 1)
pygame.draw.ellipse(screen, (255, 255, 255), (390, 380, 60, 40))
pygame.draw.ellipse(screen, (0, 0, 0), (390, 380, 60, 40), 1)
# 铃铛
pygame.draw.circle(screen, (200, 250, 0), (400, 290), 15)
pygame.draw.line(screen, (0, 0, 0), (385, 288), (408, 288))
pygame.draw.line(screen, (0, 0, 0), (385, 292), (410, 292))
pygame.draw.line(screen, (0, 0, 0), (400, 292), (400, 305))
# 左jio
pygame.draw.ellipse(screen, (255, 255, 255), (250, 320, 80, 100))
pygame.draw.ellipse(screen, (0, 0, 0), (250, 320, 80, 100), 1)
# 右jio
pygame.draw.ellipse(screen, (255, 255, 255), (470, 320, 80, 100))
pygame.draw.ellipse(screen, (0, 0, 0), (470, 320, 80, 100), 1)
pygame.time.delay(10)
pygame.display.flip()