#!/usr/bin/env python3 import pygame from pygame.draw import * import math pygame.init() FPS = 30 screen = pygame.display.set_mode((900, 900)) # 1) Цвета WHITE = (255, 255, 255) GRAY = (230, 230, 230) DARK_GRAY = (180, 180, 180) PINK = (255, 210, 210) NOSE = (255, 120, 120) BLACK = (0, 0, 0) # 2) Координаты центра cx = 450 cy = 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_left_ear(surface, x, y): """Рисует левое ухо""" ellipse(surface, GRAY, (x - 90, y - 420, 70, 260)) ellipse(surface, PINK, (x - 70, y - 400, 30, 200)) def draw_right_ear(surface, x, y): """Рисует правое ухо""" ellipse(surface, GRAY, (x + 20, y - 420, 70, 260)) ellipse(surface, PINK, (x + 40, y - 400, 30, 200)) def draw_left_eye(surface, x, y): """Рисует левый глаз""" eye_y = y - 150 circle(surface, BLACK, (x - 45, eye_y), 12) circle(surface, WHITE, (x - 50, eye_y - 5), 4) def draw_right_eye(surface, x, y): """Рисует правый глаз""" eye_y = y - 150 circle(surface, BLACK, (x + 45, eye_y), 12) circle(surface, WHITE, (x + 40, eye_y - 5), 4) def draw_nose(surface, x, y): """Рисует нос и возвращает его координату 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_left_whiskers(surface, x, ny): """Рисует левые усы""" for angle in [-10, 0, 10]: rad = math.radians(angle) x1 = x - 10 y1 = ny + 10 x2 = x - (10 + 120 * math.cos(rad)) y2 = ny + 10 + 40 * math.sin(rad) line(surface, BLACK, (x1, y1), (x2, y2), 2) def draw_right_whiskers(surface, x, ny): """Рисует правые усы""" for angle in [-10, 0, 10]: rad = math.radians(angle) x1 = x + 10 y1 = ny + 10 x2 = x + (10 + 120 * math.cos(rad)) y2 = ny + 10 + 40 * math.sin(rad) line(surface, BLACK, (x1, y1), (x2, y2), 2) def draw_left_front_paw(surface, x, y): """Рисует левую переднюю лапу""" ellipse(surface, GRAY, (x - 120, y + 160, 90, 50)) def draw_right_front_paw(surface, x, y): """Рисует правую переднюю лапу""" ellipse(surface, GRAY, (x + 30, y + 160, 90, 50)) def draw_left_hind_paw(surface, x, y): """Рисует левую заднюю лапу""" ellipse(surface, GRAY, (x - 180, y + 200, 120, 70)) def draw_right_hind_paw(surface, x, y): """Рисует правую заднюю лапу""" 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_left_ear(surface, x, y) draw_right_ear(surface, x, y) # Глаза draw_left_eye(surface, x, y) draw_right_eye(surface, x, y) # Нос и рот ny = draw_nose(surface, x, y) draw_mouth(surface, x, ny) # Усы draw_left_whiskers(surface, x, ny) draw_right_whiskers(surface, x, ny) # Лапы draw_left_front_paw(surface, x, y) draw_right_front_paw(surface, x, y) draw_left_hind_paw(surface, x, y) draw_right_hind_paw(surface, x, y) # Хвост draw_tail(surface, x, y) # Рисуем зайца screen.fill(WHITE) draw_hare(screen, cx, cy) pygame.display.update() clock = pygame.time.Clock() finished = False while not finished: clock.tick(FPS) for event in pygame.event.get(): if event.type == pygame.QUIT: finished = True pygame.quit()