Обновить rabit2.py
This commit is contained in:
151
rabit2.py
151
rabit2.py
@@ -6,119 +6,114 @@ pygame.init()
|
|||||||
|
|
||||||
FPS = 30
|
FPS = 30
|
||||||
screen = pygame.display.set_mode((400, 400))
|
screen = pygame.display.set_mode((400, 400))
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
def draw_body(surface, x, y, width, height, color):
|
# COLORS через список
|
||||||
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
|
COLORS = [
|
||||||
|
(255, 255, 255), # 0 WHITE
|
||||||
|
(0, 0, 0), # 1 BLACK
|
||||||
|
(255, 150, 150), # 2 NOSE
|
||||||
|
(150, 100, 100), # 3 MOUTH
|
||||||
|
(255, 200, 200), # 4 BLUSH
|
||||||
|
(100, 100, 100), # 5 WHISKERS
|
||||||
|
(200, 200, 200) # 6 BODY
|
||||||
|
]
|
||||||
|
|
||||||
def draw_head(surface, x, y, size, color):
|
WHITE, BLACK, NOSE, MOUTH, BLUSH, WHISKERS, BODY = COLORS
|
||||||
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):
|
def draw_hare(surface, x, y, width, height, color):
|
||||||
body_width = width // 2
|
# === ОСНОВНЫЕ ЧИСЛА ===
|
||||||
body_height = height // 2
|
body_w = width // 2
|
||||||
body_y = y + body_height // 2
|
body_h = height // 2
|
||||||
draw_body(surface, x, body_y, body_width, body_height, color)
|
|
||||||
|
|
||||||
head_size = height // 4
|
head_size = height // 4
|
||||||
|
ear_h = height // 3
|
||||||
|
|
||||||
|
# === ТЕЛО ===
|
||||||
|
ellipse(surface, color, (x - body_w // 2, y + body_h // 2 - body_h // 2, body_w, body_h))
|
||||||
|
|
||||||
|
# === ГОЛОВА ===
|
||||||
head_y = y - head_size // 2
|
head_y = y - head_size // 2
|
||||||
draw_head(surface, x, head_y, head_size, color)
|
circle(surface, color, (x, head_y), head_size // 2)
|
||||||
|
|
||||||
ear_height = height // 3
|
# === УШИ ===
|
||||||
ear_y = y - height // 2 + ear_height // 2
|
ear_y = y - height // 2 + ear_h // 2
|
||||||
for ear_x in (x - head_size // 4, x + head_size // 4):
|
ellipse(surface, color, (x - head_size // 4 - width // 16, ear_y - ear_h // 2, width // 8, ear_h))
|
||||||
draw_ear(surface, ear_x, ear_y, width // 8, ear_height, color)
|
ellipse(surface, color, (x + head_size // 4 - width // 16, ear_y - ear_h // 2, width // 8, ear_h))
|
||||||
|
|
||||||
leg_height = height // 16
|
# === ЛАПЫ (задние) ===
|
||||||
leg_y = y + height // 2 - leg_height // 2
|
leg_h = height // 16
|
||||||
for leg_x in (x - width // 4, x + width // 4):
|
leg_y = y + height // 2 - leg_h // 2
|
||||||
draw_leg(surface, leg_x, leg_y, width // 4, leg_height, color)
|
ellipse(surface, color, (x - width // 4 - width // 8, leg_y - leg_h // 2, width // 4, leg_h))
|
||||||
|
ellipse(surface, color, (x + width // 4 - width // 8, leg_y - leg_h // 2, width // 4, leg_h))
|
||||||
|
|
||||||
# Добавляем детали
|
# === ГЛАЗА ===
|
||||||
|
|
||||||
# Глаза (белки)
|
|
||||||
eye_y = head_y - head_size // 8
|
eye_y = head_y - head_size // 8
|
||||||
eye_radius = head_size // 8
|
eye_r = 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)
|
|
||||||
|
|
||||||
# Зрачки
|
circle(surface, WHITE, (x - head_size // 6, eye_y), eye_r)
|
||||||
pupil_radius = eye_radius // 2
|
circle(surface, WHITE, (x + head_size // 6, eye_y), eye_r)
|
||||||
for pupil_x in (x - head_size // 6, x + head_size // 6):
|
|
||||||
circle(surface, (0, 0, 0), (pupil_x, eye_y), pupil_radius)
|
|
||||||
|
|
||||||
# Блики в глазах
|
circle(surface, BLACK, (x - head_size // 6, eye_y), eye_r // 2)
|
||||||
spark_radius = pupil_radius // 3
|
circle(surface, BLACK, (x + head_size // 6, eye_y), eye_r // 2)
|
||||||
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)
|
|
||||||
|
|
||||||
# Носик (розовый треугольник)
|
circle(surface, WHITE, (x - head_size // 6 - 2, eye_y - 2), eye_r // 6)
|
||||||
|
circle(surface, WHITE, (x + head_size // 6 - 2, eye_y - 2), eye_r // 6)
|
||||||
|
|
||||||
|
# === НОС ===
|
||||||
nose_y = head_y + head_size // 8
|
nose_y = head_y + head_size // 8
|
||||||
polygon(surface, (255, 150, 150), [
|
polygon(surface, NOSE, [
|
||||||
(x, nose_y),
|
(x, nose_y),
|
||||||
(x - head_size // 8, nose_y + head_size // 12),
|
(x - head_size // 8, nose_y + head_size // 12),
|
||||||
(x + head_size // 8, nose_y + head_size // 12)
|
(x + head_size // 8, nose_y + head_size // 12)
|
||||||
])
|
])
|
||||||
|
|
||||||
# Ротик
|
# === РОТ ===
|
||||||
line(surface, (150, 100, 100),
|
line(surface, MOUTH,
|
||||||
(x, nose_y + head_size // 16),
|
(x, nose_y + head_size // 16),
|
||||||
(x, nose_y + head_size // 8), 2)
|
(x, nose_y + head_size // 8), 2)
|
||||||
|
|
||||||
# Немного румянца на щечках
|
# === ЩЁКИ ===
|
||||||
blush_radius = head_size // 10
|
blush_r = head_size // 10
|
||||||
for cheek_x in (x - head_size // 4, x + head_size // 4):
|
circle(surface, BLUSH, (x - head_size // 4, nose_y + head_size // 24), blush_r)
|
||||||
circle(surface, (255, 200, 200), (cheek_x, nose_y + head_size // 24), blush_radius)
|
circle(surface, BLUSH, (x + head_size // 4, nose_y + head_size // 24), blush_r)
|
||||||
|
|
||||||
# Усики (по три с каждой стороны) - теперь после румянца
|
# === УСЫ ===
|
||||||
whisker_y = nose_y + head_size // 24
|
whisker_y = nose_y + head_size // 24
|
||||||
whisker_length = head_size // 4
|
whisker_len = head_size // 4
|
||||||
|
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
# Левые усики
|
line(surface, WHISKERS,
|
||||||
line(surface, (100, 100, 100),
|
(x - head_size // 10, whisker_y + i * 2),
|
||||||
(x - head_size // 10, whisker_y + i * 2),
|
(x - whisker_len - head_size // 10, whisker_y - head_size // 10 + i * 2), 1)
|
||||||
(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, WHISKERS,
|
||||||
front_leg_width = width // 12
|
(x + head_size // 10, whisker_y + i * 2),
|
||||||
front_leg_height = height // 8
|
(x + whisker_len + head_size // 10, whisker_y - head_size // 10 + i * 2), 1)
|
||||||
front_leg_y = y + height // 6
|
|
||||||
|
|
||||||
# Левая передняя лапка (с обводкой)
|
# === ПЕРЕДНИЕ ЛАПЫ ===
|
||||||
ellipse(surface, color, (x - width // 6 - front_leg_width // 2,
|
fw = width // 12
|
||||||
front_leg_y - front_leg_height // 2,
|
fh = height // 8
|
||||||
front_leg_width, front_leg_height))
|
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, color, (x + width // 6 - front_leg_width // 2,
|
ellipse(surface, BLACK, (x - width // 6 - fw // 2, fy - fh // 2, fw, fh), 1)
|
||||||
front_leg_y - front_leg_height // 2,
|
|
||||||
front_leg_width, front_leg_height))
|
|
||||||
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))
|
ellipse(surface, color, (x + width // 6 - fw // 2, fy - fh // 2, fw, fh))
|
||||||
|
ellipse(surface, BLACK, (x + width // 6 - fw // 2, fy - fh // 2, fw, fh), 1)
|
||||||
|
|
||||||
|
|
||||||
|
# РИСУЕМ
|
||||||
|
screen.fill(WHITE)
|
||||||
|
draw_hare(screen, 200, 200, 200, 400, BODY)
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
clock = pygame.time.Clock()
|
|
||||||
finished = False
|
|
||||||
|
|
||||||
|
finished = False
|
||||||
while not finished:
|
while not finished:
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
finished = True
|
finished = True
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
Reference in New Issue
Block a user