Compare commits
7 Commits
6606671945
...
add-hare
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47bc63b7c6 | ||
|
|
aee216b2a5 | ||
| 7a6a0e2696 | |||
|
|
a1bb978827 | ||
| ef3f80babb | |||
| cf68650ab5 | |||
|
|
bc88e2138a |
80
hare.py
80
hare.py
@@ -1,80 +0,0 @@
|
|||||||
import pygame
|
|
||||||
from pygame.draw import *
|
|
||||||
|
|
||||||
pygame.init()
|
|
||||||
|
|
||||||
FPS = 30
|
|
||||||
screen = pygame.display.set_mode((400, 400))
|
|
||||||
|
|
||||||
# Цвета
|
|
||||||
WHITE = (255, 255, 255)
|
|
||||||
GRAY = (200, 200, 200)
|
|
||||||
BLACK = (0, 0, 0)
|
|
||||||
BROWN = (139, 69, 19)
|
|
||||||
|
|
||||||
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):
|
|
||||||
# Тело
|
|
||||||
w1 = width // 2
|
|
||||||
h1 = height // 2
|
|
||||||
y1 = y + h1 // 2
|
|
||||||
ellipse(surface, color, (x - w1 // 2, y1 - h1 // 2, w1, h1))
|
|
||||||
|
|
||||||
# Голова
|
|
||||||
s2 = height // 4
|
|
||||||
y2 = y - s2 // 2
|
|
||||||
circle(surface, color, (x, y2), s2 // 2)
|
|
||||||
|
|
||||||
# левое ухо
|
|
||||||
eh = height // 3
|
|
||||||
ey = y - height // 2 + eh // 2
|
|
||||||
ew = width // 8
|
|
||||||
ellipse(surface, color, (x - s2 // 4 - ew // 2, ey - eh // 2, ew, eh))
|
|
||||||
# правое ухо
|
|
||||||
ellipse(surface, color, (x + s2 // 4 - ew // 2, ey - eh // 2, ew, eh))
|
|
||||||
|
|
||||||
# Ноги - СТРАННЫЕ ПЕРЕМЕННЫЕ
|
|
||||||
lh = height // 16
|
|
||||||
ly = y + height // 2 - lh // 2
|
|
||||||
lw = width // 4
|
|
||||||
# левая нога
|
|
||||||
ellipse(surface, color, (x - width // 4 - lw // 2, ly - lh // 2, lw, lh))
|
|
||||||
# правая нога
|
|
||||||
ellipse(surface, color, (x + width // 4 - lw // 2, ly - lh // 2, lw, lh))
|
|
||||||
|
|
||||||
# НИ НА ЧТО НЕ ВЛИЯЮЩИЙ КОД
|
|
||||||
temp = 0
|
|
||||||
for i in range(5):
|
|
||||||
temp += i
|
|
||||||
|
|
||||||
# Рисуем зайца
|
|
||||||
draw_hare(screen, 200, 200, 200, 300, GRAY)
|
|
||||||
|
|
||||||
# Глаза и нос - НАХОДЯТСЯ ВНЕ ФУНКЦИИ
|
|
||||||
circle(screen, BLACK, (170, 150), 5) # левый глаз
|
|
||||||
circle(screen, BLACK, (230, 150), 5) # правый глаз
|
|
||||||
circle(screen, BLACK, (200, 170), 3) # носик
|
|
||||||
|
|
||||||
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()
|
|
||||||
70
task1.py
70
task1.py
@@ -1,49 +1,67 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from pygame.draw import*
|
from pygame.draw import *
|
||||||
|
|
||||||
pygame.init()
|
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( 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
|
|
||||||
draw_head(surface, x, y-head_size // 2, head_size, color)
|
|
||||||
|
|
||||||
ear_height = height // 3
|
Параметры:
|
||||||
ear_y = y - height // 2 + ear_height // 2
|
surface: поверхность для рисования
|
||||||
for ear_x in (x-head_size // 4, x + head_size // 4):
|
center_x, center_y: координаты центра изображения
|
||||||
draw_ear (surface, ear_x, ear_y, width // 8, ear_height, color)
|
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)
|
||||||
|
|
||||||
leg_height = height // 16
|
# Голова
|
||||||
leg_y =y + height // 2 - leg_height // 2
|
head_size = total_height // 4
|
||||||
for leg_x in (x - width // 4, x + width // 4):
|
head_y = center_y - head_size // 2
|
||||||
draw_leg(surface, leg_x, leg_y, width // 4, leg_height, color)
|
draw_head(surface, center_x, head_y, head_size, color)
|
||||||
|
|
||||||
|
# Уши
|
||||||
|
ear_height = total_height // 3
|
||||||
|
ear_y = center_y - total_height // 2 + ear_height // 2
|
||||||
|
ear_width = total_width // 8
|
||||||
|
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()
|
||||||
@@ -56,4 +74,4 @@ while not finished:
|
|||||||
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