Untitled
unknown
plain_text
2 years ago
2.1 kB
19
Indexable
import pygame
from random import randint
class Color:
WHITE = (255) * 3
BLACK = (0) * 3
@classmethod
def random(_) -> tuple[int, int, int]:
return randint(0, 255), randint(0, 255), randint(0, 255)
@classmethod
def invert(_, color: tuple[int, int, int]) -> tuple[int, int, int]:
return tuple([255-c for c in color])
SIZE = (500, 500)
def get_rect(label: pygame.Surface, x: float = 0.0) -> pygame.Rect:
return label.get_rect(center=(SIZE[0] / 2, SIZE[1] / 2 - SIZE[1] / 4 + x))
def change_screen() -> None:
color = Color.random()
inverted = Color.invert(color)
big = pygame.font.SysFont("Consolas", 180, bold=True)
normal = pygame.font.SysFont("Consolas", 36)
title = big.render("ЦВЕТ", False, inverted)
rgb_text = normal.render(f"Текст: rgb{inverted}", False, inverted)
rgb_background = normal.render(f"Фон: rgb{color}", False, color, inverted)
description_1 = normal.render("Остановить/запустить", False, inverted)
description_2 = normal.render("Клавиши S или ↓", False, inverted)
screen.fill(color)
screen.blit(title, get_rect(title))
screen.blit(rgb_text, get_rect(rgb_text, 120))
screen.blit(rgb_background, get_rect(rgb_background, 200))
screen.blit(description_1, get_rect(description_1, 280))
screen.blit(description_2, get_rect(description_2, 320))
pygame.init()
pygame.font.init()
screen, run, changing = pygame.display.set_mode(SIZE), True, True
clock, time = pygame.time.Clock(), 0
pygame.display.set_caption("Цвет.")
change_screen()
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
keys = pygame.key.get_pressed()
if keys[pygame.K_s] or keys[pygame.K_DOWN]:
changing = not changing
if time >= 50 and changing:
change_screen()
time = 0
time += 1
pygame.display.update()
clock.tick(60)
pygame.quit()
Editor is loading...
Leave a Comment