我正在尝试创建一个 3d rubiks 立方体,但是尺寸与设置的尺寸不一致。当我将尺寸设置为 3 并创建一个 3x3x3 立方体时,我最终创建了一个 4x4x4 立方体。但是,当我将维度设置为 2 时,它会创建一个 3x3x3 多维数据集,而当维度设置为 1 时,会创建一个 1x1x1 多维数据集。有人可以帮忙吗?谢谢!
立方体代码:
#imports
dim = 3
cube = [[['#' for c in range(dim)] for c in range(dim)] for r in range(dim)]
for i in range(dim):
for j in range(dim):
for k in range(dim):
print(cube[i][j][k], end='')
print()
print()
for i in range(dim):
for j in range(dim):
for k in range(dim):
scale = 0.5
cube[i][j][k] = Piece(i * scale, j * scale, k * scale, scale)
def Cube():
for i in range(dim):
for j in range(dim):
for k in range(dim):
p = cube[i][j][k]
p.draw()
def main():
pygame.init()
display = (1200, 1000)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
gluPerspective(45, (display[0] / display[1]), 0.1, 50)
glClearColor(0.6, 0.6, 0.6, 0)
glTranslatef(0.0, 0.0, -5)
glRotatef(45, 1, 1, 0)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Cube()
pygame.display.flip()
pygame.time.wait(10)
main()
浮云间
相关分类