123 lines
2.9 KiB
Python
Executable File
123 lines
2.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import pygame
|
|
from pygame.draw import *
|
|
import math
|
|
|
|
pygame.init()
|
|
|
|
FPS = 30
|
|
screen = pygame.display.set_mode((900, 900))
|
|
clock = pygame.time.Clock()
|
|
|
|
# COLORS (через список)
|
|
COLORS = [
|
|
(255, 255, 255), # 0 WHITE
|
|
(230, 230, 230), # 1 GRAY
|
|
(180, 180, 180), # 2 DARK_GRAY
|
|
(255, 210, 210), # 3 PINK
|
|
(255, 120, 120), # 4 NOSE
|
|
(0, 0, 0) # 5 BLACK
|
|
]
|
|
|
|
WHITE, GRAY, DARK_GRAY, PINK, NOSE, BLACK = COLORS
|
|
|
|
cx, cy = 450, 420
|
|
|
|
|
|
def draw_body(surface, x, y):
|
|
ellipse(surface, GRAY, (x - 150, y, 300, 220))
|
|
ellipse(surface, DARK_GRAY, (x - 80, y + 80, 160, 100))
|
|
|
|
|
|
def draw_head(surface, x, y):
|
|
circle(surface, GRAY, (x, y - 120), 120)
|
|
|
|
|
|
def draw_ears(surface, x, y):
|
|
ellipse(surface, GRAY, (x - 90, y - 420, 70, 260))
|
|
ellipse(surface, GRAY, (x + 20, y - 420, 70, 260))
|
|
|
|
ellipse(surface, PINK, (x - 70, y - 400, 30, 200))
|
|
ellipse(surface, PINK, (x + 40, y - 400, 30, 200))
|
|
|
|
|
|
def draw_eyes(surface, x, y):
|
|
eye_y = y - 150
|
|
circle(surface, BLACK, (x - 45, eye_y), 12)
|
|
circle(surface, BLACK, (x + 45, eye_y), 12)
|
|
|
|
circle(surface, WHITE, (x - 50, eye_y - 5), 4)
|
|
circle(surface, WHITE, (x + 40, eye_y - 5), 4)
|
|
|
|
|
|
def draw_nose(surface, x, y):
|
|
ny = y - 90
|
|
polygon(surface, NOSE, [
|
|
(x, ny),
|
|
(x - 12, ny + 14),
|
|
(x + 12, ny + 14)
|
|
])
|
|
return ny
|
|
|
|
|
|
def draw_mouth(surface, x, ny):
|
|
line(surface, BLACK, (x, ny + 14), (x, ny + 28), 2)
|
|
arc(surface, BLACK, (x - 30, ny + 20, 30, 20), math.pi, 2 * math.pi, 2)
|
|
arc(surface, BLACK, (x, ny + 20, 30, 20), math.pi, 2 * math.pi, 2)
|
|
|
|
|
|
def draw_whiskers(surface, x, ny):
|
|
for side in [-1, 1]:
|
|
for angle in [-10, 0, 10]:
|
|
rad = math.radians(angle)
|
|
x1 = x + side * 10
|
|
y1 = ny + 10
|
|
x2 = x + side * (10 + 120 * math.cos(rad))
|
|
y2 = ny + 10 + 40 * math.sin(rad)
|
|
line(surface, BLACK, (x1, y1), (x2, y2), 2)
|
|
|
|
|
|
def draw_paws(surface, x, y):
|
|
ellipse(surface, GRAY, (x - 120, y + 160, 90, 50))
|
|
ellipse(surface, GRAY, (x + 30, y + 160, 90, 50))
|
|
|
|
ellipse(surface, GRAY, (x - 180, y + 200, 120, 70))
|
|
ellipse(surface, GRAY, (x + 60, y + 200, 120, 70))
|
|
|
|
|
|
def draw_tail(surface, x, y):
|
|
circle(surface, GRAY, (x + 160, y + 80), 30)
|
|
|
|
|
|
def draw_shadow(surface, x, y):
|
|
ellipse(surface, (200, 200, 200), (x - 200, y + 220, 400, 60))
|
|
|
|
|
|
def draw_hare(surface, x, y):
|
|
draw_shadow(surface, x, y)
|
|
draw_body(surface, x, y)
|
|
draw_head(surface, x, y)
|
|
draw_ears(surface, x, y)
|
|
draw_eyes(surface, x, y)
|
|
|
|
ny = draw_nose(surface, x, y)
|
|
draw_mouth(surface, x, ny)
|
|
draw_whiskers(surface, x, ny)
|
|
|
|
draw_paws(surface, x, y)
|
|
draw_tail(surface, x, y)
|
|
|
|
|
|
screen.fill(WHITE)
|
|
draw_hare(screen, cx, cy)
|
|
|
|
pygame.display.update()
|
|
|
|
running = True
|
|
while running:
|
|
clock.tick(FPS)
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
running = False
|
|
|
|
pygame.quit() |