Anti-Koch Snowflake¶
By the end of this lab you'll be able to:
- Modify the Koch rule to bump inward instead of outward on alternate levels
- See how one sign change in a fractal rule produces dramatically different shapes
- Understand the concept of rule alternation in recursive systems
While the Koch snowflake always bumps outward, the Anti-Koch alternates: even depths bump out, odd depths bump in. The result is a shape with both spiky tips and concave notches.
Welcome to the Anti-Koch Snowflake!
You've seen the Koch curve bump outward at every level. What if we flipped the
direction on every other level? One sign change gives a completely different fractal!
Let's code it together!
How It Works¶
antikoch(n, depth, direction):
- direction = 1 → bump outward (left 60°, left 60°, left 60°, then right 120° between)
- direction = -1 → bump inward (the angles are negated)
On each recursive call, direction flips: direction * -1.
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 24 25 26 | |
What Do You Think Will Happen?
The standard Koch always bumps outward, giving a purely spiky shape.
The Anti-Koch alternates directions. Will it look more rounded, or more jagged?
Make your guess — then click Run to find out!
Try It Now¶
The alternating bumps create a shape with both inward notches AND outward spikes — more complex than the pure Koch because both directions appear. Were you right?
How It Works¶
60 * direction makes the turn angle positive (left) when direction = 1 and negative (right = inward) when direction = -1. Passing -direction to each recursive call flips the direction at every level, so even-depth segments bump one way and odd-depth segments bump the other.
Explanation Table¶
| Line | What it does |
|---|---|
direction parameter |
1 = bump outward, -1 = bump inward |
monty.left(60 * direction) |
Positive direction = left; negative = right |
antikoch(n3, depth-1, -direction) |
Flip direction at each recursive level |
| Same structure as Koch | The bump shape is identical — just mirrored |
Learning Check¶
Your Turn — Always Bump Inward
What if you never flipped — always passed -1 as direction?
Change antikoch(300, 4, 1) to antikoch(300, 4, -1) and the initial direction to always inward.
Predict how it differs from the standard Koch — then run it!
Always-inward bumps (direction = -1 throughout) creates a Koch snowflake that grows inward — the bumps notch into the triangle instead of radiating outward.
Experiments¶
-
Compare side by side. Run the standard Koch first (left(60), right(120), left(60)) then the Anti-Koch. You'll know it worked when you can see both shapes.
-
Depth 2 comparison. Try both with
depth=2to see the bumps clearly. You'll know it worked when individual bumps and notches are visible. -
Change the color. Try
pencolor('darkcyan'). You'll know it worked when the curve turns teal. -
Fill the snowflake. Add
begin_fill()before the loop andend_fill()after. You'll know it worked when the interior is filled.
Category 4 Complete!
You've completed 15 fractal patterns — Koch, Sierpiński, Dragon, Hilbert, Barnsley, and more!
Fractals show that infinite complexity emerges from simple recursive rules.
Up next: Category 5 — Symmetry and Tiling!