我刚刚从它的网站(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位、windows7马力的笔记本电脑。正在讨论的程序试图可视化“Langton的蚂蚁”,并如下所示:
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)发布于 2014-04-13 11:29:12
您正在尝试创建一个太大的显示:
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)这样的东西。
如果你需要一个更大的世界,你可以尝试创建一个更大的表面(而不是显示),然后只显示你需要的内容。
https://stackoverflow.com/questions/23038449
复制相似问题