Drawing letter A using Python Turtle

Drawing letter A using Python Turtle Today, we will learn how to draw the letter 'A' using Python Turtle. We all know how to write the letter 'A' using pen and paper, but would it not be great if you had a turtle, who can take your commands and draw it for you in whatever size or color you want? This is what Python Turtle does. It is a python library used to create graphics, patterns, and shapes, but it can be used to draw almost anything.

Today, we will learn how to draw the letter ‘A’ using Python Turtle. We all know how to write the letter ‘A’ using pen and paper, but would it not be great if you had a turtle, who can take your commands and draw it for you in whatever size or color you want? This is what Python Turtle does. It is a python library used to create graphics, patterns, and shapes, but it can be used to draw almost anything.

This article has two parts, in the first part we will learn how to draw the letter ‘A’ in one dimension, and in the next part, we will learn to draw the letter ‘A’ in two dimensions.

Code for drawing letter ‘A’ in one-dimension

#Drawing letter 'A' in 1 dimension

#importing the module
import turtle

#creating a turtle object and assigning it to t
t = turtle.Turtle()
side=100 #side lengths of letter 'A'

#initially the turtle points towards right
t.left(60) 
#the turtle pointer will take a 60 degree turn
t.forward(side) 
#draw length of one side of 'A'
t.right(180-60)
#turtle take a 120 degree turn from current direction of turtle
#so that there is a 60 degree angle between two sides of 'A'
t.forward(side)
#this will draw another side

#this part is to draw the middle line across two sides of 'A'
t.penup()
t.right(180)
t.forward(side/2) t.pendown() t.left(60) t.forward(side/2) #it calls Tkinter’s mainloop function #so that window will stay open until the user exits the program turtle.done()

Output:

Output: 'A' using python turtle in one dimension

Since, we are done with the easy part, we are better equipped to go ahead and draw the letter ‘A’ in two-dimensions

Code for drawing letter ‘A’ in two-dimension

#Drawing letter 'A' in 2-dimension
#importing the module
import turtle
#creating a new turtle object and assigning it to t
t = turtle.Turtle()

#setting the size of letter A
outer_side=200
width=20 #width of letter as we will be drawing in 2 dimension
inner_side=outer_side-width
inner_triangle_side=inner_side/2 - 2*width

#part1, drawing the outer boundary
t.fillcolor("blue") #select the colour of letter

t.begin_fill() #starting point for filling colour
t.backward(width) 
t.left(60) #this is to keep letter A at 60 degrees with respect to x-axis
t.forward(outer_side) 
#at this point the turtle has drawn left side of outer boundary of 'A'
t.right(120) 
t.forward(outer_side)
t.right(120)
t.forward(width)
#at this point of time, both sides of outer boundary of 'A' will be drawn

#now we will draw lower half of inner boundary of 'A'
t.right(60)
t.forward(inner_side/2)
t.left(60)
t.forward(inner_side/2 - width)
t.left(60)
t.forward(inner_side/2)
#at this point the lower half of inner boundary of 'A' will be drawn
t.end_fill() #this will fill the entire area inside the letter with blue colour
#part1, i.e., drawing the outer boundary is done

t.left(180)
t.penup()
#penup is used to move turtle to particular point without drawing anything
t.forward(inner_side/2 + width)

#part2, drawing inner triangle of 'A'
t.fillcolor("white")
#As we had filled 'A' with blue color, so keeping white color for inner triangle
t.begin_fill()
t.pendown()

t.forward(inner_triangle_side) 
t.right(120)
t.forward(inner_triangle_side)
t.right(120)
t.forward(inner_triangle_side)
t.end_fill()

turtle.done()

Output:

Output: 'A' using python turtle in two dimensions

So, we learned how to draw the letter ‘A’ using Python turtle, you can make changes in code to change color and increase/decrease the size of the letter. For better understanding, I suggest you run the program after every few lines to observe how it is working. Just remember to put turtle.done() at the end before running. Hope, you had fun going through this article.


Also Read:

Share:

Author: Ayush Purawr