Lévy C-Curve Fractal

On this page, you will use recursion to draw the Lévy C-curve.

Lévy is pronounced lay-VEE.

As in the snowflake algorithm, the base case for the Lévy C-curve is a single line segment:
Lévy C-Curve Level 1: just a straight line segment C-curve, level: (1) size: (150)

At each next level, the algorithm draws two copies of the previous level, some percentage of the length of the previous level, and arranged in a right angle as shown below. (As before, the red shows a smaller version of the previous level.) You'll have to figure out how much smaller the size input should be in the recursive calls.
Lévy C-Curve Level 2: segment broken into two segments that meet at a right angle in the middle C-curve, level: (2) size: (150)

  1. Talk with Your Partner The original line is replaced by two other lines. Together, the three would form a right triangle with the original line as the hypotenuse. Given that, what are the lengths of the legs (the two lines shown)?
    Click for a hint.

    If the hypotenuse (the base case length) is size, what length must be given to the recursive call? Need another hint?

    Use the Pythagorean formula: a^2 + b^2 = c^2.

In the third level, the sprite again replaces each straight line with a pair of lines for a total of four smaller lines. Notice that the second and third lines form one long line. The red color here makes that visible. Your version should be all one color for now.
Lévy C-Curve Level 3: two short sides and one long side of a rectangle formed C-curve, level: (3) size: (150)

This simple algorithm builds up a complicated design at higher levels:
Lévy C-Curve Level 4 C-curve, level: (4) size: (150)

  1. Develop a program that draws a Lévy C-Curve, and save it as "U7L2-LevyCCurve".

    Need a hint?

    Look at the difference between the level 2 curve and the level 3 curve. Need another hint?

    To make the level 3 curve, you must turn left (how much?), recursively draw a smaller level 2 curve (how much smaller?), turn again (which way? how much?), recursively draw another smaller level 2 curve, and then turn left.

    What should your curve look like?

    At level 12, the Levy C-curve shape will look like this:
    level 12 Lévy C-Curve drawing

  1. Changing the angles lets you create interesting variations on the Lévy C-Curve. Try some ideas of your own.
    Lévy C-Curve-like drawing