Recursive patterns – the Koch snowflake

The Koch curve can be extended by placing three copies of the Koch curve outward around the three sides of an equilateral triangle to form a simple closed curve that forms the boundary of a Koch snowflake.

Once we have the code for the recursive Koch curve, implementing the snowflake is trivial. It basically involves generating a Koch curve, rotating 120°, generating another Koch curve, rotating another 120°, and then generating the final Koch curve.

Here is the processing code, which can be used with the quick recursive functions described previously.

void kochSnowflake(float lngth, int level) {
  kochCurve(lngth,level); 
  rotation(120);
  kochCurve(lngth,level);
  rotation(120);
  kochCurve(lngth,level); 
}

Here is the output for lngth=200, and a level=4.

Koch snowflake

A 4-degree Koch snowflake

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.