• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • VBA
  • About
You are here: Home / Python / Draw Circle in Python Using turtle circle() Function

Draw Circle in Python Using turtle circle() Function

February 22, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  Python divmod() Function – Get Quotient and Remainder After Division
  • 2.  Get Days in Month Using Python
  • 3.  Check if Variable is Integer in Python
  • 4.  Keep Every Nth Element in List in Python
  • 5.  Sign Function in Python – Get Sign of Number
  • 6.  List of Turtle Shapes in Python
  • 7.  Concatenate Multiple Files Together in Python
  • 8.  pandas nsmallest – Find Smallest Values in Series or Dataframe
  • 9.  Remove Last Element from List Using Python
  • 10.  Perfect Numbers in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2022 · The Programming Expert · About · Privacy Policy