Triangular Spiral¶
By the end of this lab you'll be able to:
- Use
right(120)to create a triangular spiral with sharp equilateral corners - Color each third of the spiral a different warm color using integer division
- Understand how
i // ngroups segments into color bands rather than cycling segment-by-segment
Three warm color bands — red, orange, and gold — sweep outward along the arms of a tight triangular spiral. Change one number and the entire character of the shape changes.
Welcome to the Triangular Spiral!
We've seen square spirals (90°) and hexagonal spirals (60°). Now push the angle further —
120° gives the sharpest corners yet. Let's code it together!
How It Works¶
An equilateral triangle has interior angles of 60° and exterior angles of 120° (360° ÷ 3 = 120°). Turning 120° at every step gives the spiral triangular corners.
For coloring, (i // 60) % 3 divides the 180-step loop into three equal thirds and picks a color for each third. Integer division (//) groups segments together instead of cycling one-by-one.
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
What Do You Think Will Happen?
The square spiral had 4 sides per revolution and the hexagonal had 6.
How many sides per revolution does the triangular spiral have?
Make your guess — then click Run to find out!
Try It Now¶
3 sides per revolution — one per 120° turn. The spiral makes crisp triangular corners. Were you right?
How It Works¶
(i // 60) % 3 works like this: for the first 60 steps, i // 60 = 0, so color 0 (crimson). For steps 60–119, i // 60 = 1, so color 1 (orange). For steps 120–179, color 2 (gold). This creates solid bands along the spiral arms rather than segment-by-segment flickering.
Explanation Table¶
| Line | What it does |
|---|---|
colors = [...] |
Three warm hues — one per third of the loop |
(i // 60) % 3 |
Groups 60 segments into each color band |
monty.right(120) |
Triangular corner — 360° ÷ 3 = 120° |
step += 1.5 |
Grow the step each segment |
range(180) |
180 steps = 60 full "triangles" (3 sides each) |
Learning Check¶
Your Turn — Switch to Per-Segment Colors
Change (i // 60) % 3 to i % 3. Now each individual segment cycles through
the three colors. Predict how it will look different — then run it to check!
With i % 3, each side of each tiny triangle gets its own color — creating a striped, segment-by-segment pattern. The i // 60 version gives broader color bands across entire spiral arms.
Experiments¶
-
Try 4 colors with
i // 45. Use['red','orange','gold','yellow']and(i // 45) % 4. You'll know it worked when the spiral has four distinct color regions. -
Make it spin the other way. Change
right(120)toleft(120). You'll know it worked when the spiral winds in the opposite direction. -
Double the growth speed. Change
step += 1.5tostep += 3. The gaps between arms widen dramatically. You'll know it worked when only 2–3 revolutions fit on screen. -
Start from a large step. Change
step = 2tostep = 40. The spiral begins already expanded. You'll know it worked when the first few loops are already wide.
Sharp Thinking!
You discovered two ways to color a spiral: i % n for segment-by-segment patterns,
and i // n for broad color bands. The same trick works in any loop!
Up next: Inward Collapsing Spiral — spiraling to a point instead of growing outward.