import pygame
import sys
# здесь определяются константы,
# классы и функции
WIN_WIDTH = 600
WIN_HEIGHT = 600
WHITE = 255, 255, 255
BLACK = 0, 0, 0
PINK = 255, 0, 255
AQUA = 0, 255, 255
RED = 255, 0, 0
FPS = 1
class ChangeColor():
color_to_change = 1
def __init__(self, surface, first_fourth, second_fourth, color_to_change):
self.first_fourth = first_fourth
self.second_fourth = second_fourth
self.color_to_change = color_to_change
self.surface = surface
def change(self):
if self.color_to_change % 2 == 0:
self.surface.fill(AQUA)
screen.blit(self.surface, self.first_fourth)
screen.blit(self.surface, self.second_fourth)
self.color_to_change += 1
else:
self.surface.fill(RED)
screen.blit(self.surface, self.first_fourth)
screen.blit(self.surface, self.second_fourth)
self.color_to_change += 1
# Создание ректов для каждый четверти
fourth_1 = pygame.Rect((WIN_WIDTH // 2, 0), (WIN_WIDTH // 2, WIN_HEIGHT // 2))
fourth_2 = pygame.Rect((0, 0), (WIN_WIDTH // 2, WIN_HEIGHT // 2))
fourth_3 = pygame.Rect((0, WIN_HEIGHT // 2), (WIN_WIDTH // 2, WIN_HEIGHT // 2))
fourth_4 = pygame.Rect((WIN_WIDTH // 2, WIN_HEIGHT // 2), (WIN_WIDTH // 2, WIN_HEIGHT // 2))
# здесь происходит инициация,
# создание объектов
pygame.init()
screen = pygame.display.set_mode((600, 600))
screen.fill(WHITE)
clock = pygame.time.Clock()
surf_fourth = pygame.Surface((fourth_1.width, fourth_1.height))
# Создание экземпляра класса ChangeColor
first_two_quarters = ChangeColor(surf_fourth, fourth_1, fourth_3, 1)
second_two_quarters = ChangeColor(surf_fourth, fourth_2, fourth_4, 2)
# если надо до цикла отобразить
# какие-то объекты, обновляем экран
pygame.display.update()
active_first_fourth = False
active_second_fourth = False
# главный цикл
while True:
# задержка
clock.tick(FPS)
# цикл обработки событий
for i in pygame.event.get():
if i.type == pygame.QUIT:
sys.exit()
if i.type == pygame.KEYDOWN:
if i.key == pygame.K_1:
active_first_fourth = True
active_second_fourth = False
if i.key == pygame.K_2:
active_first_fourth = False
active_second_fourth = True
if i.key == pygame.K_0:
active_first_fourth = True
active_second_fourth = True
if active_first_fourth:
first_two_quarters.change()
if active_second_fourth:
second_two_quarters.change()
# --------
# изменение объектов
# --------
# обновление экрана
pygame.display.update()
if i.type == pygame.KEYDOWN:
if i.key == pygame.K_1:
screen.fill(WHITE)
active_first_fourth = True
active_second_fourth = False
if i.key == pygame.K_2:
screen.fill(WHITE)
active_first_fourth = False
active_second_fourth = True
if i.key == pygame.K_0:
screen.fill(WHITE)
active_first_fourth = True
active_second_fourth = True
import pygame
import sys
# здесь определяются константы,
# классы и функции
WIN_WIDTH = 600
WIN_HEIGHT = 600
WHITE = 255, 255, 255
BLACK = 0, 0, 0
PINK = 255, 0, 255
AQUA = 0, 255, 255
RED = 255, 0, 0
FPS = 1
class ChangeColor():
color_to_change = 1
def __init__(self, surface, first_fourth, second_fourth, color_to_change):
self.first_fourth = first_fourth
self.second_fourth = second_fourth
self.color_to_change = color_to_change
self.surface = surface
def change(self):
if self.color_to_change % 2 == 0:
self.surface.fill(AQUA)
screen.blit(self.surface, self.first_fourth)
screen.blit(self.surface, self.second_fourth)
self.color_to_change += 1
else:
self.surface.fill(RED)
screen.blit(self.surface, self.first_fourth)
screen.blit(self.surface, self.second_fourth)
self.color_to_change += 1
# Создание ректов для каждый четверти
fourth_1 = pygame.Rect((WIN_WIDTH // 2, 0), (WIN_WIDTH // 2, WIN_HEIGHT // 2))
fourth_2 = pygame.Rect((0, 0), (WIN_WIDTH // 2, WIN_HEIGHT // 2))
fourth_3 = pygame.Rect((0, WIN_HEIGHT // 2), (WIN_WIDTH // 2, WIN_HEIGHT // 2))
fourth_4 = pygame.Rect((WIN_WIDTH // 2, WIN_HEIGHT // 2), (WIN_WIDTH // 2, WIN_HEIGHT // 2))
# здесь происходит инициация,
# создание объектов
pygame.init()
screen = pygame.display.set_mode((600, 600))
screen.fill(WHITE)
clock = pygame.time.Clock()
surf_fourth = pygame.Surface((fourth_1.width, fourth_1.height))
# Создание экземпляра класса ChangeColor
first_two_quarters = ChangeColor(surf_fourth, fourth_1, fourth_3, 1)
second_two_quarters = ChangeColor(surf_fourth, fourth_2, fourth_4, 2)
# если надо до цикла отобразить
# какие-то объекты, обновляем экран
pygame.display.update()
active_first_fourth = False
active_second_fourth = False
# главный цикл
while True:
# задержка
clock.tick(FPS)
# цикл обработки событий
for i in pygame.event.get():
if i.type == pygame.QUIT:
sys.exit()
if i.type == pygame.KEYDOWN:
if i.key == pygame.K_1:
screen.fill(WHITE)
active_first_fourth = True
active_second_fourth = False
if i.key == pygame.K_2:
screen.fill(WHITE)
active_first_fourth = False
active_second_fourth = True
if i.key == pygame.K_0:
screen.fill(WHITE)
active_first_fourth = True
active_second_fourth = True
if active_first_fourth:
first_two_quarters.change()
if active_second_fourth:
second_two_quarters.change()
# --------
# изменение объектов
# --------
# обновление экрана
pygame.display.update()