昨天我问了一个关于这个项目的问题,但我遇到了另一个问题。 代码仍在运行,并认为它以像素为单位着色,但当到达页面底部时,它应该停止,而不是停止。你知道吗
代码如下:
import pygame,sys, random, time
y = 0
x = 0
keepgoing = True
pygame.init()
screen = pygame.display.set_mode((500,500))
pixel = raw_input('Please enter a NUMBER that goes into 500. ')
end = 500-(int(pixel))
int(pixel)
screen.fill((255,255,255))
while keepgoing:
print x,y
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
pygame.draw.rect(screen, (r,g,b),(x,y,int(pixel),int(pixel)))
if x >= end:
x = 0
y += int(pixel)
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
pygame.draw.rect(screen, (r,g,b),(x,y,int(pixel),int(pixel)))
if x == end and y == end:
print 'done'
keepgoing == False
break
x += (int(pixel))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit();
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit();
如果用python IDLE运行代码,您就会明白我的意思。你知道吗
为什么不直接使用
for
循环呢?你知道吗==
进行比较检查。你想要什么尝试更改:
收件人:
另外,更改:
收件人:
另外,考虑改变:
收件人:
注意:您可能应该使用嵌套for循环并在x像素和y像素之间循环。它可能比使用while循环更好。你知道吗
相关问题 更多 >
编程相关推荐