Expanding Hexagons¶
By the end of this lab you'll be able to:
- Draw concentric hexagons that grow outward from the center
- Rotate alternating hexagons 30° to create a more complex illusion
- Understand how color gradients enhance the sense of depth and motion
Concentric hexagons, alternating between two rotations — 0° and 30°. The color gradient from dark center to light edges creates a strong illusion of a hexagonal tunnel or a surface expanding toward you.
Welcome to Expanding Hexagons!
Hexagons tile perfectly — six around each center, all fitting without gaps.
Concentric hexagons with alternating rotations create a dizzying depth illusion!
Let's code it together!
How It Works¶
Draw n concentric regular hexagons. Each hexagon is centered at the origin, with radius increasing by a fixed step. Odd-numbered hexagons are rotated 30° from even ones. Colors fade from dark navy at the center to light blue at the edge.
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
What Do You Think Will Happen?
Alternating hexagons at 0° and 30° — will they look like separate shapes or a unified pattern?
Make your guess — then click Run to find out!
Try It Now¶
A hexagonal tunnel — the alternating rotation and color gradient create a strong sense of depth. Were you right?
How It Works¶
The inner hexagons are drawn with thicker lines (more prominent), the outer ones with thinner lines. The color gradient from dark (center) to light (edge) reinforces the tunnel illusion — objects further away appear lighter. The 30° alternation prevents the simple "telescope" look and creates star-like complexity.
Explanation Table¶
| Line | What it does |
|---|---|
rotation = 30 if i%2==0 else 0 |
Alternate 0° and 30° rotations |
t = i / n_hexagons |
Progress from 0 (center) to 1 (edge) |
int(30 + 200 * t) |
Blue value increases toward edge |
pensize(...) // 2 |
Thick inner, thin outer lines |
Learning Check¶
Your Turn — Try Pentagons
Change range(6) to range(5) and left(60) to left(72) in the inner loop.
Predict: will 5-sided pentagons create a similar illusion?
Concentric pentagons with 36° alternation — a pentagonal tunnel, less symmetric than hexagons but equally hypnotic.
Experiments¶
-
Remove the rotation alternation. Set
rotation = 0always. You'll know it worked when all hexagons align and the star-pattern disappears. -
Try triangles. Change to 3 sides,
left(120),rotation = 60. You'll know it worked when nested triangles appear. -
Use a warm color gradient. Change the color to red/orange:
pencolor(int(50+200*t), int(100*t), 0). You'll know it worked when the tunnel looks like glowing embers. -
Increase n_hexagons. Try
n_hexagons = 20. You'll know it worked when the tunnel extends much further inward.
Hexagonal Hypnosis!
You created a geometric optical illusion using only concentric hexagons!
Op Art proves that math, color, and repetition can fool the visual system.
Up next: Category 9 — Typography Patterns!