Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. ```from math import sqrt
  2. from turtle import *
  3.  
  4.  
  5. def letter_k(turtle: Turtle, height: int):
  6. """draws the letter k"""
  7. # draw the left side of the k
  8. turtle.left(90)
  9. turtle.forward(height / 2)
  10. turtle.backward(height)
  11. turtle.forward(height / 2)
  12.  
  13. # draws the upper-right side of the k
  14. turtle.right(45)
  15. turtle.forward(height / 2 * sqrt(2))
  16. turtle.backward(height / 2 * sqrt(2))
  17.  
  18. # draws the bottom-right side of the k
  19. turtle.right(90)
  20. turtle.forward(height / 2 * sqrt(2))
  21. turtle.backward(height / 2 * sqrt(2))
  22.  
  23. # resets the turtle for the next letter
  24. turtle.left(45)
  25.  
  26.  
  27. def letter_i(turtle: Turtle, height: int):
  28. """draws the letter i"""
  29. # draw the bottom of the i
  30. turtle.left(90)
  31. turtle.backward(height / 2)
  32.  
  33. # move to the top of the letter
  34. turtle.right(90)
  35. move(turtle, y=height)
  36. turtle.left(90)
  37.  
  38. # dots the i
  39. turtle.backward(10)
  40.  
  41. # resets the turtle for the next letter
  42. turtle.right(90)
  43. move(turtle, y=-height / 2 + 10)
  44.  
  45.  
  46. def letter_n(turtle: Turtle, height: int):
  47. """draws the letter n"""
  48. turtle.left(90) # turns the turtle so the line in the n can drawn
  49. turtle.backward(height / 2) # draws the left line in the letter n
  50. turtle.forward(height / 2 - 20) # go back up except 20 pixels
  51. turtle.circle(-20, 180, 30) # draw the half circle
  52. turtle.forward(height / 2 - 20) # go forward except 20 pixels
  53.  
  54. # resets the turtle for the next letter
  55. turtle.left(90)
  56. move(turtle, y=height / 2)
  57.  
  58.  
  59. def letter_d(turtle: Turtle, height: int):
  60. """draws the letter d"""
  61. # moves the turtle to the beginning of the letter
  62. move(turtle, y=-height / 2)
  63.  
  64. turtle.circle(height / 4, 450, 30) # draws the partial circle 450 degrees to help line up the line of the letter
  65. turtle.backward(height / 4) # draws down a little ways for the button of the line
  66. turtle.forward(height) # draws the line in the letter d
  67.  
  68. # resets the turtle for the next letter
  69. turtle.right(90)
  70. move(turtle, y=-height / 2)
  71.  
  72.  
  73. def letter_e(turtle: Turtle, height: int):
  74. """draws the letter e"""
  75. move(turtle, y=-height / 4) # moves the turtle to the beginning of the letter
  76.  
  77. turtle.forward(height / 2) # draws the line across the letter e
  78. turtle.left(90) # point up to help draw the partial circle
  79. turtle.circle(height / 4, 270, 30) # draws the partial circle 270 degrees
  80. turtle.forward(height / 4) # draw the end of the e on the button of the letter
  81.  
  82. # resets the turtle for the next letter
  83. move(turtle, y=height / 4)
  84.  
  85.  
  86. def letter_s(turtle: Turtle, height: int):
  87. """draws the letter s"""
  88. # moves the turtle to the beginning of the letter
  89. move(turtle, y=-height / 8)
  90. turtle.right(90)
  91.  
  92. turtle.circle(height / 8, 270, 30) # draws the first partial circle 270 degrees
  93. turtle.circle(-height / 8, 270, 30) # draws the first partial circle 270 degrees going the opposite way
  94.  
  95. # resets the turtle for the next letter
  96. turtle.left(90)
  97. move(turtle, y=-height / 8)
  98.  
  99.  
  100. def move(turtle, x=0, y=0):
  101. """
  102. moves the pen forward x amount
  103. then rotates 90 degrees
  104. and moves the pen forward y amount
  105. without drawing
  106. """
  107. turtle.penup()
  108. turtle.forward(x)
  109. turtle.left(90)
  110. turtle.forward(y)
  111. turtle.right(90)
  112. turtle.pendown()
  113.  
  114.  
  115. def kindness(turtle: Turtle, height: int):
  116. """writes the word kindness"""
  117. letter_k(turtle, height)
  118. move(turtle, 75)
  119. letter_i(turtle, height)
  120. move(turtle, 25)
  121. letter_n(turtle, height)
  122. move(turtle, 50)
  123. letter_d(turtle, height)
  124. move(turtle, 25)
  125. letter_n(turtle, height)
  126. move(turtle, 25)
  127. letter_e(turtle, height)
  128. move(turtle, 25)
  129. letter_s(turtle, height)
  130. move(turtle, 25)
  131. letter_s(turtle, height)
  132.  
  133.  
  134. if __name__ == '__main__':
  135. """main method"""
  136. t = Turtle() # creates a new turtle instance
  137. h = 100 # sets the height for the letters
  138. kindness(t, h) # draws the word kindness
  139. done() # waits for the user to exit the window
  140. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement