Circle of Squares using Python Turtle

The Circle of Squares is a fascinating geometric pattern that can be created using Python's turtle graphics library. This pattern consists of a circle of squares that are evenly spaced around its circumference, with each square rotated at an angle relative to the previous square. This creates a mesmerizing visual effect that can be customized to suit any color scheme or size.

In this tutorial, we will explore how to create the Circle of Squares pattern using Python's turtle library, step by step. We will also discuss different customization options that can be applied to create unique variations of the pattern.

Creating the Circle of Squares Pattern

Here's how to create the Circle of Squares pattern using Python's turtle graphics library ?

Step-by-Step Breakdown

First, import the turtle graphics library ?

import turtle

# Create a turtle object and set its speed
t = turtle.Turtle()
t.speed('fastest')

Set the initial position and drawing parameters ?

import turtle

t = turtle.Turtle()
t.speed('fastest')

# Set initial position
t.penup()
t.goto(0, 250)
t.pendown()

# Pattern parameters
radius = 45
angle = 10

print("Starting position:", t.position())
Starting position: (0.00, 250.00)

Complete Circle of Squares Code

Here's the complete implementation that creates 36 squares arranged in a circle ?

import turtle

# Setup the turtle
t = turtle.Turtle()
t.speed('fastest')

# Move to starting position
t.penup()
t.goto(0, 250)
t.pendown()

# Pattern parameters
radius = 45
angle = 10

# Draw 36 squares in a circle
for i in range(36):
    # Draw a square
    for j in range(4):
        t.forward(50)
        t.right(90)
    
    # Move to next square position
    t.penup()
    t.right(angle)
    t.forward(radius)
    t.pendown()

# Clean up
t.hideturtle()
turtle.done()

How It Works

The algorithm creates a circular arrangement of squares using these key components:

  • Outer loop: Iterates 36 times (360° ÷ 10° = 36 squares)

  • Inner loop: Draws each square by moving forward 50 pixels and turning right 90°

  • Position update: After each square, the turtle rotates 10° and moves forward by the radius to position for the next square

  • Pen control: Uses penup() and pendown() to move without drawing lines between squares

Customization Options

You can customize the pattern by modifying these parameters ?

import turtle

t = turtle.Turtle()
t.speed('fastest')
t.penup()
t.goto(0, 200)
t.pendown()

# Customized parameters
radius = 60        # Distance between squares
angle = 15         # Rotation angle (360/15 = 24 squares)
square_size = 30   # Size of each square
num_squares = 24   # Number of squares

# Different colors for variation
colors = ['red', 'blue', 'green', 'orange', 'purple', 'yellow']

for i in range(num_squares):
    t.color(colors[i % len(colors)])
    
    # Draw square
    for j in range(4):
        t.forward(square_size)
        t.right(90)
    
    # Move to next position
    t.penup()
    t.right(angle)
    t.forward(radius)
    t.pendown()

t.hideturtle()
turtle.done()

Parameters Summary

Parameter Purpose Effect
radius Distance from center Larger values create bigger circles
angle Rotation between squares Smaller angles = more squares
square_size Side length of squares Controls individual square size

Conclusion

The Circle of Squares pattern demonstrates how simple geometric shapes can create complex visual patterns. By adjusting parameters like radius, angle, and colors, you can create unique variations limited only by your creativity.

Updated on: 2026-03-27T14:34:48+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements