我想定义25个不同的“矩形”,每个矩形有6个不同的属性。我首先创建了一个只有25个不同元素的列表。然后使用不同的循环,我试图将每个矩形的6个属性附加到包含1-25的列表中。这是我得到的错误,我有一种感觉,这是由于我没有分配什么元素“列表”分配新的6个元素。在
Traceback (most recent call last):
File "tryingRectangle.py", line 37, in <module>
rectanglePos.append(x, y, width, height)
TypeError: append() takes exactly one argument (4 given)
# Create the empty array to house the rectangle
rectanglePos = []
rectangleInPos = [rectanglePos]
# Loop 25 times and add rectangle in random x,y position
for i in range(25):
rectanglePos[i] = i
height = random.randint(20,400)
x = i*20
y = 200
width = 15
rectangleInPos.append(rectanglepos[i])
# Ignore me clock = pygame.tme.Clock()
# Loop until user closes
done = False
while done == False:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
# Set the background WHITE
screen.fill(WHITE)
# Process each rectangle
for i in range(len(rectangle)):
# Draw the Rectangle
pygame.draw.rect(SIZE, RED , rectanglePos[i[1]], rectanglePos[i[2]], rectanglePos[i[3]], rectangle[i[4]], 0)
我知道我可能在这方面做得不对,但我对如何创建列表感到困惑。在
从这里我可以看到,python使用rectanglepos[I]处的值作为append方法的参数,而不是将其作为实际列表传递。我唯一的想法就是尝试
但我真的不明白这会有什么不同。在
所以实际上,你不能改变你的屏幕属性,因为你定义了游戏屏幕的大小。在
^{pr2}$输出:
输出:
或者如果您想要更多颜色只需更改这一个
输出:
这里是整个代码:
尝试在不使用if i==24语句的情况下执行此操作!:-)
输出:
我假设列表是你想要一个三角形列表,每个三角形由一个属性列表组成?假设这是你想要的,试试这个。在
相关问题 更多 >
编程相关推荐