import pygame, random # how many horizontal cells? NUM_CELLS=64 # open the graphics window screen = pygame.display.set_mode((640, 480)) for x in range(0, NUM_CELLS): if random.randrange(2) == 1: # if coin-flip gives a 1, set color to green color = (0, 255, 0) else: # otherwise to black color = (0, 0, 0) # draw a 9x9 pixel rectable, with the top left corner at (x*10,0) # (notice, unlike turtle graphics, (0, 0) is the *top left* of the window pygame.draw.rect(screen, color, (x*10, 0, 9, 9)) # actually show the graphics we've been plotting pygame.display.flip() raw_input("--- Press enter to quit ---") # close the window pygame.display.quit()