что не так с моим приложением pygame?

Я хотел создать приложение pygame, которое будет делать каждый пиксель на экране 500,500 случайным цветом, но при этом окрашивает только верхнюю строку.

here is the code:

import pygame,sys, random, time
y = 0
x = 0 
true = True
pygame.init()
screen = pygame.display.set_mode((500,500))
screen.fill((255,255,255))
while true:
    r = random.randint(0,255)
    g = random.randint(0,255)
    b = random.randint(0,255)
    print x
    pygame.draw.line(screen, (r,g,b),(x,y),(x,y))
    if x >= 500:
        x == 0
        y += 1
    x += 1
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit(); sys.exit();

person Jacob Forsyth    schedule 08.09.2013    source источник


Ответы (2)


Вероятно, вам следует заменить:

    # This checks if x == 0. It obviously isn't but it has no real effect
    x == 0

с участием

    # This will assign 0 to x variable if x >= 500
    x = 0
person zero323    schedule 08.09.2013

from pygame.locals import *

def random_colors(surf):
    for x in range(500):
        for y in range(500):
            c = Color(random.randint(0,255), random.randint(0,255), random.randint(0,255))
            surf.set_at((x,y), c)

Обратите внимание: если вы планируете использовать частый доступ к пикселям, используйте PixelArray или surfarray

person ninMonkey    schedule 08.09.2013