绘制一个8行8列的棋盘,棋盘小方格边长为36像素。 请将完成后的程序以“chessboard
时间: 2023-12-10 19:00:50 浏览: 124
画棋盘格程序
5星 · 资源好评率100%
def chessboard():
import turtle
# 设置小方格边长
length = 36
# 设置屏幕大小
screen = turtle.Screen()
screen.setup(length*8, length*8)
# 创建一个海龟对象
turtle1 = turtle.Turtle()
turtle1.speed(0)
# 绘制棋盘
for i in range(8):
for j in range(8):
if (i + j) % 2 == 0:
turtle1.fillcolor("black")
else:
turtle1.fillcolor("white")
turtle1.begin_fill()
# 绘制小方格
for _ in range(4):
turtle1.forward(length)
turtle1.right(90)
turtle1.end_fill()
turtle1.forward(length)
turtle1.backward(length*8)
turtle1.right(90)
turtle1.forward(length)
turtle1.left(90)
turtle.done()
chessboard()
阅读全文