Skip to content

Lévy C Curve

By the end of this lab you'll be able to:

  • Implement the Lévy C Curve using the same recursive structure as the Koch curve but with 45° angles
  • Compare how different replacement angles produce completely different fractal shapes
  • Understand how a fractal can tile the plane — the Lévy curve packs into itself perfectly

Each line segment is replaced by two equal segments forming a right-angled peak. After 14 iterations, the curve packs into a shape resembling a dragon's wing or a crinkled leaf.

Welcome to the Lévy C Curve!

Monty waving welcome You already know the Koch curve uses 60° bumps. The Lévy C uses 45° bumps — one small change that produces a completely different, tile-able fractal! Let's code it together!

How It Works

levy(n, depth): - If depth == 0: draw a line of length n - Otherwise: turn left 45°, recurse with n / √2, turn right 90°, recurse with n / √2, turn left 45°

The key difference from Koch: both recursive calls go in the same direction, making an upward peak. The angle is 45° instead of 60°.

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import turtle
import math
monty = turtle.Turtle()
monty.speed(0)
monty.hideturtle()
monty.pencolor('steelblue')

def levy(n, depth):
    if depth == 0:
        monty.forward(n)
        return
    n2 = n / math.sqrt(2)
    monty.left(45)
    levy(n2, depth - 1)
    monty.right(90)
    levy(n2, depth - 1)
    monty.left(45)

monty.penup()
monty.goto(-160, -60)
monty.pendown()
levy(320, 14)

What Do You Think Will Happen?

Monty thinking The Koch curve bumps outward in a triangle. The Lévy uses 45° bumps. Will the overall shape look more like a snowflake or a cloud? Make your guess — then click Run to find out!

Try It Now


  

More like a cloud or wing — the asymmetric 45° packing creates an irregular silhouette rather than a symmetric snowflake. Were you right?

How It Works

Each segment becomes two segments of length n / √2. Since (n/√2)^2 + (n/√2)^2 = n^2, the two sub-segments form a right isoceles triangle with hypotenuse n — the original segment length is preserved geometrically.

The repeated peak replacements pack densely without crossing — the Lévy C curve tiles the plane when copies are placed correctly.

Explanation Table

Line What it does
n / math.sqrt(2) Sub-segment length by Pythagorean theorem
monty.left(45) First rotation — forms the left leg of the peak
monty.right(90) Turn between the two sub-segments
monty.left(45) Restore original heading after the peak
depth == 0 Base case: draw a raw segment

Learning Check

Your Turn — Try Depth 8

Monty thinking Change levy(320, 14) to levy(320, 8). The curve will be much less detailed. Predict what it will look like at only 8 levels of substitution — then run it!


  

At depth 8 you can clearly see the individual V-shapes before they pack together. The full shape is recognizable but coarser.

Experiments

  1. Change the color. Try pencolor('darkviolet'). You'll know it worked when the curve turns purple.

  2. Use Koch comparison. Try the Koch rule (left(60), no right, etc.) on the same starting length to compare. You'll know it worked when you see the Koch shape instead.

  3. Thicker pen. Add monty.pensize(2) before the levy call. You'll know it worked when the curve lines are thicker and easier to see.

  4. Flip the curve. Start facing South (monty.setheading(270)) and adjust the starting position. You'll know it worked when the curve hangs downward like a stalactite.

Fractal Wings!

Monty celebrating You changed one angle (60° → 45°) and got a completely different fractal! That's the power of parametric thinking — small changes, huge impact. Up next: Gosper Curve — a fractal that tiles hexagonal space.