# 海龟绘图之棋盘
# x1[(-400,400), (400,400)],那么x1[0]是不是(-400,400), x1[0][0]代表取-400
import turtle
# 如果不赋值p = turtle.Pen(),turtle.Pen()是一个 对象,如果直接调用turtle.Pen()参与循环的,每次都会创建一个新的turtle.Pen()对象,这样就是产生你这个运行结果
# p = turtle.Pen()
width = 30
num = 18
x1 = [(-400,400),(-400+width*num,400)]
y1 = [(-400,400),(-400,400-width*num)]
t = turtle.Pen()
t.speed(18) # 绘图速度
# t.goto(x1[0][0],x1[0][1])
# t.goto(x1[1][0],x1[1][1])
for i in range(num+1): # 循环18次
t.penup() # 抬笔
t.goto(x1[0][0],x1[0][1]-30*i)
t.pendown() # 下笔
t.goto(x1[1][0],x1[1][1]-30*i)
for i in range(num+1):
t.penup()
t.goto(y1[0][0] + 30 * i, y1[0][1])
t.pendown()
t.goto(y1[1][0] + 30 * i, y1[1][1])
t.hideturtle() # 隐藏画笔
turtle.done()