Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```from math import sqrt
- from turtle import *
- def letter_k(turtle: Turtle, height: int):
- """draws the letter k"""
- # draw the left side of the k
- turtle.left(90)
- turtle.forward(height / 2)
- turtle.backward(height)
- turtle.forward(height / 2)
- # draws the upper-right side of the k
- turtle.right(45)
- turtle.forward(height / 2 * sqrt(2))
- turtle.backward(height / 2 * sqrt(2))
- # draws the bottom-right side of the k
- turtle.right(90)
- turtle.forward(height / 2 * sqrt(2))
- turtle.backward(height / 2 * sqrt(2))
- # resets the turtle for the next letter
- turtle.left(45)
- def letter_i(turtle: Turtle, height: int):
- """draws the letter i"""
- # draw the bottom of the i
- turtle.left(90)
- turtle.backward(height / 2)
- # move to the top of the letter
- turtle.right(90)
- move(turtle, y=height)
- turtle.left(90)
- # dots the i
- turtle.backward(10)
- # resets the turtle for the next letter
- turtle.right(90)
- move(turtle, y=-height / 2 + 10)
- def letter_n(turtle: Turtle, height: int):
- """draws the letter n"""
- turtle.left(90) # turns the turtle so the line in the n can drawn
- turtle.backward(height / 2) # draws the left line in the letter n
- turtle.forward(height / 2 - 20) # go back up except 20 pixels
- turtle.circle(-20, 180, 30) # draw the half circle
- turtle.forward(height / 2 - 20) # go forward except 20 pixels
- # resets the turtle for the next letter
- turtle.left(90)
- move(turtle, y=height / 2)
- def letter_d(turtle: Turtle, height: int):
- """draws the letter d"""
- # moves the turtle to the beginning of the letter
- move(turtle, y=-height / 2)
- turtle.circle(height / 4, 450, 30) # draws the partial circle 450 degrees to help line up the line of the letter
- turtle.backward(height / 4) # draws down a little ways for the button of the line
- turtle.forward(height) # draws the line in the letter d
- # resets the turtle for the next letter
- turtle.right(90)
- move(turtle, y=-height / 2)
- def letter_e(turtle: Turtle, height: int):
- """draws the letter e"""
- move(turtle, y=-height / 4) # moves the turtle to the beginning of the letter
- turtle.forward(height / 2) # draws the line across the letter e
- turtle.left(90) # point up to help draw the partial circle
- turtle.circle(height / 4, 270, 30) # draws the partial circle 270 degrees
- turtle.forward(height / 4) # draw the end of the e on the button of the letter
- # resets the turtle for the next letter
- move(turtle, y=height / 4)
- def letter_s(turtle: Turtle, height: int):
- """draws the letter s"""
- # moves the turtle to the beginning of the letter
- move(turtle, y=-height / 8)
- turtle.right(90)
- turtle.circle(height / 8, 270, 30) # draws the first partial circle 270 degrees
- turtle.circle(-height / 8, 270, 30) # draws the first partial circle 270 degrees going the opposite way
- # resets the turtle for the next letter
- turtle.left(90)
- move(turtle, y=-height / 8)
- def move(turtle, x=0, y=0):
- """
- moves the pen forward x amount
- then rotates 90 degrees
- and moves the pen forward y amount
- without drawing
- """
- turtle.penup()
- turtle.forward(x)
- turtle.left(90)
- turtle.forward(y)
- turtle.right(90)
- turtle.pendown()
- def kindness(turtle: Turtle, height: int):
- """writes the word kindness"""
- letter_k(turtle, height)
- move(turtle, 75)
- letter_i(turtle, height)
- move(turtle, 25)
- letter_n(turtle, height)
- move(turtle, 50)
- letter_d(turtle, height)
- move(turtle, 25)
- letter_n(turtle, height)
- move(turtle, 25)
- letter_e(turtle, height)
- move(turtle, 25)
- letter_s(turtle, height)
- move(turtle, 25)
- letter_s(turtle, height)
- if __name__ == '__main__':
- """main method"""
- t = Turtle() # creates a new turtle instance
- h = 100 # sets the height for the letters
- kindness(t, h) # draws the word kindness
- done() # waits for the user to exit the window
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement