目标是在屏幕上制作具有随机绿色阴影的正方形,但 iy 轴不想改变
import pygame
from random import randint
#activate pygame
pygame.init()
#screen (x,y)
screen = pygame.display.set_mode([500, 500])
#bool - if game is running
running = True
tablica = [[randint(1,255) for i in range(10)] for i in range(10)]
print(tablica)
#while game is running
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
#fill screen with (r,g,b)
screen.fill((255,255,255))
x = 0
for i, e in enumerate(tablica):
for j in e:
pygame.draw.rect(screen,(j,j,0),(x,50*i,50,50))
x += 50
#update screen
pygame.display.flip()
#turn off game
pygame.quit()
但不是在屏幕上绘制 100 个正方形,而是在同一个 x 轴上只画 10 个。提前致谢!