import pygame
import random
WIDTH = 500
HEIGHT = 500
FPS = 60
color = [(0, 255, 255), (0, 0, 0),(255, 0, 0),(0, 255, 0),(0, 0, 255)]
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
f1 = pygame.font.Font(None, 36)
running = True
clock = pygame.time.Clock()
x = []
for index in range(0,5):
x.append(WIDTH/2)
y = []
for index in range(0,5):
y.append(WIDTH/2)
while running:
clock.tick(10)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
for it_1 in range(0,500,50):
for it_2 in range(0,500,50):
pygame.draw.rect(screen,(255,255,255), (it_1,it_2,49,49))
for index in range(0,5):
pygame.draw.rect(screen,color[index], (x[index],y[index],49,49))
select = random.randint(0,3)
if (select == 0):
x[index] = x[index] - 50
if (select == 1):
x[index] = x[index] + 50
if (select == 2):
y[index] = y[index] - 50
if (select == 3):
y[index] = y[index] + 50
if (x[index]==0): x[index] = 250
if (x[index]>450): x[index] = 250
if (y[index]==0): y[index]= 250
if (y[index]>450): y[index] = 250
pygame.display.update()
pygame.quit()
|