Hi, I am writing a program that draws to checkerboards. So you input the starting and ending points of the checkerboards and it draws it. My, problem is that after the first checkerboard is drawn, the cursor wanders off out of the screen instead of going to the starting point of the second checkerboard and drawing the second checkerboard. What have I done wrong? Thanks
import turtle
def draw_chess_board(startx, endx, starty, endy):
draw_first_half_diagonal(startx, endx, starty, endy)
draw_second_half_diagonal(startx, endx, starty, endy)
draw_border(startx, endx, starty, endy)
def draw_first_half_diagonal(startx, endx, starty, endy):
y_shift = (endy - starty) / 8
for i in range(1, 7 + 1, 2):
turtle.penup()
turtle.goto(startx, starty + i * y_shift)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("black")
for j in range(1, i + 1):
turtle.setheading(0)
turtle.forward((endx - startx) / 8)
turtle.setheading(270)
turtle.forward((endy - starty) / 8)
for k in range(1, i + 1):
turtle.setheading(180)
turtle.forward((endx - startx) / 8)
turtle.setheading(90)
turtle.forward((endy - starty) / 8)
turtle.end_fill()
def draw_second_half_diagonal(startx, endx, starty, endy):
x_shift = (endx - startx) / 8
for i in range(1, 7 + 1, 2):
turtle.penup()
turtle.goto(endx - i * x_shift, endy)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("black")
for j in range(1, i + 1):
turtle.setheading(0)
turtle.forward((endx - startx) / 8)
turtle.setheading(270)
turtle.forward((endy - starty) / 8)
for k in range(1, i + 1):
turtle.setheading(180)
turtle.forward((endx - startx) / 8)
turtle.setheading(90)
turtle.forward((endy - starty) / 8)
turtle.end_fill()
def draw_border(startx, endx, starty, endy):
turtle.penup()
turtle.goto(startx, starty)
turtle.pendown()
turtle.goto(startx, endy)
turtle.goto(endx, endy)
turtle.goto(endx, starty)
turtle.goto(startx, starty)
def main():
# Get start and end coordinates for chessboard 1 and 2
c1_startx, c1_endx, c1_starty, c1_endy = eval(input("Enter the coordinates of chessboard one's starting and ending points: "))
c2_startx, c2_endx, c2_starty, c2_endy = eval(input("Enter the coordinates of chessboard two's starting and ending points: "))
turtle.screensize(1000, 1000)
turtle.showturtle()
draw_chess_board(c1_startx, c1_endx, c1_starty, c1_endy)
draw_chess_board(c2_startx, c2_endx, c2_starty, c2_endy)
turtle.hideturtle()
turtle.done()
main()