Добавлена лабораторная работа 2

This commit is contained in:
Vlad24
2026-03-04 14:14:16 +03:00
parent e50aaa443c
commit 98fc10133c
3 changed files with 359 additions and 0 deletions

47
lab2/task1.py Normal file
View File

@@ -0,0 +1,47 @@
import pygame
from pygame.draw import *
pygame.init()
FPS = 30
screen = pygame.display.set_mode((400, 400))
# ЦВЕТА
GRAY = (200, 200, 200) # Светло-серый фон
YELLOW = (255, 255, 0) # Жёлтое лицо
BLACK = (0, 0, 0) # Чёрный (контуры, рот, брови)
RED = (255, 0, 0) # Красные глаза
# ФОН
screen.fill(GRAY)
# === ЛИЦО ===
# Жёлтый круг
circle(screen, YELLOW, (200, 200), 100)
circle(screen, BLACK, (200, 200), 100, 3)
#ГЛАЗА
circle(screen, RED, (165, 170), 18) # Левый
circle(screen, RED, (235, 170), 18) # Правый
circle(screen, BLACK, (165, 170), 8) # Левый
circle(screen, BLACK, (235, 170), 8) # Правый
РОdb
line(screen, BLACK, (140, 145), (185, 165), 8)
line(screen, BLACK, (260, 145), (215, 165), 8)
rect(screen, BLACK, (150, 240, 100, 15))
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()

161
lab2/task2.py Normal file
View File

@@ -0,0 +1,161 @@
import pygame
# Инициализация
pygame.init()
# Размеры окна
WIDTH, HEIGHT = 800, 500
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Северный пейзаж (По образцу)")
# --- Цвета ---
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
SKY_GRAY = (220, 220, 220) # Небо
SNOW_WHITE = (255, 255, 255) # Снег
COAT_BROWN = (90, 70, 50) # Темно-коричневая шуба
STRIP_BROWN = (60, 40, 30) # Полоски
HOOD_COLOR = (245, 245, 245) # Капюшон
SKIN_COLOR = (230, 215, 200) # Лицо
CAT_GRAY = (150, 150, 150) # Серый кот
FISH_BLUE = (80, 100, 180)
FISH_RED = (200, 50, 50)
PI = 3.14
def draw_igloo(surface, x, y):
radius = 160
# 1. Основной купол (белый)
pygame.draw.circle(surface, WHITE, (x, y), radius)
# Срезаем низ прямоугольником снега
pygame.draw.rect(surface, SNOW_WHITE, (x - radius, y, radius * 2, radius))
# 2. Контур
rect = (x - radius, y - radius, radius * 2, radius * 2)
pygame.draw.arc(surface, BLACK, rect, 0, PI, 2)
# 3. Сетка линий
# Горизонтальные дуги
pygame.draw.arc(surface, BLACK, (x - radius + 30, y - radius + 50, (radius - 30)*2, (radius - 50)*2), 0, PI, 1)
pygame.draw.arc(surface, BLACK, (x - radius + 10, y - radius + 100, (radius - 10)*2, (radius - 100)*2), 0, PI, 1)
# Вертикальная линия по центру
pygame.draw.line(surface, BLACK, (x, y - radius), (x, y), 1)
# Боковые линии (дугами)
pygame.draw.arc(surface, BLACK, (x - 100, y - radius, 80, radius*2), PI/2, PI, 1)
pygame.draw.arc(surface, BLACK, (x, y - radius, 80, radius*2), 0, PI/2, 1)
def draw_chukcha(surface, x, y):
# x, y - координаты низа шубы
# 1. Палка (тонкая линия слева)
pygame.draw.line(surface, BLACK, (x - 70, y - 10), (x - 70, y - 150), 2)
# 2. Ноги (Вертикальные овалы ПОД телом)
# Сделаем их темными
pygame.draw.ellipse(surface, STRIP_BROWN, (x - 25, y, 20, 35)) # Левая
pygame.draw.ellipse(surface, STRIP_BROWN, (x + 5, y, 20, 35)) # Правая
# 3. Тело (Трапеция)
# Делаем тело чуть выше, чтобы голова поднялась
body_height = 70
body_points = [
(x - 30, y - body_height), # Плечи лево
(x + 30, y - body_height), # Плечи право
(x + 55, y), # Низ право
(x - 55, y) # Низ лево
]
pygame.draw.polygon(surface, COAT_BROWN, body_points)
# Полоски
pygame.draw.rect(surface, STRIP_BROWN, (x - 55, y - 10, 110, 10)) # Низ
pygame.draw.rect(surface, STRIP_BROWN, (x - 5, y - body_height, 10, body_height)) # Центр
# 4. Руки (Овалы по бокам)
pygame.draw.ellipse(surface, COAT_BROWN, (x - 75, y - 50, 40, 20)) # Левая
pygame.draw.ellipse(surface, COAT_BROWN, (x + 35, y - 50, 40, 20)) # Правая
# 5. Голова
# Центр головы выше плеч
head_y = y - body_height - 15
# Капюшон (белый круг)
pygame.draw.circle(surface, HOOD_COLOR, (x, head_y), 38)
# Лицо (бежевое)
pygame.draw.circle(surface, SKIN_COLOR, (x, head_y), 24)
# ЛИЦО
# Глаза (прищуренные палочки \ /), ПОДНЯТЫ ВЫШЕ
eye_y = head_y - 5
pygame.draw.line(surface, BLACK, (x - 20, eye_y - 3), (x - 4, eye_y + 3), 2)
pygame.draw.line(surface, BLACK, (x + 4, eye_y + 3), (x + 20, eye_y - 3), 2)
# Рот (дуга вниз), ОПУЩЕН НИЖЕ (чтобы не касался глаз)
mouth_y = head_y + 10
pygame.draw.arc(surface, BLACK, (x - 8, mouth_y, 23, 16), 0, PI, 3)
def draw_cat(surface, x, y):
# Координаты x, y - центр тела
# Хвост (толстый, справа)
pygame.draw.ellipse(surface, CAT_GRAY, (x + 40, y - 5, 60, 20))
# Лапки (СНИЗУ, вертикальные маленькие овалы)
# Задние
pygame.draw.ellipse(surface, CAT_GRAY, (x + 20, y + 15, 12, 30))
pygame.draw.ellipse(surface, CAT_GRAY, (x + 35, y + 15, 12, 30))
# Передние
pygame.draw.ellipse(surface, CAT_GRAY, (x - 10, y + 15, 12, 30))
pygame.draw.ellipse(surface, CAT_GRAY, (x - 25, y + 15, 12, 30))
# Туловище (Овал)
pygame.draw.ellipse(surface, CAT_GRAY, (x - 30, y - 10, 90, 40))
# Голова (Круг слева)
pygame.draw.circle(surface, CAT_GRAY, (x - 35, y + 5), 22)
# Уши
pygame.draw.polygon(surface, CAT_GRAY, [(x - 45, y - 10), (x - 50, y - 20), (x - 35, y - 15)])
pygame.draw.polygon(surface, CAT_GRAY, [(x - 25, y - 15), (x - 20, y - 20), (x - 15, y - 10)])
# Глаза (Белые круги + точки)
pygame.draw.circle(surface, WHITE, (x - 42, y + 2), 5)
pygame.draw.circle(surface, BLACK, (x - 42, y + 2), 2)
pygame.draw.circle(surface, WHITE, (x - 28, y + 2), 5)
pygame.draw.circle(surface, BLACK, (x - 28, y + 2), 2)
# Рыба
fx, fy = x - 55, y + 15
pygame.draw.ellipse(surface, FISH_BLUE, (fx, fy, 30, 12))
pygame.draw.polygon(surface, FISH_RED, [(fx, fy + 6), (fx - 8, fy), (fx - 8, fy + 12)])
# --- Запуск ---
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Фон (горизонт посередине иглу)
horizon = 220
pygame.draw.rect(screen, SKY_GRAY, (0, 0, WIDTH, horizon))
pygame.draw.rect(screen, SNOW_WHITE, (0, horizon, WIDTH, HEIGHT - horizon))
# Иглу
draw_igloo(screen, 320, horizon)
# Чукча (справа, висит в воздухе чуть выше низа экрана, как на рисунке)
draw_chukcha(screen, 650, 350)
# Кот (слева внизу)
draw_cat(screen, 180, 400)
pygame.display.flip()
clock.tick(60)
pygame.quit()

151
lab2/task3.py Normal file
View File

@@ -0,0 +1,151 @@
import pygame
pygame.init()
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
SKY_GRAY = (225, 225, 225)
SNOW_WHITE = (253, 253, 253)
COAT_BROWN = (100, 80, 60)
STRIP_BROWN = (70, 50, 40)
HOOD_COLOR = (240, 240, 240)
SKIN_COLOR = (230, 215, 200)
CAT_GRAY = (170, 170, 170)
FISH_BLUE = (80, 110, 190)
FISH_RED = (200, 60, 60)
PI = 3.14
def draw_igloo(surface, x, y, scale=1.0):
s = scale
radius = int(150 * s)
pygame.draw.circle(surface, WHITE, (x, y), radius)
pygame.draw.rect(surface, SNOW_WHITE, (x - radius, y, radius * 2, radius))
rect = (x - radius, y - radius, radius * 2, radius * 2)
width = max(1, int(2 * s)) # Толщина линии зависит от масштаба
pygame.draw.arc(surface, BLACK, rect, 0, PI, width)
pygame.draw.arc(surface, BLACK,
(x - radius + 20 * s, y - radius + 40 * s, (radius - 20 * s) * 2, (radius - 40 * s) * 2), 0, PI, 1)
pygame.draw.arc(surface, BLACK,
(x - radius + 5 * s, y - radius + 90 * s, (radius - 5 * s) * 2, (radius - 90 * s) * 2), 0, PI, 1)
pygame.draw.line(surface, BLACK, (x, y - radius), (x, y), 1)
pygame.draw.arc(surface, BLACK, (x - 70 * s, y - radius, 70 * s, radius * 2), PI / 2, PI, 1)
pygame.draw.arc(surface, BLACK, (x, y - radius, 70 * s, radius * 2), 0, PI / 2, 1)
def draw_chukcha(surface, x, y, scale=1.0):
s = scale
pygame.draw.line(surface, BLACK, (x - 65 * s, y - 10 * s), (x - 65 * s, y - 140 * s), max(1, int(2 * s)))
pygame.draw.ellipse(surface, STRIP_BROWN, (x - 25 * s, y, 20 * s, 30 * s))
pygame.draw.ellipse(surface, STRIP_BROWN, (x + 5 * s, y, 20 * s, 30 * s))
body_h = 65 * s
body_points = [
(x - 30 * s, y - body_h),
(x + 30 * s, y - body_h),
(x + 55 * s, y),
(x - 55 * s, y)
]
pygame.draw.polygon(surface, COAT_BROWN, body_points)
pygame.draw.rect(surface, STRIP_BROWN, (x - 55 * s, y - 8 * s, 110 * s, 8 * s))
pygame.draw.rect(surface, STRIP_BROWN, (x - 5 * s, y - body_h, 10 * s, body_h))
pygame.draw.ellipse(surface, COAT_BROWN, (x - 70 * s, y - 45 * s, 40 * s, 18 * s))
pygame.draw.ellipse(surface, COAT_BROWN, (x + 30 * s, y - 45 * s, 40 * s, 18 * s))
head_y = y - body_h - 15 * s
pygame.draw.circle(surface, HOOD_COLOR, (x, head_y), 35 * s)
pygame.draw.circle(surface, SKIN_COLOR, (x, head_y), 24 * s)
eye_y = head_y - 4 * s
pygame.draw.line(surface, BLACK, (x - 10 * s, eye_y - 2 * s), (x - 4 * s, eye_y + 2 * s), max(1, int(2 * s)))
pygame.draw.line(surface, BLACK, (x + 4 * s, eye_y + 2 * s), (x + 10 * s, eye_y - 2 * s), max(1, int(2 * s)))
mouth_y = head_y + 6 * s
pygame.draw.arc(surface, BLACK, (x - 7 * s, mouth_y, 20 * s, 8 * s), 0, PI, max(1, int(2 * s)))
def draw_cat(surface, x, y):
s = 1.0
pygame.draw.ellipse(surface, CAT_GRAY, (x + 40 * s, y - 5 * s, 90 * s, 18 * s))
pygame.draw.ellipse(surface, CAT_GRAY, (x + 20 * s, y + 8 * s, 14 * s, 35 * s))
pygame.draw.ellipse(surface, CAT_GRAY, (x + 40 * s, y + 8 * s, 14 * s, 35 * s))
pygame.draw.ellipse(surface, CAT_GRAY, (x - 15 * s, y + 8 * s, 14 * s, 35 * s))
pygame.draw.ellipse(surface, CAT_GRAY, (x - 35 * s, y + 8 * s, 14 * s, 35 * s))
pygame.draw.ellipse(surface, CAT_GRAY, (x - 40 * s, y - 12 * s, 110 * s, 35 * s))
pygame.draw.circle(surface, CAT_GRAY, (x - 45 * s, y + 2 * s), 22 * s)
pygame.draw.polygon(surface, CAT_GRAY,
[(x - 55 * s, y - 12 * s), (x - 60 * s, y - 25 * s), (x - 45 * s, y - 18 * s)])
pygame.draw.polygon(surface, CAT_GRAY,
[(x - 35 * s, y - 18 * s), (x - 30 * s, y - 25 * s), (x - 25 * s, y - 12 * s)])
pygame.draw.circle(surface, WHITE, (x - 52 * s, y), 5 * s)
pygame.draw.circle(surface, BLACK, (x - 52 * s, y), 2 * s)
pygame.draw.circle(surface, WHITE, (x - 38 * s, y), 5 * s)
pygame.draw.circle(surface, BLACK, (x - 38 * s, y), 2 * s)
fx, fy = x - 65 * s, y + 12 * s
pygame.draw.ellipse(surface, FISH_BLUE, (fx, fy, 30 * s, 12 * s))
pygame.draw.polygon(surface, FISH_RED, [(fx, fy + 6 * s), (fx - 8 * s, fy), (fx - 8 * s, fy + 12 * s)])
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
horizon = 230
pygame.draw.rect(screen, SKY_GRAY, (0, 0, WIDTH, horizon))
pygame.draw.rect(screen, SNOW_WHITE, (0, horizon, WIDTH, HEIGHT - horizon))
draw_igloo(screen, 150, 290, scale=0.5)
draw_igloo(screen, 500, 290, scale=0.5)
draw_chukcha(screen, 600, 280, 0.35)
draw_chukcha(screen, 660, 270, 0.35)
draw_chukcha(screen, 720, 280, 0.35)
draw_chukcha(screen, 580, 330, 0.4)
draw_chukcha(screen, 640, 340, 0.4)
draw_chukcha(screen, 700, 330, 0.4)
draw_igloo(screen, 320, 330, scale=1.1)
draw_igloo(screen, 180, 380, scale=0.6)
draw_igloo(screen, 420, 380, scale=0.6)
draw_chukcha(screen, 720, 480, scale=1.2)
draw_cat(screen, 320, 430)
draw_cat(screen, 180, 520)
draw_cat(screen, 50, 460)
draw_cat(screen, 550, 550)
draw_cat(screen, 750, 560)
pygame.display.flip()
clock.tick(60)
pygame.quit()