自制动画
import pygame
import math
from random import randint as ri
if __name__ == '__main__':
pygame.init()
screen = pygame.display.set_mode((500,500))
font = pygame.font.Font('./font/aa.ttf', 40)
sum_l = 115 # 初始左眼珠x坐标
sum_r = 295 # 初始右眼珠x坐标
add = 0 # 眼珠移动标量
count = 0 # 计数器
sum_h1 = 255 # 初始白条高度
sum_h2 = 0 # 初始能量条高度
sum_h3 = 375 # 初始能量起点
change_height = 0 # 变色高度
while True:
count += 1
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
screen.fill((255, 255, 255))
surface = font.render('滑稽次数: '+str(int(count/90)), True, (ri(0,255),ri(0,255),ri(0,255))) # 文字打印
screen.blit(surface,(20,20))
pygame.draw.circle(screen, (255, 255, 0), (250, 250), 140) # 大黄脸
pygame.draw.circle(screen, (200, 200, 0), (250, 250), 141, 1) # 黄脸轮廓线
pygame.draw.ellipse(screen, (255, 255, 255), (100, 170, 120, 40)) # 左眼
pygame.draw.ellipse(screen, (210, 210, 0), (100, 170, 120, 40), 1) #左眼轮廓线
pygame.draw.ellipse(screen, (255, 255, 255), (280, 170, 120, 40)) # 右眼
pygame.draw.ellipse(screen, (210, 210, 0), (280, 170, 120, 40), 1) #右眼轮廓线
pygame.draw.arc(screen,(100,100,0),(130,130,240,240),math.pi*16/15,math.pi*29/15,2) # 嘴
pygame.draw.arc(screen,(150,150,0),(130,120,70,50),math.pi/16,math.pi*5/6,3) # 左眉
pygame.draw.arc(screen,(150,150,0),(300,120,70,50),math.pi/6,math.pi*15/16,3) # 右眉
pygame.draw.circle(screen, (ri(0,255),ri(0,255),ri(0,255)), (sum_l, 190), 12) # 左眼珠
pygame.draw.circle(screen, (ri(0,255),ri(0,255),ri(0,255)), (sum_r, 190), 12) # 右眼珠
pygame.draw.rect(screen,(255,255,255),(430,120,30,sum_h1)) # 能量槽1
pygame.draw.rect(screen,(sum_h2,sum_h1,ri(0,255)),(430,sum_h3,30,sum_h2)) # 能量槽2
pygame.draw.rect(screen,(0,0,0),(430,120,30,255),1) # 能量槽轮廓框
# 眼珠移动控制器
if sum_l == 115:
add = 1
if sum_l == 205:
add = -1
if add > 0:
sum_l += add
sum_r += add
else:
sum_l += add
sum_r += add
# 能量条控制器
if sum_h2 == 0:
change_height = 1
if sum_h2 == 255:
change_height = -1
sum_h1 -= change_height
sum_h2 += change_height
sum_h3 -= change_height
pygame.display.flip()
# 眼珠移速控制器
pygame.time.delay(20)
image.png
网友评论