In: Computer Science
I need to draw my first name using Turtle. I am struggling with "P" and "A" this is what I have
import turtle
turtle.setup(800, 700)
window = turtle.Screen()
window.reset()
window.bgcolor('cornsilk')
t = turtle.Turtle()
t.color('blue')
t.pencolor('red')
t.turtlesize(6)
t.speed(2)
t.up()
t.setposition(-50, 0)
t.pendown()#Drawing letter T
t.forward(40)
t.back(20)
t.right(90)
t.forward(50) t.left(90)
t.penup() t.forward(70)
t.left(90) t.forward(25)
t.pendown()
t.circle(25)# Drawing letter O
t.penup()
t.left(180)
t.forward(25)
t.left(90)
t.forward(10)
t.pendown()#Drawing letter N
t.left(90)
t.forward(50)
t.right(150)
t.forward(60)
t.left(150)
t.forward(53)
t.back(53)
t.right(90)
turtle.done()
code:
import turtle
turtle.setup(800, 700)
window = turtle.Screen()
window.reset()
window.bgcolor('cornsilk')
t = turtle.Turtle()
t.color('blue')
t.pencolor('red')
t.turtlesize(6)
t.speed(2)
def drawA(width, height):
    """
    t will draw the letter A with a given width and height,
    with the current location being the lower left corner of the A.
    """
    # figure out where we are
    startX = t.xcor()
    startY = t.ycor()
    # figure out the other points using only what we know,
    # which is width, height, startX and startY
    
    topAX = startX + (width/2)
    topAY = startY + height
    bottomRightX = startX + width
    bottomRightY = startY
    
    barLeftX = startX + width/4
    barLeftY = startY + height/2
    barRightX = startX + (width/4) + (width/2)
    barRightY = startY + height/2
    
    # draw left hand side of the A    
    t.goto(topAX,topAY)
    # draw the right side of the A
    t.goto(bottomRightX, bottomRightY)
    # draw bar across the middle
    
    t.up()
    t.goto(barLeftX,barLeftY)
    t.down()
    t.goto(barRightX,barRightY)
    # leave turtle at lower right hand corner of letter
    
    t.up()
    t.goto(bottomRightX,bottomRightY)
    t.down()
def drawT(width,height):
   '''
   draw a T
   assume turtle facing east (0), and leave it facing east
   assume pen is down
   no assumptions about position.
   '''
   t.forward (width)
   t.backward (width/2)
   t.right (90)
   t.forward (height)
   t.left(90)
def drawO(width,height):
    """
    Draw the digit zero.  Assumes aTurtle starts pointing right,
    pen down
    at lower left of a rectantgle, with given width and height.
    Leave the turtle pointing right at the lower right of that
    same rectangle when done, with pen still down.
    """
    # Go counter-clockwise around the box
    t.forward(width)
    t.left(90)
    t.forward(height)
    t.left(90)
    t.forward(width)
    t.left(90)
    t.forward(height)
    t.left(90)
    # Now move over to lower left corner
    t.up()
    t.forward(width) 
    t.down()
def drawN():
    t.left(90)
    t.forward(100)
    t.right(150)
    t.forward(116)
    t.left(150)
    t.forward(100)
    t.up()
    t.right(180)
    t.forward(100)
    t.left(90)
def drawP():
    t.left(90)
    t.forward(100)
    t.right(90)
    t.circle(-30, 180, 50)
t.up()
t.setposition(-300, 0)
t.down()
drawT(50,100)
t.up()
t.forward(50)
t.down()
drawO(50, 100)
t.up()
t.forward(50)
t.down()
drawA(50, 100)
t.up()
t.forward(50)
t.down()
drawN()
t.up()
t.forward(50)
t.down()
drawP()
turtle.done()
output: