Python海龟画棋盘

from turtle import *

i = 0
x = -200
y = -200

color("black")
hideturtle()
speed(1000)
pensize(3)

def draw(i):
    for _ in range(8):
        if i % 2 == 0:
            begin_fill()
        left(90)
        forward(40)
        right(90)
        forward(40)
        right(90)
        forward(40)
        right(90)
        forward(40)
        if i % 2 == 0:
            end_fill()
        penup()
        right(180)
        forward(40)
        pendown()
        i += 1

loop = 0
for _ in range(8):
    penup()
    goto(x, y + loop)
    pendown()
    draw(i)
    i += 1
    loop += 40

done()

你可能感兴趣的:(Python海龟画棋盘)