On-screen text
project.py 2
import pygame
import math
pygame.init()
WIDTH, HEIGHT = 1000, 700
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("3D Cartoon Animation")
clock = pygame.time.Clock()
BG = (15, 18, 30)
SKIN = (255, 220, 180)
HAIR = (40, 20, 10)
HOODIE = (90, 120, 255)
HOODIE_SHADOW = (60, 80, 200)
EYE = (255, 255, 255)
PUPIL = (20, 20, 20)
MOUTH = (255, 120, 120)
SHOE = (255, 255, 255)
time = 0
def draw_cartoon(x, y, scale, t):
bounce = math.sin(t * 0.08) * 12
float_y = y + bounce
pygame.draw.ellipse(
screen,
(0, 0, 0),
(x - 70, float_y + 180, 140, 35),
)
pygame.draw.circle(
screen,
SKIN,
(x, int(float_y - 40)),
int(65 * scale),
)
pygame.draw.arc(
screen,
HAIR,
(x - 70, float_y - 110, 140, 90),
math.pi * 2,
18,
)
eye_offset = math.sin(t * 0.15) * 2
pygame.draw.circle(
screen,
EYE,
(x - 22, int(float_y - 48)),
10,
)
pygame.draw.circle(
screen,
EYE,
(x + 22, int(float_y - 48)),
10,
)
pygame.draw.circle(
screen,
PUPIL,
(int(x - 22 + eye_offset), int(float_y - 48)),
4,
)
pygame.draw.circle(
screen,
PUPIL,
(int(x + 22 + eye_offset), int(float_y - 48)),
4,
)
mouth_open = abs(math.sin(t * 0.12)) * 8
pygame.draw.arc(
screen,
MOUTH,
(x - 18, float_y - 20, 36, mouth_open + 10),
0,
math.pi,
3,
)
pygame.draw.rect(
screen,
HOODIE,
(x - 55, float_y + 20, 110, 120),
border_radius=30,
)
pygame.draw.rect(
screen,
HOODIE_SHADOW,
(x - 55, float_y + 20, 55, 120),
border_radius=30,
)
arm_wave = math.sin(t * 0.1) * 20
pygame.draw.line(
screen,
HOODIE,
(x - 50, float_y + 40),
(x - 100, float_y + 90 + arm_wave),
18,
)
pygame.draw.line(
screen,
HOODIE,
(x + 50, float_y + 40),
(x + 95, float_y + 90 - arm_wave),
18,
)
pygame.draw.line(
screen,
(40, 40, 40),
(x - 25, float_y + 140),
(x - 35, float_y + 220),
18,
)
pygame.draw.line(
screen,
(40, 40, 40),
(x + 25, float_y + 140),
(x + 35, float_y + 220),
18,
)
pygame.draw.ellipse(
screen,
SHOE,
(x - 60, float_y + 210, 45, 20),
)
pygame.draw.ellipse(
screen,
SHOE,
(x + 15, float_y + 210, 45, 20),
)
running = True
while running:
screen.fill(BG)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
for i in range(8):
radius = 100 + i * 35
pygame.draw.circle(
screen,
(20, 30, 60),
(WIDTH // 2, HEIGHT // 2),
radius,
2,
)
draw_cartoon(WIDTH // 2, HEIGHT // 2 - 50, 1, time)
time += 1
pygame.display.flip()
clock.tick(60)
pygame.quit()
Watch the final result😮🥶. Want the source code? Comment “Code” and I’ll DM it to you directly👉🏻#programming #coding #developer #python #computer