Compare commits

4 Commits
main ... main

Author SHA1 Message Date
921d41b816 Обновить rabit2.py 2026-03-18 14:04:13 +03:00
65c49aaa7b Обновить rabit2.py 2026-03-18 13:24:33 +03:00
f5d679db68 Обновить rabit2.py 2026-03-18 13:21:32 +03:00
7a648e6b72 Обновить rabit2.py 2026-03-18 12:03:28 +03:00

169
rabit2.py
View File

@@ -6,112 +6,125 @@ pygame.init()
FPS = 30
screen = pygame.display.set_mode((400, 400))
clock = pygame.time.Clock()
def draw_body(surface, x, y, width, height, color):
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
# === 1. Словарь цветов ===
COLORS = {
"WHITE": (255, 255, 255),
"BLACK": (0, 0, 0),
"NOSE": (255, 150, 150),
"MOUTH": (150, 100, 100),
"BLUSH": (255, 200, 200),
"WHISKERS": (100, 100, 100),
"BODY": (200, 200, 200)
}
def draw_head(surface, x, y, size, color):
circle(surface, color, (x, y), size // 2)
# === 2. Словарь размеров и пропорций ===
SIZES = {
"body_ratio": 0.5,
"head_ratio": 0.25,
"ear_ratio": 1/3,
"leg_ratio": 1/16,
"eye_ratio": 1/8,
"blush_ratio": 1/10,
"front_leg_w_ratio": 1/12,
"front_leg_h_ratio": 1/8
}
def draw_ear(surface, x, y, width, height, color):
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
# === 3. Подфункции для частей тела ===
def draw_body(surface, x, y, width, height, color=None):
ellipse(surface, color, (x - width // 4, y, width // 2, height // 2))
def draw_leg(surface, x, y, width, height, color):
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
def draw_head(surface, x, y, width, height, color=None):
head_size = int(height * SIZES["head_ratio"])
circle(surface, color, (x, y - head_size // 2), head_size // 2)
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)
def draw_ears(surface, x, y, width, height, color=None):
head_size = int(height * SIZES["head_ratio"])
ear_h = int(height * SIZES["ear_ratio"])
ellipse(surface, color, (x - head_size // 4 - width // 16, y - height // 2, width // 8, ear_h))
ellipse(surface, color, (x + head_size // 4 - width // 16, y - height // 2, width // 8, ear_h))
head_size = height // 4
def draw_eyes(surface, x, y, width, height, color=None): # color необязательный
head_size = int(height * SIZES["head_ratio"])
eye_r = int(head_size * SIZES["eye_ratio"])
eye_y = y - head_size // 2 - head_size // 8
circle(surface, COLORS["WHITE"], (x - head_size // 6, eye_y), eye_r)
circle(surface, COLORS["WHITE"], (x + head_size // 6, eye_y), eye_r)
circle(surface, COLORS["BLACK"], (x - head_size // 6, eye_y), eye_r // 2)
circle(surface, COLORS["BLACK"], (x + head_size // 6, eye_y), eye_r // 2)
circle(surface, COLORS["WHITE"], (x - head_size // 6 - 2, eye_y - 2), eye_r // 6)
circle(surface, COLORS["WHITE"], (x + head_size // 6 - 2, eye_y - 2), eye_r // 6)
def draw_nose_mouth(surface, x, y, width, height, color=None):
head_size = int(height * SIZES["head_ratio"])
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
for ear_x in (x - head_size // 4, x + head_size // 4):
draw_ear(surface, ear_x, ear_y, width // 8, ear_height, color)
leg_height = height // 16
leg_y = y + height // 2 - leg_height // 2
for leg_x in (x - width // 4, x + width // 4):
draw_leg(surface, leg_x, leg_y, width // 4, leg_height, color)
# Глаза (белки)
eye_y = head_y - head_size // 8
eye_radius = head_size // 8
for eye_x in (x - head_size // 6, x + head_size // 6):
circle(surface, (255, 255, 255), (eye_x, eye_y), eye_radius)
# Зрачки
pupil_radius = eye_radius // 2
for pupil_x in (x - head_size // 6, x + head_size // 6):
circle(surface, (0, 0, 0), (pupil_x, eye_y), pupil_radius)
# Блики в глазах
spark_radius = pupil_radius // 3
for spark_x in (x - head_size // 6 - 2, x + head_size // 6 - 2):
circle(surface, (255, 255, 255), (spark_x, eye_y - 2), spark_radius)
# Носик (розовый треугольник)
nose_y = head_y + head_size // 8
polygon(surface, (255, 150, 150), [
polygon(surface, COLORS["NOSE"], [
(x, nose_y),
(x - head_size // 8, nose_y + head_size // 12),
(x + head_size // 8, nose_y + head_size // 12)
])
line(surface, COLORS["MOUTH"], (x, nose_y + head_size // 16), (x, nose_y + head_size // 8), 2)
# Ротик
line(surface, (150, 100, 100),
(x, nose_y + head_size // 16),
(x, nose_y + head_size // 8), 2)
def draw_blush_whiskers(surface, x, y, width, height, color=None):
head_size = int(height * SIZES["head_ratio"])
head_y = y - head_size // 2
nose_y = head_y + head_size // 8
# Немного румянца на щечках
blush_radius = head_size // 10
for cheek_x in (x - head_size // 4, x + head_size // 4):
circle(surface, (255, 200, 200), (cheek_x, nose_y + head_size // 24), blush_radius)
blush_r = int(head_size * SIZES["blush_ratio"])
circle(surface, COLORS["BLUSH"], (x - head_size // 4, nose_y + head_size // 24), blush_r)
circle(surface, COLORS["BLUSH"], (x + head_size // 4, nose_y + head_size // 24), blush_r)
# Усики
whisker_y = nose_y + head_size // 24
whisker_length = head_size // 4
whisker_len = head_size // 4
for i in range(3):
# Левые усики
line(surface, (100, 100, 100),
(x - head_size // 10, whisker_y + i * 2),
(x - whisker_length - head_size // 10, whisker_y - head_size // 10 + i * 2), 1)
# Правые усики
line(surface, (100, 100, 100),
(x + head_size // 10, whisker_y + i * 2),
(x + whisker_length + head_size // 10, whisker_y - head_size // 10 + i * 2), 1)
line(surface, COLORS["WHISKERS"],
(x - head_size // 10, whisker_y + i * 2),
(x - whisker_len - head_size // 10, whisker_y - head_size // 10 + i * 2), 1)
line(surface, COLORS["WHISKERS"],
(x + head_size // 10, whisker_y + i * 2),
(x + whisker_len + head_size // 10, whisker_y - head_size // 10 + i * 2), 1)
# Передние лапки (две маленькие) - с обводкой
front_leg_width = width // 12
front_leg_height = height // 8
front_leg_y = y + height // 6
def draw_front_legs(surface, x, y, width, height, color=None):
fw = int(width * SIZES["front_leg_w_ratio"])
fh = int(height * SIZES["front_leg_h_ratio"])
fy = 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, color, (x - width // 6 - fw // 2, fy - fh // 2, fw, fh))
ellipse(surface, COLORS["BLACK"], (x - width // 6 - fw // 2, fy - fh // 2, fw, fh), 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)
ellipse(surface, color, (x + width // 6 - fw // 2, fy - fh // 2, fw, fh))
ellipse(surface, COLORS["BLACK"], (x + width // 6 - fw // 2, fy - fh // 2, fw, fh), 1)
# === 4. Словарь функций частей тела ===
PARTS = {
"body": draw_body,
"head": draw_head,
"ears": draw_ears,
"eyes": draw_eyes,
"nose_mouth": draw_nose_mouth,
"blush_whiskers": draw_blush_whiskers,
"front_legs": draw_front_legs
}
draw_hare(screen, 200, 200, 200, 400, (200, 200, 200))
# === 5. Главная функция, объединяющая все части ===
def draw_hare(surface, x, y, width, height, color):
for part in ["body", "head", "ears", "eyes", "nose_mouth", "blush_whiskers", "front_legs"]:
PARTS[part](surface, x, y, width, height, color)
# === РИСУЕМ ===
screen.fill(COLORS["WHITE"])
draw_hare(screen, 200, 200, 200, 400, COLORS["BODY"])
pygame.display.update()
clock = pygame.time.Clock()
finished = False
finished = False
while not finished:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
finished = True
pygame.quit()
pygame.quit()