Python3 Turtle Draw Chess board
#!/usr/bin/env python#-*-coding:utf-8-*-# author:hiuhung wanimport turtlen = 60 # each line interval x = -300 # x Initial value y =-300 # X initial value Turtle.speed (one) turtle.pensize (2) # First draw the square of the 8*8, and apply black as required for I in range (8): for J in range (1, 9): Turtle.penup () Turtle.goto (x + i * N, y + J * N) Turtle.pendown () if (i + j)% 2 = = 1: #不涂黑 for index I N Range (4): Turtle.forward (n) turtle.left (All) elif (i + j)% 2 = = 0: #涂黑 Turtle.begin_fill () Turtle.fillcolor (' black ') for index in range (4): Turtle.forward (n ) Turtle.left (+) Turtle.end_fill () Turtle.penup () # Draw out again two squares x1 = x-n * 0.12y1 = y-n * 0.12 + nturtle.goto (x1, y1) Turtle.pendown () turtle.pensize (4) for index in range (4): Turtle.forward (n * 8 + 2 * n * 0.1 2) Turtle.left (+) Turtle.penup () #-----------------------------------------------x2 = x-n * 0.3y2 = y-n * 0.3 + NTU Rtle.goto (x2, y2) turtle.Pendown () turtle.pensize () for index in range (4): Turtle.forward (n * 8 + 2 * n * 0.3) Turtle.left (+) Turtle.hideturt Le () turtle.done ()
As follows:
Python3 Turtle Draw Chess board