To draw a circle in Python, we can use the circle() function from the Python turtle module.

import turtle

t = turtle.Turtle()

def draw_circle(radius):
    t.circle(radius)

draw_circle(100)

The turtle module in Python allows us to create graphics easily in our Python code.

We can use the turtle module to make all sorts of shapes in Python. For example, we can draw rectangles and draw triangles easily in Python with the turtle module.

One other shape which is easy to draw with turtle is a circle.

The defining feature of a circle is the radius. To draw a circle in Python, we can use the turtle circle() function from the turtle module.

We can define a simple function which will take one argument, the radius of our circle, and make the circle.

Below is a simple example of how to use Python to create a circle.

import turtle

t = turtle.Turtle()

def draw_circle(radius):
    t.circle(radius)

draw_circle(100)

turtle circle

Cool Patterns You Can Make With circle() in Python

There are a few cool patterns you can create with the Python turtle circle() function.

One example is a spiral.

Below is the Python code for creating a spiral, and the output of the spiral with the turtle module.

import turtle
    
t = turtle.Turtle()
  
def draw_spiral(starting_radius, loops):
    for i in range(0, loops):
        t.circle(starting_radius + i, 60)      

draw_spiral(10, 100)

turtle spiral

You can also make concentric circles easily with the circle() function. To make concentric circles, we make circles starting in the middle, and keep increasing the radius until the end.

Below is the Python code for creating concentric circles.

import turtle
    
t = turtle.Turtle()
  
def draw_concentric_circles(starting_radius, loops):
    for i in range(0, loops):
        t.circle(starting_radius*i)  
        t.up()
        t.sety((starting_radius *i)*(-1))
        t.down()    

draw_concentric_circles(10, 25)

turtle concentric circles

How to Draw a Circle with Different Colors in Python

With turtle, we can easily add color to the shapes we create.

The main function you can use to change the color of a line is with the turtle pencolor() function.

Below is an example and the output of how to draw a green circle using pencolor() in Python.

import turtle

t = turtle.Turtle()

t.pencolor("green")

t.circle(50)

turtle color green circle

To fill a shape, there are a few steps to take. We use the fillcolor() function to define the fill color of our shape, and then use the begin_fill() and end_fill() functions to define when to begin and end filling shapes with the fill color.

Below is an example and the output of how to fill a circle with the color ‘blue’ using fillcolor(), begin_fill() and end_fill() in Python.

import turtle

t = turtle.Turtle()

t.fillcolor("blue")

t.begin_fill()

t.circle(50)

t.end_fill()

turtle fill color blue circle

Hopefully this article has been helpful for you to learn how to draw a circle in Python.

Categorized in:

Python,

Last Update: March 1, 2024