Function Repository Resource:

LevyCCurve

Source Notebook

Generate the Lévy C curve

Contributed by: Sander Huisman

ResourceFunction["LevyCCurve"][n]

generates the line segments of the Lévy C curve with n iterations.

ResourceFunction["LevyCCurve"][{p1,p2},n]

uses the line connecting the points p1 and p2 as the initial line.

ResourceFunction["LevyCCurve"][{p1,p2, ,pn},n]

uses the lines joining the points pi.

Details

The following transformation is done with each line segment:
The first four iterations and the ninth iteration:
ResourceFunction["LevyCCurve"][n] is equivalent to ResourceFunction["LevyCCurve"][{{-1,0},{1,0}},n].
The syntax ResourceFunction["LevyCCurve"][Line[{p1,p2, ,pn}],n] is also supported.

Examples

Basic Examples (2) 

Generate the Lévy C curve for four iterations:

In[1]:=
ResourceFunction["LevyCCurve"][4]
Out[1]=

Generate the line for eight iterations and visualize the result:

In[2]:=
Graphics[ResourceFunction["LevyCCurve"][8]]
Out[2]=

Scope (1) 

Start from a vertical line segment:

In[3]:=
Graphics[ResourceFunction["LevyCCurve"][Line[{{0, 0}, {0, 1}}], 8]]
Out[3]=

Properties and Relations (1) 

The length of the Lévy C curve grows approximately exponentially:

In[4]:=
ListLogPlot[
 Table[Length[First[ResourceFunction["LevyCCurve"][k]]], {k, 0, 9}], Joined -> True]
Out[4]=

Neat Examples (2) 

"Inward" and "outward" Lévy C curve starting from a square:

In[5]:=
Graphics[{ResourceFunction["LevyCCurve"][
   Line[{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}], 10], ResourceFunction["LevyCCurve"][
   Line[Reverse@{{3, 0}, {3, 1}, {4, 1}, {4, 0}, {3, 0}}], 10]}]
Out[5]=

Color the curve along its length:

In[6]:=
pts = First@ResourceFunction["LevyCCurve"][10];
colors = Blend[{Red, Blue, Green, Orange}, #] & /@ Subdivide[Length[pts] - 1];
Graphics[Line[pts, VertexColors -> colors]]
Out[6]=

Publisher

SHuisman

Version History

  • 1.0.0 – 22 October 2021

Related Resources

Author Notes

Code used for images in the Details and Option section:

In[1]:=
Graphics[{Text[Style["\[Rule]", 14], {0, 1/2}], RGBColor[0.`, 0.`, 0.5`], Translate[LevyCCurve[0], {-1.5, 0}], Translate[LevyCCurve[1], {1.5, 0}]}, ImageSize -> 200]
In[2]:=
Table[{Framed[
     Graphics[{RGBColor[0.`, 0.`, 0.5`], LevyCCurve[n]}, ImageSize -> {80, 60}], FrameStyle -> Directive[GrayLevel[0.75], Thickness[Tiny]]], Row[{Style["n", FontFamily -> "Times", FontSize -> 10, FontSlant -> Italic], Style[" = " <> ToString[n], FontFamily -> "Helvetica", FontSize -> 10]}]}, {n, {0, 1, 2, 3, 4, 9}}] // Transpose // Grid

License Information