【发布时间】:2021-12-07 20:27:10
【问题描述】:
目标是在屏幕上制作带有随机绿色阴影的正方形,但我的 y 轴不想改变
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 个。 提前致谢!
【问题讨论】: