Snowflakes

Today, we will be generating a well-known symbol of winter:


But here's the secret: these snowflakes are actually procedurally generated! Can you believe it?

Here's 60 more of them:


The approach is pretty straightforward - all it is is Perlin noise.

Let's talk about what a snowflake is. It is, quite simply, a geometric shape with mirror-symmetry that then also has six-times rotational symmetry:


This means that every point of Perlin noise calculated was drawn onto the screen twelve times.

The big trouble of the project, then, was to create an interesting bit of Perlin to then be mirrored. If you were to just take normal Perlin noise with a normal threshold, it would look like this.


These are certainly pretty, but not really snowflake shaped.

The snowflake shape was accomplished by comparing the Perlin noise with a variable threshold. The formula ended up being a bit complicated, though:

sq(nx/(40+ny/5))/1.5+ny/450-max(0,4-nx-ny/200)/10+sq(ny/1600)*10+max(0,.25-ny/400)

The arguments are ny (distance to centre) and nx (distance to the closest "arm") - rather than explaining each part of the formula, I can show the average probability-map of that the formula leads to:


The brighter, the higher chance of being opaque. The six arms are almost always opaque, while the further towards the space between arms, the less likely. The further out from the centre, the lower the probability - however, the very centre also has a decreased probability.

Talking about the average snowflake - since we're using Perlin noise, we can add a third dimension to the noise function - here this third dimension is animated over time:



On top of this, there are some additional effects:
  • A bit of domain warping (adding in another source of Perlin noise as the 3rd dimension in the actual noise used).
  • Coloration which creates an interesting crystal texture.
  • Using circles to combat tiny Perlin islands.
  • Radial coordinates.
Radial coordinates creates quite interesting Perlin noise. This is a bit of an exaggerated example:



Neat, huh? But that's not a snowflake. The snowflakes above, however, do also use radial coordinates for the Perlin noise, just with slightly less obvious effects. It creates a more round shape, instead of the snowflake feeling blocky, as well as makes the details smaller closer to the centre of the snowflake.

You can find the snowflakes and their code on my OpenProcessing.
You can also find the above experiment, named vinyl, on my OpenProcessing.

Comments