Files
2/task1.py
2026-03-18 15:03:10 +03:00

78 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pygame
from pygame.draw import *
pygame.init()
FPS = 30
screen = pygame.display.set_mode((400, 400))
# Цвета
WHITE = (255, 255, 255)
GRAY = (200, 200, 200)
BLACK = (0, 0, 0)
BROWN = (139, 69, 19)
def draw_body(surface, x, y, width, height, color):
"""Рисует тело зайца."""
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
def draw_head(surface, x, y, size, color):
"""Рисует голову зайца."""
circle(surface, color, (x, y), size // 2)
def draw_ear(surface, x, y, width, height, color):
"""Рисует ухо зайца."""
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
def draw_leg(surface, x, y, width, height, color):
"""Рисует ногу зайца."""
def draw_hare(surface, center_x, center_y, total_width, total_height, color):
"""
Рисует зайца на экране.
Параметры:
surface: поверхность для рисования
center_x, center_y: координаты центра изображения
total_width, total_height: ширина и высота изображения
color: цвет зайца
"""
# Тело
body_width = total_width // 2
body_height = total_height // 2
body_y = center_y + body_height // 2
draw_body(surface, center_x, body_y, body_width, body_height, color)
# Голова
head_size = total_height // 4
head_y = center_y - head_size // 2
draw_head(surface, center_x, head_y, head_size, color)
# Уши
ear_height = total_height // 3
ear_y = center_y - total_height // 2 + ear_height // 2
ear_width = total_width // 8
draw_ear(surface, center_x - head_size // 4, ear_y, ear_width, ear_height, color)
draw_ear(surface, center_x + head_size // 4, ear_y, ear_width, ear_height, color)
# Ноги
leg_height = total_height // 16
leg_y = center_y + total_height // 2 - leg_height // 2
leg_width = total_width // 4
draw_leg(surface, center_x - total_width // 4, leg_y, leg_width, leg_height, color)
draw_leg(surface, center_x + total_width // 4, leg_y, leg_width, leg_height, color)
# Рисуем зайца
draw_hare(screen, 200, 200, 200, 400, BROWN)
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()