Agile Coder Logo
Intermediate

Koch Snowflake: Three Curves, One Crystal

Apply the Koch curve to all three sides of an equilateral triangle and you get a snowflake. Infinite perimeter, finite area, endlessly satisfying.

Smruti Ranjan
May 20, 2026
3 min read
#fractals#generative-art#snowflake#mathematics#p5js
Koch Snowflake: Three Curves, One Crystal
p5.js sketch
Advertisement

This is the follow up of the Koch Curve, You can read about the mathematical significance of the Koch Curve in this article.

At its core, the Koch snowflake begins with an equilateral triangle—a straightforward geometric shape. However, this seemingly simple shape undergoes a series of transformations that unveil its true magic. By iteratively replacing each straight line segment of the initial triangle with smaller segments, the snowflake pattern emerges. In each iteration, four smaller triangles are added to the previous segment, and this process repeats indefinitely. What starts as a basic geometric shape evolves into an infinitely intricate boundary.

One of the most fascinating features of the Koch snowflake is its self-similarity. At any level of iteration, a smaller portion of the snowflake looks like a scaled-down version of the entire shape. This property reveals the fractal nature of the Koch snowflake, where the complexity is maintained across different scales.

How can we reproduce this pattern

js
let segments = []
let depth = 6
let currDepth = 0
let isMobile = false

const setup = () => {  
  createCanvas(500, 500)
  let length = 300;

  segments[0] = {
    start: { x: width / 2 - length / 2, y: height / 2 - sqrt(3) * length / 4 },
    end: { x: width / 2 + length / 2, y: height / 2 - sqrt(3) * length / 4 }
  }
  
  segments[1] = {
    start: { x: width / 2 - length / 2, y: height / 2 - sqrt(3) * length / 4 },
    end: { x: width / 2, y: height / 2 + sqrt(3) * length / 4 }
  }

  segments[2] = {
    start: { x: width / 2, y: height / 2 + sqrt(3) * length / 4 },
    end: { x: width / 2 + length / 2, y: height / 2 - sqrt(3) * length / 4 }
  }
};

const draw = () => {
  background(255)

  kochSnowflake(segments[0].start, segments[0].end, currDepth, p5);
  kochSnowflake(segments[1].end, segments[1].start, currDepth, p5);
  kochSnowflake(segments[2].end, segments[2].start, currDepth, p5);
}
↕ click to expand

And, the kochSnowflake() is nothing but the Koch Curve. You can find the function in this article. In this article, I have explained the mathematical signicance of the Koch Curve itself.

Some of the Facts about Koch Snowflake

  1. Fractal Geometry: The Koch snowflake is one of the earliest and most well-known examples of a fractal—a geometric shape that exhibits self-similarity and complexity at every level of magnification.

  2. Named After Helge von Koch: The fractal was first described by the Swedish mathematician Helge von Koch in 1904. He introduced it as a way to illustrate the concept of a continuous curve with an infinite length, despite starting from a finite initial shape.

  3. Infinite Perimeter, Finite Area: The Koch snowflake has a remarkable property—the perimeter of the shape becomes infinitely long as the number of iterations approaches infinity, while the area remains finite.

  4. Iterative Construction: The Koch snowflake is constructed through a recursive process. Starting with an equilateral triangle, each side is divided into four segments, and the middle segment is replaced by two smaller segments to create a new shape. This process is repeated infinitely.

  5. Fractal Dimension: The Koch snowflake's fractal dimension is approximately 1.2618, which lies between the dimensions of a 1D line (dimension = 1) and a 2D plane (dimension = 2).

  6. Self-Similarity: At every level of iteration, the Koch snowflake exhibits self-similarity. Each smaller portion of the snowflake looks similar to the whole, albeit at a different scale.

  7. Fractal Art: The Koch snowflake, with its beautiful and intricate patterns, has become a popular subject for fractal art—a form of digital or traditional art that employs mathematical algorithms to create stunning visual representations.

  8. Applications: Fractals, including the Koch snowflake, have found applications in various fields such as computer graphics, terrain generation, data compression, and even antenna design.

  9. Inspiration for Mathematics Education: The Koch snowflake is often used as an educational tool to introduce students to the concept of fractals, infinite series, and self-replicating patterns.

  10. Limitations of Realization: While the concept of the Koch snowflake is infinite, in reality, its realization is limited by the resolution of the medium used to draw or represent it. Nevertheless, the concept of infinity remains a fundamental aspect of the fractal's beauty and intrigue.

The Koch snowflake's charm lies in its ability to transform a simple triangle into a boundary of infinite complexity, illustrating the captivating nature of mathematics and the profound beauty of fractal geometry.

Advertisement

Behind-the-build, in your inbox.

New tutorials, book updates, and behind-the-scenes notes from the studio. No schedule, no spam.

Comments

Leave a comment

Comments are moderated before appearing.