Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. import turtle
  2.  
  3. def drawChessboard(startX, startY, width = 250, height = 250):
  4. turtle.speed(0)
  5. turtle.penup()
  6. # go to location specified by user
  7. turtle.goto(startX, startY)
  8. turtle.pendown()
  9. # Draw the red outline of the chessboard.
  10. turtle.color("red")
  11. for i in range(2):
  12. turtle.forward(width)
  13. turtle.left(90)
  14. turtle.forward(height)
  15. turtle.left(90)
  16. # Draw all of the black rectangles.
  17. drawAllRectangles(width, height, startX, startY)
  18. turtle.done()
  19.  
  20.  
  21. def drawAllRectangles(width, height, startX, startY):
  22. # Draw first set of squares
  23. for n in range(4):
  24. for i in range(4):
  25. turtle.pendown()
  26. drawRectangle(width, height)
  27. turtle.penup()
  28. turtle.forward(width / 4)
  29. turtle.penup()
  30. turtle.setheading(180)
  31. turtle.forward(width)
  32. turtle.setheading(90)
  33. turtle.forward(height / 4)
  34. turtle.setheading(0)
  35. # Set up for the second set of squares.
  36. turtle.penup()
  37. turtle.goto(startX, startY)
  38. turtle.setheading(0)
  39. turtle.forward(width / 8)
  40. turtle.setheading(90)
  41. turtle.forward(height / 8)
  42. turtle.setheading(0)
  43. turtle.pendown()
  44. # Draw second set of squares
  45. for n in range(4):
  46. for i in range(4):
  47. turtle.pendown()
  48. drawRectangle(width, height)
  49. turtle.penup()
  50. turtle.forward(width / 4)
  51. turtle.penup()
  52. turtle.setheading(180)
  53. turtle.forward(width)
  54. turtle.setheading(90)
  55. turtle.forward(height / 4)
  56. turtle.setheading(0)
  57. # Draw individual rectangles
  58. def drawRectangle(width, height):
  59. turtle.fillcolor("black")
  60. turtle.begin_fill()
  61. for i in range(2):
  62. turtle.forward(width / 8)
  63. turtle.left(90)
  64. turtle.forward(height / 8)
  65. turtle.left(90)
  66. turtle.end_fill()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement