Koch snowflakes for the holidays

| Dec 12, 2018 min read

Code for these images.

I hope you’re familiar with the Koch curve fractal or snowflake. It essentially consists taking a line segment, splitting it in three, and substituting the middle part by two segments that form an equilateral triangle without the base. From one segment you obtain four. For each new segment, repeat the process.

Images:

The most important aspect of the koch line is that it looks awesome. Furthermore, you can do it for any image that is a collection of segments. In particular, regular polygons, both outward and inward.

Another way to define the four new segments is this: Given the endpoints of the segment $P_1$ and $P_2$, we define $\vec{v} = \vec{P_1P_2}$. The five points that define the four new segments, in order, are $P_1$, $P_1 + \frac{1}{3}\vec{v}$, $P_1 + \frac{1}{2}\vec{v} + \alpha R\vec{v}$, $P1 + \frac{2}{3}\vec{v}$ and $P_2$, where $\alpha = \sqrt{3}/6$. A simple thing one can do is change the value of $\alpha$ to obtain different images:

Using a diamond with $\alpha = 1.25$.

Using a square with $\alpha = 1.2$.

Using polygons with $N$ equals to 3, 4 and 5 sides, and $\alpha = 3\sqrt{N}/5$.

Using a line segment from the center to the vertex and back and to next vertex, etc., with $\alpha = 1$.

And to close off, here’s a traditional triangle, repeated, with alternating colors.

Here’s a larger scale version:

Happy holidays!