Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- def drawChessboard(startX, startY, width = 250, height = 250):
- turtle.speed(0)
- turtle.penup()
- turtle.goto(startX, startY)
- turtle.pendown()
- # Draw the red outline of the chessboard.
- turtle.color("red")
- for i in range(2):
- turtle.forward(width)
- turtle.left(90)
- turtle.forward(height)
- turtle.left(90)
- turtle.color("black")
- #draw first set of black squares.
- drawAllRectangles(width, height, startX, startY)
- for k in range(4):
- secondBlackSpace()
- startY += (spaceHeight * 2)
- turtle.goto(startX, startY)
- def drawAllRectangles(width, height, startX, startY):
- # Draw first set of squares
- for n in range(4):
- turtle.pendown()
- drawRectangle(width, height)
- turtle.penup()
- turtle.forward(width / 4)
- turtle.pendown()
- # Reposition the turtle to draw second set of squares
- turtle.penup()
- newstartY = startY + (spaceHeight * 2)
- turtle.goto(startX, newstartY)
- # Draw second set of squares
- for n in range(4):
- for i in range(4):
- turtle.penup()
- turtle.forward(spaceWidth)
- turtle.pendown()
- drawRectangle(width, height)
- secondstartY += spaceHeight
- turtle.goto(startX, secondstartY)
- # Draw individual rectangles
- def drawRectangle(width, height):
- turtle.fillcolor("black")
- turtle.begin_fill()
- for i in range(2):
- turtle.forward(width / 8)
- turtle.left(90)
- turtle.forward(height / 8)
- turtle.left(90)
- turtle.end_fill()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement