Draw Python Logo in Python Turtle

Draw Python Logo in Python Turtle

Introduction

Hello and welcome to the copyassignment, today we will learn how to Draw Python Logo in Python Turtle. This could be very interesting for both beginners and experienced coders to learn. This could be simple and easy to understand because we have explained the code in simple terms.

Step 1: Importing Libraries

# Importing turtle library to draw python logo
import turtle

Step 2: Creating a Cursor and a Separate Canvas to draw Python Logo

# Creating our turtle cursor to draw
my_turtle_cursor = turtle.Turtle()

# Creating a separate Canvas to draw Python Logo
my_turtle_screen = turtle.Screen()

Step 3: Creating a function to draw the upper dot of the Python Logo


# Function to draw upper dot of Python Logo
def draw_upper_dot_of_python_logo():
    my_turtle_cursor.penup()
    my_turtle_cursor.right(90)
    my_turtle_cursor.forward(160)
    my_turtle_cursor.left(90)
    my_turtle_cursor.forward(70)
    my_turtle_cursor.pencolor("white")
    my_turtle_cursor.dot(35)

Step 3: Creating a function to go to Second Position on our Canvas

# Function to do to second position
def goto_second_position():
    my_turtle_cursor.penup()
    my_turtle_cursor.forward(20)
    my_turtle_cursor.right(90)
    my_turtle_cursor.forward(10)
    my_turtle_cursor.right(90)
    my_turtle_cursor.pendown()

Step 4: Creating a function to draw the second dot of the Python Logo

# Function to draw second dot
def draw_lower_dot_of_python_logo():
    my_turtle_cursor.left(90)
    my_turtle_cursor.penup()
    my_turtle_cursor.forward(310)
    my_turtle_cursor.left(90)
    my_turtle_cursor.forward(120)
    my_turtle_cursor.pendown()

    my_turtle_cursor.dot(35)

Step 5: Creating a half function

def half():
    my_turtle_cursor.forward(50)
    draw_side_curve_of_python_logo()
    my_turtle_cursor.forward(90)
    draw_first_left_curve_of_python_logo()
    my_turtle_cursor.forward(40)
    my_turtle_cursor.left(90)
    my_turtle_cursor.forward(80)
    my_turtle_cursor.right(90)
    my_turtle_cursor.forward(10)
    my_turtle_cursor.right(90)
    my_turtle_cursor.forward(120)  # on test
    draw_second_left_curve_of_python_logo()
    my_turtle_cursor.forward(30)
    my_turtle_cursor.left(90)
    my_turtle_cursor.forward(50)
    draw_right_curve_of_python_logo()
    my_turtle_cursor.forward(40)
    my_turtle_cursor.end_fill()

Step 6: Creating a Function to Draw First left Curve of Python Logo

# Function to draw first left curve
def draw_first_left_curve_of_python_logo():
    draw_side_curve_of_python_logo()
    my_turtle_cursor.forward(80)
    draw_side_curve_of_python_logo()

Step 7: Creating a Function to draw the second left curve of the Python Logo

# Function to draw second left curve
def draw_second_left_curve_of_python_logo():
    draw_side_curve_of_python_logo()
    my_turtle_cursor.forward(90)
    draw_side_curve_of_python_logo()

Step 8: Creating a function to draw a side curve

# Function to Draw Side Curve
def draw_side_curve_of_python_logo():
    for i in range(90):
        my_turtle_cursor.left(1)
        my_turtle_cursor.forward(1)

Step 9: Creating a Function to Draw Right Curve

# Function to draw right curve
def draw_right_curve_of_python_logo():
    for i in range(90):
        my_turtle_cursor.right(1)
        my_turtle_cursor.forward(1)

Step 10: Creating a Function to Pause the Cursor at the End

#  Creating a pause function to pause the cursor
def pause():
    my_turtle_cursor.speed(2)
    for i in range(100):
        my_turtle_cursor.left(90)

Step 11: Setting the Pen size and Speed of our Cursor

# Setting The configuration of our cursor according to our needs
my_turtle_cursor.pensize(2)
my_turtle_cursor.speed(10)
my_turtle_cursor.pensize(2)
my_turtle_cursor.pencolor("black")

Step 12: Setting the Fill Colors for different parts and Calling all the Functions

# We have changed background color of canvas
my_turtle_screen.bgcolor("white")

# Setting the fill color of upper part of python logo
my_turtle_cursor.fillcolor("#306998")

# Starting to fill color of upper part of python logo
my_turtle_cursor.begin_fill()

half()

# Stooping the cursor to fill color in upper part of python logo
my_turtle_cursor.end_fill()

goto_second_position()

# Setting the fill color of lower part of python logo
my_turtle_cursor.fillcolor("#FFD43B")
my_turtle_cursor.begin_fill()

half()

# Stooping the cursor to fill color in lower part of python logo
my_turtle_cursor.end_fill()

# Drawing upper and lower dots of python logo
draw_upper_dot_of_python_logo()
draw_lower_dot_of_python_logo()

pause()

Complete Code to Draw Python Logo Using Turtle in Python

# Importing turtle library to draw python logo
import turtle

# Creating our turtle cursor to draw
my_turtle_cursor = turtle.Turtle()

# Creating a separate Canvas to draw Python Logo
my_turtle_screen = turtle.Screen()

#  Creating a pause function to pause the cursor
def pause():
    my_turtle_cursor.speed(2)
    for i in range(100):
        my_turtle_cursor.left(90)



def draw_upper_dot_of_python_logo():
    my_turtle_cursor.penup()
    my_turtle_cursor.right(90)
    my_turtle_cursor.forward(160)
    my_turtle_cursor.left(90)
    my_turtle_cursor.forward(70)
    my_turtle_cursor.pencolor("white")
    my_turtle_cursor.dot(35)


def goto_second_position():
    my_turtle_cursor.penup()
    my_turtle_cursor.forward(20)
    my_turtle_cursor.right(90)
    my_turtle_cursor.forward(10)
    my_turtle_cursor.right(90)
    my_turtle_cursor.pendown()


def half():
    my_turtle_cursor.forward(50)
    draw_side_curve_of_python_logo()
    my_turtle_cursor.forward(90)
    draw_first_left_curve_of_python_logo()
    my_turtle_cursor.forward(40)
    my_turtle_cursor.left(90)
    my_turtle_cursor.forward(80)
    my_turtle_cursor.right(90)
    my_turtle_cursor.forward(10)
    my_turtle_cursor.right(90)
    my_turtle_cursor.forward(120)  # on test
    draw_second_left_curve_of_python_logo()
    my_turtle_cursor.forward(30)
    my_turtle_cursor.left(90)
    my_turtle_cursor.forward(50)
    draw_right_curve_of_python_logo()
    my_turtle_cursor.forward(40)
    my_turtle_cursor.end_fill()


def draw_lower_dot_of_python_logo():
    my_turtle_cursor.left(90)
    my_turtle_cursor.penup()
    my_turtle_cursor.forward(310)
    my_turtle_cursor.left(90)
    my_turtle_cursor.forward(120)
    my_turtle_cursor.pendown()

    my_turtle_cursor.dot(35)


def draw_first_left_curve_of_python_logo():
    draw_side_curve_of_python_logo()
    my_turtle_cursor.forward(80)
    draw_side_curve_of_python_logo()


def draw_second_left_curve_of_python_logo():
    draw_side_curve_of_python_logo()
    my_turtle_cursor.forward(90)
    draw_side_curve_of_python_logo()


def draw_side_curve_of_python_logo():
    for i in range(90):
        my_turtle_cursor.left(1)
        my_turtle_cursor.forward(1)


def draw_right_curve_of_python_logo():
    for i in range(90):
        my_turtle_cursor.right(1)
        my_turtle_cursor.forward(1)


# Setting The configuration of our cursor according to our needs
my_turtle_cursor.pensize(2)
my_turtle_cursor.speed(10)
my_turtle_cursor.pensize(2)
my_turtle_cursor.pencolor("black")

# We have changed background color of canvas
my_turtle_screen.bgcolor("white")

# Setting the fill color of upper part python logo
my_turtle_cursor.fillcolor("#306998")

# Starting to fill color of upper part of python logo
my_turtle_cursor.begin_fill()

half()

# Stooping the cursor to fill color in upper part of python logo
my_turtle_cursor.end_fill()

goto_second_position()

# Setting the fill color of lower part of python logo
my_turtle_cursor.fillcolor("#FFD43B")
my_turtle_cursor.begin_fill()

half()

# Stooping the cursor to fill color in lower part of python logo
my_turtle_cursor.end_fill()

# Drawing upper and lower dots of python logo
draw_upper_dot_of_python_logo()
draw_lower_dot_of_python_logo()
pause()

Output for Python Logo using Turtle

Our code is complete, and we finally run it to see a Python logo.

After running the code, it will open a new window and begin generating the Python logo; after completed, the result should look like this.

We hope this article on Draw Python Logo Using Turtle Library Helps you.

Thank you for reading this article, click here to start learning Python in 2022.


Also Read:

Share:

Author: Ayush Purawr