Files
YP_2026_litvintseva/rabit2.py
2026-03-18 12:35:54 +03:00

118 lines
4.4 KiB
Python
Executable File

#!/usr/bin/env python3
import pygame
from pygame.draw import *
pygame.init()
FPS = 30
screen = pygame.display.set_mode((400, 400))
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):
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
def draw_hare(surface, x, y, width, height, color):
body_width = width // 2
body_height = height // 2
body_y = y + body_height // 2
draw_body(surface, x, body_y, body_width, body_height, color)
head_size = height // 4
head_y = y - head_size // 2
draw_head(surface, x, head_y, head_size, color)
ear_height = height // 3
ear_y = y - height // 2 + ear_height // 2
draw_ear(surface, x - head_size // 4, ear_y, width // 8, ear_height, color)
draw_ear(surface, x + head_size // 4, ear_y, width // 8, ear_height, color)
leg_height = height // 16
leg_y = y + height // 2 - leg_height // 2
draw_leg(surface, x - width // 4, leg_y, width // 4, leg_height, color)
draw_leg(surface, x + width // 4, leg_y, width // 4, leg_height, color)
eye_y = head_y - head_size // 8
eye_radius = head_size // 8
circle(surface, (255, 255, 255), (x - head_size // 6, eye_y), eye_radius)
circle(surface, (255, 255, 255), (x + head_size // 6, eye_y), eye_radius)
pupil_radius = eye_radius // 2
circle(surface, (0, 0, 0), (x - head_size // 6, eye_y), pupil_radius)
circle(surface, (0, 0, 0), (x + head_size // 6, eye_y), pupil_radius)
spark_radius = pupil_radius // 3
circle(surface, (255, 255, 255), (x - head_size // 6 - 2, eye_y - 2), spark_radius)
circle(surface, (255, 255, 255), (x + head_size // 6 - 2, eye_y - 2), spark_radius)
nose_y = head_y + head_size // 8
polygon(surface, (255, 150, 150), [
(x, nose_y),
(x - head_size // 8, nose_y + head_size // 12),
(x + head_size // 8, nose_y + head_size // 12)
])
line(surface, (150, 100, 100),
(x, nose_y + head_size // 16),
(x, nose_y + head_size // 8), 2)
blush_radius = head_size // 10
circle(surface, (255, 200, 200), (x - head_size // 4, nose_y + head_size // 24), blush_radius)
circle(surface, (255, 200, 200), (x + head_size // 4, nose_y + head_size // 24), blush_radius)
whisker_y = nose_y + head_size // 24
whisker_length = head_size // 4
line(surface, (100, 100, 100),
(x - head_size // 10, whisker_y),
(x - whisker_length - head_size // 10, whisker_y - head_size // 10), 1)
line(surface, (100, 100, 100),
(x - head_size // 10, whisker_y + 2),
(x - whisker_length - head_size // 10, whisker_y - head_size // 10 + 2), 1)
line(surface, (100, 100, 100),
(x - head_size // 10, whisker_y + 4),
(x - whisker_length - head_size // 10, whisker_y - head_size // 10 + 4), 1)
line(surface, (100, 100, 100),
(x + head_size // 10, whisker_y),
(x + whisker_length + head_size // 10, whisker_y - head_size // 10), 1)
line(surface, (100, 100, 100),
(x + head_size // 10, whisker_y + 2),
(x + whisker_length + head_size // 10, whisker_y - head_size // 10 + 2), 1)
line(surface, (100, 100, 100),
(x + head_size // 10, whisker_y + 4),
(x + whisker_length + head_size // 10, whisker_y - head_size // 10 + 4), 1)
front_leg_width = width // 12
front_leg_height = height // 8
front_leg_y = y + height // 6
ellipse(surface, (0, 0, 0), (x - width // 6 - front_leg_width // 2,
front_leg_y - front_leg_height // 2,
front_leg_width, front_leg_height), 1)
ellipse(surface, (0, 0, 0), (x + width // 6 - front_leg_width // 2,
front_leg_y - front_leg_height // 2,
front_leg_width, front_leg_height), 1)
draw_hare(screen, 200, 200, 200, 400, (200, 200, 200))
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()