Drawing Patterns and Designs Jump to this section
This lesson combines loops and variables to create patterns: spirals, radial designs, and symmetric art.
A simple spiral Jump to this section
import turtle
t = turtle.Turtle()
length = 5
for i in range(60):
t.forward(length)
t.left(20)
length += 3
The length increases each step, creating a spiral. The small left turn makes the curve.
length += 3 means the same thing as length = length + 3
Radial pattern (repeat rotated shape) Jump to this section
import turtle
t = turtle.Turtle()
t.speed(8)
for i in range(12):
for _ in range(6):
t.forward(50)
t.left(60)
t.left(30)
This draws a hexagon 12 times, rotating a bit between each copy to make a flower-like design.
Colorful pattern using variables Jump to this section
import turtle
colors = ['blue','green','purple','lightblue','seagreen','mediumpurple']
t = turtle.Turtle()
t.speed(10)
for i in range(36):
t.pencolor(colors[i % len(colors)]) # cycle through the different colors
t.forward(100)
t.left(170)
This uses a list of colors and cycles through them while drawing a spirograph-like pattern.
colors[i % len(colors)] cycles through the different colors in the colors list based on the count of the for loop. See the Python Beginner Course to learn more about how lists, operators (such as %), and for loops work.
Exercise Jump to this section
- Play around with the lengths and angles; try to create your own unique pattern.
