使用Turtle绘制国际象棋棋盘,如图所示
要求:
1. 棋盘每一个方格为正方形,边长:30
2. 棋盘每一行由8个方格组成
3. 棋盘方格通过黑白颜色进行交替绘制
4. 绘制结束后隐藏小乌龟
参考代码
import turtle
def draw():
for i in range(4):
turtle.forward(30)
turtle.left(90)
turtle.forward(30)
for i in range(8):
turtle.penup()
turtle.goto(0, 30 * i)
turtle.pendown()
for j in range(8):
if (i+j) % 2 == 0:
col = 'black'
else:
col = 'white'
turtle.fillcolor(col)
turtle.begin_fill()
draw()
turtle.end_fill()
turtle.hideturtle()
标签:turtle,国际象棋,30,range,棋盘,绘制,col From: https://www.cnblogs.com/liuyangjava/p/18309849