Pygame错误:无法创建DIB部分

时间:2014-04-13 02:28:47

标签: python pygame dib

我刚从其网站(http://pygame.org/download.shtml)的下载页面下载了pygame(python模块),我选择了名为“pygame-1.9.1.win32-py2.7.msi”的软件包。当我尝试执行程序时出现此错误:

Traceback (most recent call last):
  File "C:\Users\kkkkllkk53\The Mish Mash Files\langtons ant.py", line 16, in <module>
    windowSurface = pygame.display.set_mode((window_length, window_length), 0, 32)
error: Couldn't create DIB section

我不知道这意味着什么。有人可以帮帮我吗?

我使用的是64位Windows 7 hp笔记本电脑。有问题的程序试图将“Langton's Ant”可视化,并且如下所示:

import pygame, sys

black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)

colour_code = { True: red, False: white }

pygame.init()
mainClock = pygame.time.Clock()

cell_length = 10
num_cells_per_side = 10000

window_length = cell_length * num_cells_per_side
windowSurface = pygame.display.set_mode((window_length, window_length), 0, 32)
pygame.display.set_caption('Langtons ant')
windowSurface.fill(white)

def cell_2_rect(x, y):
    rect_x = ( 5000 + x ) * cell_length
    rect_y = ( 5000 + y ) * cell_length
    return pygame.Rect( rect_x, rect_y )

ant_x = 0
ant_y = 0
ant_angle = 1

angles = { 0: [1, 0], 1: [0, -1], 2: [-1, 0], 3: [0, 1] }

row = [ False ] * num_cells_per_side
matrix = [ row.copy() ] * num_cells_per_side

def turn_ant():
    turn = matrix[ant_y, ant_x]
    if turn:
        ant_angle += 1
    else:
        ant_angle -= 1
    ant_angle = ant_angle % 4

def move_ant():
    displacement = angles[ ant_angle ]
    delta_x = displacement[0]
    delta_y = displacement[1]
    ant_x += delta_x
    ant_y += delta_y

def update_square():
    cell = matrix[ant_x][ant_y]
    cell = not cell
    pygame.draw.rect( windowSurface, colour_code[cell], cell_2_rect(ant_x, ant_y) )

def show_ant():
    pygame.draw.rect( windowSurface, red, cell_2_rect(ant_x, ant_y) )

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    update_square()
    turn_ant()
    move_ant()
    show_ant()
    pygame.display.update()
    mainClock.tick(100)

1 个答案:

答案 0 :(得分:0)

您正试图创建一个太大的显示器:

cell_length = 10
num_cells_per_side = 10000

window_length = cell_length * num_cells_per_side
windowSurface = pygame.display.set_mode((window_length, window_length), 0, 32)

等于:(100000,100000)

尝试类似(800x600)的内容。

如果你需要一个更大的世界,你可以尝试创建一个更大的表面(不显示),然后只在你需要的屏幕上进行blitting。