Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import math
- WIN_WIDTH = 1240 # Ширина экрана
- WIN_HEIGHT = 960 # Высота экрана
- WIN_SIZE = [WIN_WIDTH, WIN_HEIGHT] # Размеры экрана
- FPS = 30 # Frame Per Second(Кадров в секунду)
- center = (WIN_WIDTH // 2, WIN_HEIGHT // 2)
- # Цвета в шестнадцаричной системе счисления
- WHITE = (0xff, 0xff, 0xff)
- BLACK = (0x00, 0x00, 0x00)
- RED = (0xff, 0x00, 0x00)
- GREEN = (0x00, 0xff, 0x00)
- BLUE = (0x00, 0x00, 0xff)
- GREY = (0xcc, 0xcc, 0xcc)
- DARK_GREY = (0x33, 0x33, 0x33)
- DARK_GREY_2 = (0x22, 0x22, 0x22)
- DARK_BLUE = (0x3e, 0x42, 0x43)
- LIGHT_GREY = (0x2b, 0x2c, 0x2d)
- WHITE_GREY = (0xd7, 0xd7, 0xd7)
- # Инициализация игрового движка
- pygame.init()
- # Создание окна
- screen = pygame.display.set_mode(WIN_SIZE)
- # Установка заголовка окна
- pygame.display.set_caption("My game")
- # Используется для контроля fps
- clock = pygame.time.Clock()
- # Шрифт
- font = pygame.font.Font("freesansbold.ttf", 12)
- # Настройки
- radius = 221
- alpha = math.pi / 2
- # Ремень
- strap_w = 230
- strap_h = 700
- # Крепление ремня
- belt_face = 5
- belt_mount_w = 280
- belt_mount_h = 500
- belt_mount_w_2 = belt_mount_w - 2
- belt_mount_h_2 = belt_mount_h - 2
- belt_mount_w_3 = belt_mount_w - 40
- belt_mount_h_3 = belt_mount_h - 64
- # Завод
- charge_w = 15
- charge_h = 40
- charge_face = 5
- charge_w += radius
- # Рамка
- frame_margin = 30
- frame_face = 50
- frame_line_w = 2
- frame_color = BLACK
- gameExit = False
- #**************** Основной цикл игры ************************
- while not gameExit:
- # Обработка событий
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- gameExit = True
- # -----------------
- # Игровая логика
- x1 = int(-1 * radius * math.cos(alpha) * 0.8) + center[0]
- y1 = int(-1 * radius * math.sin(alpha) * 0.8) + center[1]
- x2 = int(-1 * radius * math.cos(alpha * 0.1) * 0.5) + center[0]
- y2 = int(-1 * radius * math.sin(alpha * 0.1) * 0.5) + center[1]
- alpha += 0.01 * math.pi
- if alpha == 2 * math.pi:
- alpha = 0
- # -----------------
- # Рисование
- screen.fill(WHITE) # Залить экран
- # Рамка
- '''pygame.draw.arc(screen, BLACK,
- (frame_margin, frame_margin, frame_face*2, frame_face*2),
- math.pi/2, math.pi, frame_line_w)
- pygame.draw.arc(screen, BLACK,
- (WIN_WIDTH - frame_margin - 2*frame_face, frame_margin, frame_face*2, frame_face*2),
- 0, math.pi/2, frame_line_w)
- pygame.draw.arc(screen, BLACK,
- (frame_margin, WIN_HEIGHT - frame_margin - frame_face*2, frame_face*2, frame_face*2),
- math.pi, 3*math.pi/2, frame_line_w)
- pygame.draw.arc(screen, BLACK,
- (WIN_WIDTH - frame_margin - 2*frame_face, WIN_HEIGHT - frame_margin - frame_face*2,
- frame_face*2, frame_face*2),
- 3*math.pi/2, 0, frame_line_w)'''
- pygame.draw.circle(screen, frame_color,
- (frame_margin + frame_face, frame_margin + frame_face),
- frame_face, frame_line_w)
- pygame.draw.circle(screen, frame_color,
- (WIN_WIDTH - frame_margin - frame_face, frame_margin + frame_face),
- frame_face, frame_line_w)
- pygame.draw.circle(screen, frame_color,
- (frame_margin + frame_face, WIN_HEIGHT - frame_margin - frame_face),
- frame_face, frame_line_w)
- pygame.draw.circle(screen, frame_color,
- (WIN_WIDTH - frame_margin - frame_face, WIN_HEIGHT - frame_margin - frame_face),
- frame_face, frame_line_w)
- pygame.draw.rect(screen, WHITE,
- (frame_margin + frame_face, frame_margin,
- WIN_WIDTH - 2*frame_margin - 2*frame_face, WIN_HEIGHT - 2*frame_margin))
- pygame.draw.rect(screen, WHITE,
- (frame_margin, frame_margin + frame_face,
- WIN_WIDTH - 2*frame_margin, WIN_HEIGHT - 2*frame_margin - 2*frame_face))
- pygame.draw.line(screen, frame_color,
- (frame_margin + frame_face, frame_margin),
- (WIN_WIDTH - frame_margin - frame_face, frame_margin), frame_line_w)
- pygame.draw.line(screen, frame_color,
- (frame_margin, frame_margin + frame_face),
- (frame_margin, WIN_HEIGHT - frame_margin - frame_face), frame_line_w)
- pygame.draw.line(screen, frame_color,
- (frame_margin + frame_face, WIN_HEIGHT - frame_margin),
- (WIN_WIDTH - frame_margin - frame_face, WIN_HEIGHT - frame_margin), frame_line_w)
- pygame.draw.line(screen, frame_color,
- (WIN_WIDTH - frame_margin, frame_margin + frame_face),
- (WIN_WIDTH - frame_margin, WIN_HEIGHT - frame_margin - frame_face), frame_line_w)
- # Ремень
- pygame.draw.rect(screen, DARK_GREY_2,
- (center[0] - strap_w // 2, center[1] - strap_h // 2, strap_w, strap_h))
- # Крепление ремня
- pygame.draw.circle(screen, BLACK,
- (center[0] - belt_mount_w//2 + belt_face, center[1] - belt_mount_h//2 + belt_face),
- belt_face)
- pygame.draw.circle(screen, BLACK,
- (center[0] + belt_mount_w//2 - belt_face, center[1] - belt_mount_h//2 + belt_face),
- belt_face)
- pygame.draw.circle(screen, BLACK,
- (center[0] - belt_mount_w//2 + belt_face, center[1] + belt_mount_h//2 - belt_face),
- belt_face)
- pygame.draw.circle(screen, BLACK,
- (center[0] + belt_mount_w//2 - belt_face, center[1] + belt_mount_h//2 - belt_face),
- belt_face)
- pygame.draw.rect(screen, BLACK,
- (center[0] - belt_mount_w//2, center[1] - belt_mount_h//2 + belt_face,
- belt_mount_w, belt_mount_h - 2 * belt_face))
- pygame.draw.rect(screen, BLACK,
- (center[0] - belt_mount_w//2 + belt_face, center[1] - belt_mount_h//2,
- belt_mount_w - 2 * belt_face, belt_mount_h))
- pygame.draw.circle(screen, DARK_GREY,
- (center[0] - belt_mount_w_2//2 + belt_face, center[1] - belt_mount_h_2//2 + belt_face),
- belt_face)
- pygame.draw.circle(screen, DARK_GREY,
- (center[0] + belt_mount_w_2//2 - belt_face, center[1] - belt_mount_h_2//2 + belt_face),
- belt_face)
- pygame.draw.circle(screen, DARK_GREY,
- (center[0] - belt_mount_w_2//2 + belt_face, center[1] + belt_mount_h_2//2 - belt_face),
- belt_face)
- pygame.draw.circle(screen, DARK_GREY,
- (center[0] + belt_mount_w_2//2 - belt_face, center[1] + belt_mount_h_2//2 - belt_face),
- belt_face)
- pygame.draw.rect(screen, DARK_GREY,
- (center[0] - belt_mount_w_2//2, center[1] - belt_mount_h_2//2 + belt_face,
- belt_mount_w_2, belt_mount_h_2 - 2 * belt_face))
- pygame.draw.rect(screen, DARK_GREY,
- (center[0] - belt_mount_w_2//2 + belt_face, center[1] - belt_mount_h_2//2,
- belt_mount_w_2 - 2 * belt_face, belt_mount_h_2))
- pygame.draw.circle(screen, WHITE,
- (center[0] - belt_mount_w_3//2 + belt_face, center[1] - belt_mount_h_3//2 + belt_face),
- belt_face)
- pygame.draw.circle(screen, WHITE,
- (center[0] + belt_mount_w_3//2 - belt_face, center[1] - belt_mount_h_3//2 + belt_face),
- belt_face)
- pygame.draw.circle(screen, WHITE,
- (center[0] - belt_mount_w_3//2 + belt_face, center[1] + belt_mount_h_3//2 - belt_face),
- belt_face)
- pygame.draw.circle(screen, WHITE,
- (center[0] + belt_mount_w_3//2 - belt_face, center[1] + belt_mount_h_3//2 - belt_face),
- belt_face)
- pygame.draw.rect(screen, WHITE,
- (center[0] - belt_mount_w_3//2, center[1] - belt_mount_h_3//2 + belt_face,
- belt_mount_w_3, belt_mount_h_3 - 2 * belt_face))
- pygame.draw.rect(screen, WHITE,
- (center[0] - belt_mount_w_3//2 + belt_face, center[1] - belt_mount_h_3//2,
- belt_mount_w_3 - 2 * belt_face, belt_mount_h_3))
- # Завод
- pygame.draw.circle(screen, DARK_GREY,
- (center[0] + charge_w - charge_face, center[1] - charge_h//2 + charge_face),
- charge_face)
- pygame.draw.circle(screen, DARK_GREY,
- (center[0] + charge_w - charge_face, center[1] + charge_h//2 - charge_face),
- charge_face)
- pygame.draw.rect(screen, DARK_GREY,
- (center[0], center[1] - charge_h//2, charge_w - charge_face, charge_h))
- pygame.draw.rect(screen, DARK_GREY,
- (center[0], center[1] - charge_h//2 + charge_face,
- charge_w, charge_h - charge_face*2))
- # Обод часов
- pygame.draw.circle(screen, BLACK, center, radius)
- pygame.draw.circle(screen, DARK_GREY, center, radius - 1)
- pygame.draw.circle(screen, DARK_BLUE, center, radius - 16)
- pygame.draw.circle(screen, BLACK, center, radius - 21)
- pygame.draw.circle(screen, LIGHT_GREY, center, radius - 23)
- # Засечки
- for i in range(60):
- angle = i * math.pi / 30
- x = int((radius - 24) * math.cos(angle)) + center[0]
- y = int((radius - 24) * math.sin(angle)) + center[1]
- pygame.draw.line(screen, DARK_BLUE, center, (x, y), 1)
- pygame.draw.circle(screen, LIGHT_GREY, center, radius - 35)
- for i in range(12):
- angle = i * math.pi / 6
- x = int((radius - 40) * math.cos(angle)) + center[0]
- y = int((radius - 40) * math.sin(angle)) + center[1]
- pygame.draw.line(screen, WHITE_GREY, center, (x, y), 3)
- pygame.draw.circle(screen, LIGHT_GREY, center, radius - 80)
- # Надпись
- text = font.render("TISSOT", True, RED)
- screen.blit(text, [center[0] - text.get_width()//2, center[1] + 100])
- # Стрелки
- pygame.draw.circle(screen, WHITE_GREY, center, 5)
- pygame.draw.line(screen, WHITE_GREY, center, (x1, y1), 2)
- pygame.draw.line(screen, WHITE_GREY, center, (x2, y2), 4)
- pygame.display.flip() # Обновить экран, выведя то, что в буфере
- # -----------------
- # Ограничение fps
- clock.tick(FPS)
- # "Правильное" завершение программы в pygame
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement