У меня есть 3 разные функции, которые рисует, буквы, прямоугольники (желтый и красный) и обновление положения прямоугольника.
Мои функции
def DrawText():
Alphabet = list(string.ascii_uppercase + string.digits)
HorizontalIterator = 0
VerticalIterator = 0
for i in range(len(Alphabet)):
font = pygame.font.SysFont('Arial', 250, True, False)
font = pygame.font.Font(None, 225)
text = font.render(Alphabet[i], True, BLACK)
screen.blit(text, [20 + HorizontalIterator, 100 + VerticalIterator])
HorizontalIterator = HorizontalIterator + 190
if HorizontalIterator >= 1700:
HorizontalIterator = 0
VerticalIterator = VerticalIterator + 180
def Fill(Iterator):
RectangleHorizontal = pygame.Surface((140, 700), pygame.SRCALPHA, 32)
RectangleHorizontal.fill(((255, 255, 0, 150)))
screen.blit(RectangleHorizontal, (10 + Iterator, 95))
# Vertical Rectangle
RectangleVertical = pygame.Surface((1650, 140), pygame.SRCALPHA, 32)
RectangleVertical.fill(((255, 0, 0, 150)))
screen.blit(RectangleVertical, (10, 95))
return RectangleHorizontal, RectangleVertical
Эта 2 - моя основная функция при настройке дисплея
Этофункция обновляет новую позицию прямоугольников
def NewPositionOfRectangle(RectangleHorizontal, RectangleVertical, Iterator):
RectangleHorizontal = pygame.Surface((140, 700), pygame.SRCALPHA, 32)
RectangleHorizontal.fill(((255, 255, 0, 150)))
screen.blit(RectangleHorizontal, (10 + Iterator, 95))
# Vertical Rectangle
RectangleVertical = pygame.Surface((1650, 140), pygame.SRCALPHA, 32)
RectangleVertical.fill(((255, 0, 0, 150)))
screen.blit(RectangleVertical, (10, 635))
У меня есть цикл for, который каждый раз повторяет мои позиции прямоугольника.Тем не менее, всегда, когда я заставляю прямоугольники двигаться, я хочу показать каждый шаг.(Пример: от первого ряда ко второму ряду, от второго столбца до третьего столбца и т. Д.)
Проблема в том, что в моем цикле for я пробовал много вещей, но не смог этого сделать.Любое предложение для достижения этой цели?Я пытался, таймер, подождите, спать, показать обновление, может быть, я делаю что-то не так.
Вот мой цикл
for Iterator in range(0, 1530, 190):
NewPositionOfRectangle(LeftRightMove, UpdownMove, Iterator)
screen.fill(WHITE)
DrawText()
Fill(Iterator)
if Iterator == 1520:
Iterator = 0
Подводя итог, я хотел бы обновлять свои красные и желтые позиции прямоугольника каждую секунду.Например, желтый прямоугольник расположен на I, R 0 9, через секунду он перейдет к HQZ 8.
Если вы хотите увидеть все мои коды:
import pygame
import string
import sys
import time
import threading
Clock = pygame.time.Clock()
Iterator = 0
def DrawText():
Alphabet = list(string.ascii_uppercase + string.digits)
HorizontalIterator = 0
VerticalIterator = 0
for i in range(len(Alphabet)):
font = pygame.font.SysFont('Arial', 250, True, False)
font = pygame.font.Font(None, 225)
text = font.render(Alphabet[i], True, BLACK)
screen.blit(text, [20 + HorizontalIterator, 100 + VerticalIterator])
HorizontalIterator = HorizontalIterator + 190
if HorizontalIterator >= 1700:
HorizontalIterator = 0
VerticalIterator = VerticalIterator + 180
def Fill(Iterator):
RectangleHorizontal = pygame.Surface((140, 700), pygame.SRCALPHA, 32)
RectangleHorizontal.fill(((255, 255, 0, 150)))
screen.blit(RectangleHorizontal, (10 + Iterator, 95))
# Vertical Rectangle
RectangleVertical = pygame.Surface((1650, 140), pygame.SRCALPHA, 32)
RectangleVertical.fill(((255, 0, 0, 150)))
screen.blit(RectangleVertical, (10, 95))
return RectangleHorizontal, RectangleVertical
def NewPositionOfRectangle(RectangleHorizontal, RectangleVertical, Iterator):
RectangleHorizontal = pygame.Surface((140, 700), pygame.SRCALPHA, 32)
RectangleHorizontal.fill(((255, 255, 0, 150)))
screen.blit(RectangleHorizontal, (10 + Iterator, 95))
# Vertical Rectangle
RectangleVertical = pygame.Surface((1650, 140), pygame.SRCALPHA, 32)
RectangleVertical.fill(((255, 0, 0, 150)))
screen.blit(RectangleVertical, (10, 635))
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
DARKBLUE = (0, 0, 128)
pygame.init()
# Set the width and height of the screen [width, height]
size = (1700, 950)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Poligram")
# Loop until the user clicks the close button.
done = False
# Used to manage how fast the screen updates
# -------- Main Program Loop -----------
while not done:
# --- Main event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# --- Game logic should go here
# --- Screen-clearing code goes here
# Here, we clear the screen to white. Don't put other drawing commands
# above this, or they will be erased with this command.
# If you want a background image, replace this clear with blit'ing the
# background image.
screen.fill(WHITE)
# --- Drawing code should go here
LeftRightMove, UpdownMove = Fill(Iterator)
for Iterator in range(0, 1530, 190):
NewPositionOfRectangle(LeftRightMove, UpdownMove, Iterator)
screen.fill(WHITE)
DrawText()
Fill(Iterator)
if Iterator == 1520:
Iterator = 0
pygame.display.flip()
# --- Limit to 60 frames per second
# Close the window and quit.
pygame.quit()