Spiral Text¶
By the end of this lab you'll be able to:
- Use
turtle.write()to place text at computed positions - Place characters along a spiral path using polar coordinates
- Understand how
setheading()makes each character face the right direction
Each character of a message is placed along an outward spiral, rotated to face tangentially along the curve. The result is text that winds around the center like a snail shell.
Welcome to Spiral Text!
turtle.write() can place any text at the turtle's current position.
This lab combines that with spiral math to spell out a message in a spiral!
Let's code it together!
How It Works¶
Place characters of a message one at a time. For character i, the spiral radius grows with i and the angle advances by a fixed step. setheading() aligns each character tangentially to the spiral direction.
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
What Do You Think Will Happen?
Each character is placed at increasing radius and rotated to face the spiral direction.
Will the characters look like a readable spiral, or just scattered letters?
Make your guess — then click Run to find out!
Try It Now¶
The message spirals outward — each character faces tangentially to the spiral curve. Were you right?
How It Works¶
heading = (i * angle_step + 90) % 360 adds 90° to the radial direction because setheading(0) points right (radial direction). Adding 90° makes the turtle face tangentially (along the spiral). math.cos(angle), math.sin(angle) converts polar to Cartesian for positioning.
Explanation Table¶
| Line | What it does |
|---|---|
enumerate(message) |
Gives both index i and character ch |
r = r_start + i * r_step |
Radius grows linearly — Archimedean spiral |
heading = (i * angle_step + 90) % 360 |
Tangential direction — perpendicular to radius |
monty.write(ch, font=...) |
Place single character at turtle's position |
Learning Check¶
Your Turn — Change the Message
Change the message to your name repeated several times.
Predict: will the spiral look different with a shorter or longer message?
Rainbow-colored spiral text — each character gets a cycling color for a more festive effect.
Experiments¶
-
Tighter spiral. Decrease
angle_stepto 10. You'll know it worked when more revolutions of the spiral fit in the canvas. -
Larger font. Change
font=('Arial', 10, 'bold')tofont=('Arial', 14, 'bold')and increaser_step = 4. You'll know it worked when larger letters appear. -
Logarithmic spiral. Replace
r = r_start + i * r_stepwithr = 10 * math.exp(0.06 * i). You'll know it worked when the characters space out faster near the outside. -
Reverse the spiral. Change
angle_stepto negative. You'll know it worked when the spiral winds clockwise instead of counter-clockwise.
Typography in Motion!
You combined polar coordinates with turtle.write() to create spiral text!
This technique is used in logo design and artistic typography.
Up next: Seven-Segment Display — digital numbers from line segments.