Advertisement
Guest User

Untitled

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