Chess board

import turtle    # 导入海龟绘图模块

def drawrect(c):
    turtle.color(c,c)  # 设置颜色
    turtle.begin_fill()  # 开始填充
    for i in range(4):
        turtle.forward(32)
        turtle.right(90)
    turtle.end_fill()  # 结束填充

row = 8  # 行数
col = 8  # 列数
for i in range(4):
    turtle.forward(32*8)
    turtle.right(90)
for i in range(row):
    for j in range(col):
        turtle.penup()  # 抬笔
        turtle.goto(32*j,-32*i) # 移动
        turtle.pendown()  # 落笔
        if i%2 == 0:  # 奇数行
            if j%2 == 0:   # 奇数列绘制
                drawrect('black')
        else:  # 偶数行
            if ~j%2 == 0: # 偶数列绘制
                drawrect('black')
turtle.ht()  # 隐藏海龟光标
turtle.done()  #海龟绘图程序的结束语句(开始主循环)


 

Guess you like

Origin blog.csdn.net/weixin_43115314/article/details/114639146