我已经能够在5 x 5中创建圆了。我被困在10 X 10网格中放置圆。如何使用python 3 synax将圆圈放入10X10网格中?
这是我当前的代码;
谢谢:)
centrex = 5
centrey = 5
colour1 = "red"
colour2 = "white"
for i in range(5):
for j in range(5):
circle = Circle(Point(centrex,centrey),5)
circle.setFill(colour2)
circle.setOutline(colour2)
circle.draw(win)
centrex+=10
centrex=5
centrey+=10
答案 0 :(得分:0)
您可以使for
循环的运行范围更大。然后为网格的四个扇区定义要使用的4种不同颜色,并在内部循环体内使用这些颜色:
centrex = 5
centrey = 5
fillcolours = [["red", "blue"],
["green", "grey"]]
bordercolour = "white"
for i in range(10):
for j in range(10):
fillcolour = fillcolours[i // 5][j // 5]
circle = Circle(Point(centrex,centrey),5)
circle.setFill(fillcolour)
circle.setOutline(bordercolour)
circle.draw(win)
centrex+=10
centrex=5
centrey+=10