More Space Filling Curves…

Recently I completed a small project related to the Hilbert curve. So I have been a bit interested in space filling curves since then. Hence I decided to create implementations of three of the more famous ones out there, that is the Sierpinski curve, the Sierpinski arrowhead curve, and the Gosper curve.

I am really hoping that these recent fractal projects (including those on the Hilbert curve, bifurcation diagrams, the chaos game, along with this one) have gotten the fractal out of my system at least for a little while. However, I am sure I will eventually return back to the fractal world. At least my current fractal addiction isn’t as bad as my old font collecting addiction.

Sierpinski Arrowhead Curve

While writing code for the Hilbert curve I came across a few references to the Sierpinski arrowhead curve. Basically, the previous code for the Hilbert curve can be modified a bit to produce this new fractal. The code isn’t that great but was ok enough to produce some results; the main thing about the so-so code was motivation to learn of a new way to draw such curves in the future.

Below are implementations of the Sierpinski arrowhead curve after 8 iterations on the left, and the first 6 iterations on the right.

There are more than a few different instances of the Sierpinski arrowhead curve out there. These ones amused me a bit:

Sierpinski Curve

So while making the previous curve, I realized that there is a more efficient way to code these things. Hence, I made the jump to creating fractals with L-systems. To be honest I was always a little confused with them at first and would just skip over when I saw them mentioned, but after a moment writing some code they actually fun to deal with.

So the Sierpinski curve can be implemented using the following L-system:

\begin{aligned} \mathsf{Alphabet} &: F, G, X \\ \mathsf{Constants} &: F, G, +, – \\ \mathsf{Axiom} &: F–XF–F–XF \\ \mathsf{Rule(s)} &: X \mapsto XF+G+XF–F–XF+G+X \\ \mathsf{Angle} &: 45^{\circ} \end{aligned}

Bellow are implementations of the Sierpinski curve after 7 iterations on the left, and the first 6 iterations on the right.

Some related links…

Gosper Curve

Getting into L-system based fractals, I was rather amused by the Gosper curve (or Gosper-Peano Curve). It is also called the flowsnake by some people out there.

The L-system for the Gosper curve is:

\begin{aligned} \mathsf{Alphabet} &: A, B \\ \mathsf{Axiom} &: A \\ \mathsf{Angle} &: 60^{\circ} \\ \mathsf{Rule(s)} &: A\mapsto A-B–B+A++AA+B- \\ &\hphantom{:\ \ } B\mapsto +A-BB–B-A++A+B \end{aligned}

Below are implementations of the Gosper curve, with the results after 5 iterations on the left and the first 4 iterations on the right.

Some interesting links that I stumbled over:

Code Implementations

The code for this project is available here and here.

 

No Comments

Add your comment