Gosper curve


The Gosper curve, also known as Peano-Gosper Curve, named after Bill Gosper, also known as the flowsnake, is a space-filling curve whose limit set is rep-7. It is a fractal curve similar in its construction to the dragon curve and the Hilbert curve.
The Gosper curve can be used also to efficient hierarchical hexagonal clustering and indexing.

Algorithm

Lindenmayer system

The Gosper curve can be represented using an L-system with rules as follows:
In this case both A and B mean to move forward, + means to turn left 60 degrees and - means to turn right 60 degrees - using a "turtle"-style program such as Logo.

Logo

A Logo program to draw the Gosper curve using turtle graphics :
to rg :st :ln
make "st :st - 1
make "ln :ln / sqrt 7
if :st > 0
if :st = 0
end
to gl :st :ln
make "st :st - 1
make "ln :ln / sqrt 7
if :st > 0
if :st = 0
end
The program can be invoked, for example, with rg 4 300, or alternatively gl 4 300.

Python

A Python program, that uses the aforementioned L-System rules, to draw the Gosper curve using turtle graphics :

import turtle
def gosper_curve -> None:
"""Draw the Gosper curve."""
if order 0:
turtle.forward
return
for op in "A-B--B+A++AA+B-" if is_A else "+A-BB--B-A++A+B":
gosper_op_map
gosper_op_map =
size = 10
order = 3
gosper_curve

Properties

The space filled by the curve is called the Gosper island. The first few iterations of it are shown below:
The Gosper Island can tile the plane. In fact, seven copies of the Gosper island can be joined together to form a shape that is similar, but scaled up by a factor of in all dimensions. As can be seen from the diagram below, performing this operation with an intermediate iteration of the island leads to a scaled-up version of the next iteration. Repeating this process indefinitely produces a tessellation of the plane. The curve itself can likewise be extended to an infinite curve filling the whole plane.