Python Turtle Dot: How to Create Colorful Dots in Graphics

I was working on a Python project with my students where we needed to create an interactive visual representation of the US electoral map. The challenge was to represent each state with dots of varying sizes and colors. That’s when I turned to Python’s Turtle module and its dot() function.

The Turtle module is one of Python’s most beginner-friendly graphics libraries, and the dot function is an incredibly versatile tool for creating visual elements. In this article, I will show you how to use the Turtle dot method to create everything from simple dots to complex patterns.

So let’s start!

Turtle Dot Method

The Turtle dot method allows you to draw filled circles (dots) of different sizes and colors at the current turtle position. Unlike drawing a circle and filling it, the dot method creates a solid circular shape in a single command.

Here’s the basic syntax:

turtle.dot(size, color)

Both parameters are optional:

  • size: The diameter of the dot in pixels (default is the pen size + 4)
  • color: The color of the dot (default is the current pen color)

Read Python Turtle Mouse

Method 1: Basic Dot Creation

Let’s start with the simplest use of the dot method. Here’s how to create a basic dot:

import turtle

# Create a turtle screen and turtle object
screen = turtle.Screen()
t = turtle.Turtle()

# Speed up the drawing
t.speed(0)

# Draw a dot
t.dot(20, "red")

# Keep the window open
turtle.done()

You can refer to the screenshot below to see the output.

how to make a dashed line in python turtle

This code creates a simple red dot with a diameter of 20 pixels. It’s that easy!

When I’m teaching beginners, I often start with this example to show how quickly you can create visual elements with minimal code.

Check out Python Turtle Draw Letters

Method 2: Create Multiple Dots

Now, let’s create multiple dots in different positions:

import turtle

screen = turtle.Screen()
t = turtle.Turtle()
t.speed(0)
t.hideturtle()  # Hide the turtle icon

# Draw dots in different positions
colors = ["red", "blue", "green", "purple", "orange"]
positions = [(0, 0), (50, 50), (-50, 50), (-50, -50), (50, -50)]

for i in range(5):
    t.penup()
    t.goto(positions[i])
    t.pendown()
    t.dot(30, colors[i])

turtle.done()

You can refer to the screenshot below to see the output.

python turtle dot

I’ve used this pattern many times when creating data visualizations. It’s perfect for scatter plots or any visual where you need to represent data points.

Read Python Turtle Input

Method 3: Create a Dotted Line

The dot method can also be used to create dotted lines:

import turtle

screen = turtle.Screen()
t = turtle.Turtle()
t.speed(0)
t.hideturtle()

# Create a dotted line
t.penup()
t.goto(-150, 0)

for i in range(30):
    t.dot(10, "navy")
    t.forward(10)

turtle.done()

You can refer to the screenshot below to see the output.

turtle dot

This creates a line of 30 navy blue dots, each with a diameter of 10 pixels and spaced 10 pixels apart.

I’ve found this technique particularly useful when creating borders or boundaries in maps and diagrams.

Check out the Python Turtle Pen

Method 4: Create Dot Patterns

Let’s create a more complex pattern using dots of varying sizes:

import turtle
import random

screen = turtle.Screen()
screen.bgcolor("black")
t = turtle.Turtle()
t.speed(0)
t.hideturtle()

# Create a spiral pattern of dots
colors = ["red", "gold", "cyan", "magenta", "green", "white"]

for i in range(180):
    color = random.choice(colors)
    size = random.randint(5, 20)

    t.penup()
    t.forward(i)
    t.right(45)
    t.pendown()

    t.dot(size, color)

turtle.done()

This code creates a spiral pattern of randomly colored and sized dots against a black background. It’s a great way to demonstrate both the dot method and some basic algorithmic art.

When teaching more advanced concepts, I use examples like this to show how simple commands can create complex and beautiful patterns.

Method 5: Create an Interactive Dot Game

Here’s a fun interactive example, a simple dot-clicking game:

import turtle
import random

screen = turtle.Screen()
screen.title("Dot Clicker Game")
screen.setup(600, 600)
t = turtle.Turtle()
t.hideturtle()
t.speed(0)

score = 0
game_over = False

# Create a function to draw a random dot
def draw_dot():
    if not game_over:
        t.clear()
        x = random.randint(-250, 250)
        y = random.randint(-250, 250)
        size = random.randint(20, 50)

        t.penup()
        t.goto(x, y)
        t.dot(size, "red")

        # Return the position and size for hit detection
        return x, y, size
    return None, None, None

# Create a function to update score
def update_score():
    score_turtle.clear()
    score_turtle.write(f"Score: {score}", align="center", font=("Arial", 16, "normal"))

# Create a turtle for displaying the score
score_turtle = turtle.Turtle()
score_turtle.hideturtle()
score_turtle.penup()
score_turtle.goto(0, 260)
update_score()

# Function to handle clicks
def on_click(x, y):
    global score, game_over, dot_info

    if game_over:
        return

    dot_x, dot_y, dot_size = dot_info

    # Calculate distance from click to dot center
    distance = ((x - dot_x)**2 + (y - dot_y)**2)**0.5

    # If click is inside the dot
    if distance <= dot_size/2:
        score += 1
        update_score()
        dot_info = draw_dot()

    # End game after 10 successful clicks
    if score >= 10:
        game_over = True
        t.clear()
        t.goto(0, 0)
        t.write("Game Over!", align="center", font=("Arial", 24, "bold"))

# Draw the first dot and store its info
dot_info = draw_dot()

# Set up the click listener
screen.onclick(on_click)

turtle.done()

This creates a simple game where players click on randomly appearing dots to earn points. I’ve used this in classrooms to demonstrate how the Turtle module can be used for interactive applications.

Read Python Turtle Grid

Use the Dot Method for Data Visualization

One practical application I’ve used is visualizing population data for major US cities:

import turtle

screen = turtle.Screen()
screen.setup(800, 500)
screen.title("US Major Cities Population Visualization")

# Load background US map image (you would need to have this image)
screen.bgpic("us_map.gif")

t = turtle.Turtle()
t.hideturtle()
t.speed(0)

# Population data for major US cities (city, coordinates, population in millions)
cities = [
    ("New York", (200, 60), 8.8),
    ("Los Angeles", (-350, 0), 4.0),
    ("Chicago", (100, 100), 2.7),
    ("Houston", (50, -50), 2.3),
    ("Phoenix", (-250, 0), 1.7),
    ("Philadelphia", (220, 80), 1.6),
    ("San Antonio", (0, -75), 1.5),
    ("San Diego", (-330, -30), 1.4),
    ("Dallas", (50, -30), 1.3),
    ("San Jose", (-330, 50), 1.0)
]

# Create a legend
legend = turtle.Turtle()
legend.hideturtle()
legend.penup()
legend.goto(280, 200)
legend.write("Population (millions):", font=("Arial", 10, "bold"))
legend.goto(280, 180)
legend.dot(30, "red")
legend.goto(310, 180)
legend.write("> 5", font=("Arial", 10, "normal"))
legend.goto(280, 150)
legend.dot(20, "orange")
legend.goto(310, 150)
legend.write("2-5", font=("Arial", 10, "normal"))
legend.goto(280, 120)
legend.dot(10, "blue")
legend.goto(310, 120)
legend.write("< 2", font=("Arial", 10, "normal"))

# Plot each city
for city, coords, population in cities:
    t.penup()
    t.goto(coords)

    # Size and color based on population
    if population > 5:
        size = 30
        color = "red"
    elif population > 2:
        size = 20
        color = "orange"
    else:
        size = 10
        color = "blue"

    # Draw the dot
    t.dot(size, color)

    # Label the city
    t.goto(coords[0], coords[1] - 15)
    t.write(city, align="center", font=("Arial", 8, "normal"))

turtle.done()

This code creates a visualization where major US cities are represented by dots whose size and color correspond to their population. I’ve used this when teaching data visualization concepts to demonstrate how graphical elements can represent numerical data.

I hope you found this article helpful! The Turtle dot method might seem simple at first, but as we’ve seen, it can be used in a variety of creative and practical ways. Whether you’re teaching programming to beginners, creating data visualizations, or just having fun with graphics, the dot method is a valuable tool in your Python toolkit.

Other Python articles you may also like:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.