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.penup()
- # go to location specified by user
- 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)
- # Draw all of the black rectangles.
- drawAllRectangles(width, height, startX, startY)
- turtle.done()
- def drawAllRectangles(width, height, startX, startY):
- # Draw first set of squares
- for n in range(4):
- for i in range(4):
- turtle.pendown()
- drawRectangle(width, height)
- turtle.penup()
- turtle.forward(width / 4)
- turtle.penup()
- turtle.setheading(180)
- turtle.forward(width)
- turtle.setheading(90)
- turtle.forward(height / 4)
- turtle.setheading(0)
- # Set up for the second set of squares.
- turtle.penup()
- turtle.goto(startX, startY)
- turtle.setheading(90)
- turtle.forward(height / 8)
- turtle.setheading(0)
- turtle.pendown()
- # Draw second set of squares
- for n in range(4):
- for i in range(4):
- turtle.penup()
- turtle.forward(width / 8)
- turtle.pendown()
- drawRectangle(width, height)
- turtle.penup()
- turtle.setheading(180)
- turtle.forward(width)
- turtle.setheading(90)
- turtle.forward(height / 4)
- turtle.setheading(0)
- # 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()
- draw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement