Inward Collapsing Spiral¶
By the end of this lab you'll be able to:
- Create a spiral that converges to a point by decreasing the step length each iteration
- Color segments from bright blue at the outside to white at the center using a fade list
- Understand the difference between increasing sequences (outward) and decreasing sequences (inward)
Instead of growing outward, this spiral collapses inward — starting wide and converging to a near-invisible point at the center. Segments fade from deep blue on the outside to near-white as the spiral tightens to a point.
Welcome to the Inward Spiral!
All the spirals so far grew outward. Now we run the same idea in reverse —
start big and shrink toward zero. Let's code it together!
How It Works¶
The step starts large (at 200) and decreases by a small amount each iteration. When step reaches 0 the path has converged to a point. A color list fades from dark blue through lighter shades to near-white, so the outer segments look bolder and the inner ones fade away.
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
What Do You Think Will Happen?
The step starts at 200 and decreases by 1 each iteration. The loop uses right(91) —
slightly more than 90°. Will the spiral wind clockwise or counterclockwise?
Make your guess — then click Run to find out!
Try It Now¶
The spiral winds clockwise because right() turns clockwise. The 91° angle — just 1° past a right angle — makes the path drift slightly so the loops don't overlap exactly. Were you right?
How It Works¶
while step > 1 runs until the step becomes too small to matter. Each iteration step -= 1 shrinks the path segment — opposite of step += n in the outward spirals.
min(i // 25, len(colors) - 1) maps iteration index to a color but clamps it so we never go past the last color in the list, even if the loop runs longer than expected.
Explanation Table¶
| Line | What it does |
|---|---|
step = 200 |
Start with a long segment |
while step > 1 |
Keep going until segments are tiny |
step -= 1 |
Shrink by 1 pixel each step — creates the inward spiral |
right(91) |
Slightly more than 90° — prevents loops from sitting exactly on top of each other |
min(i // 25, len(colors) - 1) |
Advance color every 25 steps, clamped at the list end |
Learning Check¶
Your Turn — Change the Convergence Rate
The spiral currently decreases by 1 per step. Change step -= 1 to step -= 2.
Predict how the spiral will change — then run it to see if you were right!
With step -= 2 the spiral converges twice as fast — it reaches the center in half the steps, so there are fewer revolutions and the loops are spaced further apart.
Experiments¶
-
Try
right(89). One degree less than 90° winds the spiral in the opposite rotational direction. You'll know it worked when the loops tilt the other way. -
Start even larger. Change
step = 200tostep = 300. More revolutions fit before convergence. You'll know it worked when the spiral takes up more of the canvas. -
Use warm colors. Replace the blues with
['darkred', 'red', 'orangered', 'orange', 'gold', 'yellow', 'lightyellow', 'white']. You'll know it worked when the spiral shifts from deep red to pale yellow. -
Make it hexagonal. Change
right(91)toright(61). You'll know it worked when the corners look more rounded.
Brilliant!
You saw the same spiral rule work in both directions — outward AND inward —
just by switching += to -=. Convergence is just divergence in reverse!
Up next: Colored Logarithmic Spiral — using trigonometry to draw a truly curved spiral.