Files
LABAn3/lb3_GLEB_fix.py
2026-03-31 19:48:23 +03:00

116 lines
3.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
import sys
# Инициализация
pygame.init()
WIDTH, HEIGHT = 600, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Кроликкк")
# Цвета
WHITE = (255, 255, 255)
GRAY = (200, 200, 200)
PINK = (255, 180, 180)
BLACK = (0, 0, 0)
def draw_ears(surface):
"""Рисует уши кролика с использованием циклов"""
# Позиции для левого и правого уха
ear_positions = [
(250, 100, 40, 120), # левое ухо (внешняя часть)
(310, 100, 40, 120) # правое ухо (внешняя часть)
]
# Внешняя часть ушей
for x, y, w, h in ear_positions:
pygame.draw.ellipse(surface, GRAY, (x, y, w, h))
# Внутренняя часть ушей
inner_ear_positions = [
(260, 110, 20, 80), # левое ухо (внутренняя часть)
(320, 110, 20, 80) # правое ухо (внутренняя часть)
]
for x, y, w, h in inner_ear_positions:
pygame.draw.ellipse(surface, PINK, (x, y, w, h))
def draw_head(surface):
"""Рисует голову кролика"""
pygame.draw.circle(surface, GRAY, (300, 250), 80)
def draw_face(surface):
"""Рисует лицо кролика с использованием циклов"""
x, y = 300, 250
# Глаза с бликами (цикл для повторяющихся элементов)
eye_offsets = [(-30, -10), (30, -10)]
for dx, dy in eye_offsets:
eye_x, eye_y = x + dx, y + dy
pygame.draw.circle(surface, BLACK, (eye_x, eye_y), 10)
pygame.draw.circle(surface, WHITE, (eye_x + 5, eye_y - 5), 4)
# Нос
pygame.draw.circle(surface, PINK, (x, y + 20), 8)
# Рот
pygame.draw.arc(surface, BLACK, (x - 15, y + 25, 30, 20), 3.14, 0, 2)
# Усы (цикл для пар линий)
mustache_points = [
(260, 270, 220, 265), # левый верхний
(260, 275, 220, 280), # левый нижний
(340, 270, 380, 265), # правый верхний
(340, 275, 380, 280) # правый нижний
]
for x1, y1, x2, y2 in mustache_points:
pygame.draw.line(surface, BLACK, (x1, y1), (x2, y2), 2)
def draw_body(surface):
"""Рисует тело кролика"""
pygame.draw.ellipse(surface, GRAY, (240, 330, 120, 150))
def draw_limbs(surface):
"""Рисует лапки и хвост с использованием циклов"""
# Лапки (левая и правая)
paw_positions = [
(250, 450, 40, 50), # левая лапка
(310, 450, 40, 50) # правая лапка
]
for x, y, w, h in paw_positions:
pygame.draw.ellipse(surface, GRAY, (x, y, w, h))
# Хвост
pygame.draw.circle(surface, WHITE, (300, 470), 20)
def draw_rabbit(surface):
"""Отрисовывает всего кролика в правильном порядке"""
# Порядок отрисовки оптимизирован (сначала задние элементы)
draw_body(surface)
draw_head(surface)
draw_ears(surface)
draw_face(surface)
draw_limbs(surface)
# Основной цикл
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill(WHITE)
draw_rabbit(screen)
pygame.display.flip()
clock.tick(60)
pygame.quit()
sys.exit()