Drawing Captain America Shield with Python Turtle

Drawing Captain America Shield with Python Turtle

In this tutorial, we will be Drawing Captain America Shield with Python Turtle. First of all, let me tell you that we are using the Python turtle module, which is easy to learn and use just like the Python programming language is compared to other languages. That’s why we are using the Python Turtle module.

This module comes inbuilt Python Python versions of greater than or equal to 3. You need to download this module externally. Now let’s first see the code for Drawing Captain America Shield with Python Turtle. After this, we will see the explanation of this code.


Code:


import turtle
import math

t = turtle.Turtle()


def ankur(x, y):
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.setheading(0)
    t.pensize(2)
    t.speed(10)


def golo(r, color):
    x_point = 0
    y_pont = -r
    ankur(x_point, y_pont)
    t.pencolor(color)
    t.fillcolor(color)
    t.begin_fill()
    t.circle(r)
    t.end_fill()


def paanch(r, color):
    ankur(0, 0)
    t.pencolor(color)
    t.setheading(162)
    t.forward(r)
    t.setheading(0)
    t.fillcolor(color)
    t.begin_fill()
    for i in range(5):
        t.forward(math.cos(math.radians(18)) * 2 * r)  # 2cos18°*r
        t.right(144)
    t.end_fill()
    t.hideturtle()


if __name__ == '__main__':
    golo(288, 'crimson')
    golo(234, 'snow')
    golo(174, 'crimson')
    golo(114, 'blue')
    paanch(114, 'snow')
    turtle.done()

Output:




Explanation:


First Part:

  • Firstly, in Drawing Captain America Shield with Python Turtle, we will import the “turtle” and “math” module. Then, we will set the variable “t” as the turtle.Turtle(). Now, create a function named ankur() with the parameters “x” and “y”. Similarly, inside this function, we will pick the pen up, go to (x, y), and put it down. Then, we will call the setheading() method with the value of 0, and we will set the pen size to 2 and the speed to 10.
  • Likewise, create a function named golo() with the parameters “r” and “color”. Inside this function, we will set the value of the variable x_point to “0” and the value of the variable y_pont to “-r”. Then, call the “ankur” function with the arguments “x_point” and “y_point”. Now, set the pen color to “color” and fill the color as “color”. Similarly, begin the fill and call the golo() function with the argument r. End the fill.
  • Accordingly, create a function named paanch() with the parameters “r” and “color.” Inside this function, we will call the ankur() function with the arguments (0, 0). Set the pen color as “color” and call the “setheading” method with the value of 162. Move the turtle forward at the value of r. Again, set the heading to 0 and fill the part with the color “color” and begin the fill. Likewise, create a for loop with the range of 5. Inside this loop, move the turtle forward with the equation [math.cos(math.radians(18))*2*r] and right at an angle of 144 degrees. End the fill and hide the turtle.

Last Part:

  • Write a module source as this is the main program. Inside this code, call the golo() function with the arguments (288,’crimson’), (234,’snow’), (174,’crimson’), (114,’blue’) and (114,’snow’) respectively.

Thank You for reading till the end. Comment your queries if you have any.

Humans do mistakes, tell us if you find something wrong in this article.

Keep Learning


Also Read:



    Share:

    Author: Ayush Purawr