Compare commits
4 Commits
85499b9d80
...
add-hare
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47bc63b7c6 | ||
|
|
aee216b2a5 | ||
| 7a6a0e2696 | |||
|
|
a1bb978827 |
64
task1.py
64
task1.py
@@ -6,46 +6,62 @@ pygame.init()
|
|||||||
FPS = 30
|
FPS = 30
|
||||||
screen = pygame.display.set_mode((400, 400))
|
screen = pygame.display.set_mode((400, 400))
|
||||||
|
|
||||||
|
# Цвета
|
||||||
WHITE = (255, 255, 255)
|
WHITE = (255, 255, 255)
|
||||||
GRAY = (200, 200, 200)
|
GRAY = (200, 200, 200)
|
||||||
BLACK = (0, 0, 0)
|
BLACK = (0, 0, 0)
|
||||||
BROWN = (139, 69, 19)
|
BROWN = (139, 69, 19)
|
||||||
|
|
||||||
#Рисунок
|
|
||||||
def draw_body(surface, x, y, width, height, color):
|
def draw_body(surface, x, y, width, height, color):
|
||||||
''' Рисует тело '''
|
"""Рисует тело зайца."""
|
||||||
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
|
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
|
||||||
|
|
||||||
def draw_head(surface, x, y, size, color):
|
def draw_head(surface, x, y, size, color):
|
||||||
''' Рисует голову '''
|
"""Рисует голову зайца."""
|
||||||
circle(surface, color, (x, y), size // 2)
|
circle(surface, color, (x, y), size // 2)
|
||||||
|
|
||||||
def draw_ear(surface, x, y, width, height, color):
|
def draw_ear(surface, x, y, width, height, color):
|
||||||
''' Рисует ухо '''
|
"""Рисует ухо зайца."""
|
||||||
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
|
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
|
||||||
|
|
||||||
def draw_leg(surface, x, y, width, height, color):
|
def draw_leg(surface, x, y, width, height, color):
|
||||||
''' Рисует ногу '''
|
"""Рисует ногу зайца."""
|
||||||
ellipse(surface, color, (x - width // 2, y - height // 2, width, height))
|
def draw_hare(surface, center_x, center_y, total_width, total_height, color):
|
||||||
def draw_hare(srf, cx, cy, w, h, clr):
|
"""
|
||||||
''' Рисует зайца '''
|
Рисует зайца на экране.
|
||||||
bw = w // 2
|
|
||||||
bh = h // 2
|
|
||||||
by = cy + bh // 2
|
|
||||||
draw_body(srf, cx, by, bw, bh, clr)
|
|
||||||
|
|
||||||
hs = h // 4
|
Параметры:
|
||||||
hy = cy - hs // 2
|
surface: поверхность для рисования
|
||||||
draw_head(srf, cx, hy, hs, clr)
|
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)
|
||||||
|
|
||||||
eh = h // 3
|
# Голова
|
||||||
ey = cy - h // 2 + eh // 2
|
head_size = total_height // 4
|
||||||
for ex in (cx - hs // 4, cx + hs // 4):
|
head_y = center_y - head_size // 2
|
||||||
draw_ear(srf, ex, ey, w // 8, eh, clr)
|
draw_head(surface, center_x, head_y, head_size, color)
|
||||||
|
|
||||||
lh = h // 16
|
# Уши
|
||||||
ly = cy + h // 2 - lh // 2
|
ear_height = total_height // 3
|
||||||
coords = [cx - w // 4, cx + w // 4]
|
ear_y = center_y - total_height // 2 + ear_height // 2
|
||||||
for lx in coords:
|
ear_width = total_width // 8
|
||||||
draw_leg(srf, lx, ly, w // 4, lh, clr)
|
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)
|
draw_hare(screen, 200, 200, 200, 400, BROWN)
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|||||||
Reference in New Issue
Block a user