# Arup Guha
# 6/14/2017
# Draws a chessboard using the python turtle, adding x's in the forward diagonal.
# This board must be square.
import turtle
# Constants for our board
SIZE = 8
SQSIZE = 50
XSIZE = 42
DY = 30
XGAP = 10
STARTX = -200
STARTY = -200
def main():
# Lot to draw so let's do it fast.
turtle.speed(0)
# Draw each row, from the bottom up.
for row in range(SIZE+1):
# Lift the pen, move to the bottom end, draw up.
turtle.penup()
turtle.setpos(STARTX, STARTY + SQSIZE*row)
turtle.pendown()
turtle.forward(SQSIZE*SIZE)
# Face up.
turtle.left(90)
# Draw each column, from the bottom up, left to right.
for col in range(SIZE+1):
# Lift the pen, move to the bottom end, draw up.
turtle.penup()
turtle.setpos(STARTX + SQSIZE*col, STARTY)
turtle.pendown()
turtle.forward(SQSIZE*SIZE)
# Loop to draw x's, from the bottom left to the top right.
for row in range(SIZE):
# Where I want to start from each time.
turtle.setheading(0)
# Calculate bottom left corner.
x = STARTX + SQSIZE*row
y = STARTY + SQSIZE*row
# First diagonal
turtle.penup()
turtle.setpos(x+XGAP, y+XGAP)
turtle.left(45)
turtle.pendown()
turtle.forward(XSIZE)
# Lift the pen and draw the cross diagonal.
turtle.penup()
turtle.setpos(x+XGAP, y+XGAP+DY)
turtle.right(90)
turtle.pendown()
turtle.forward(XSIZE)
main()