Well, the title is self-explanatory. What sorts of snowfall can we generate using Mathematica? There are two options I suggest to consider:
1) Continuous GIF animations with smallest possible number of frames.
My simple version using
A slightly prettier version, same basic idea but now with flakes.
|show 2 more comments|
I happened to create some snowflakes and snow fall a couple weeks back, and its nice to have some place to share with others!
First, we create some algorithmically generated snowflakes with some randomness using a kind of iterated function system based off the 6-pointed "star" shown below.
To construct the snowflake we just make copies of this star which are translated by some random amount and rotated (for 6-fold symmetry), and scaled in size.
We can seed some random real numbers to generate unique snowflakes
There are various parameters one could adjust here including some like x, y position and spin to rotate a snowflake which will be used later to animate snowfall. Here is a sample of several snowflakes after fixing a particular choice of parameters and ranging Q to seed different random reals:
To generate snowfall, we parameter the x,y position, and spin of each snowflake with time t. I used the following code. Notice that Snowflake was used twice and combined with Show. The reason this was done was to create a better simulation of depth in the snowfall. The only difference between the two is the size the snowflakes are allowed to randomly range through. Here, Q1 and Q2 can be varied to generate different snowflakes, and F1 and F2 control the number of snowflakes.
This animated gif loops seamlessly with 40 frames, but can of course be made smaller if desired. In my original project, I included some text (code not shown):
My attempt adresses the second option. These are simple falling circles with random shift and color depending on the radius of the "snowflake".
The usage is
And finally a "full screen" version:
This approach uses a voxel-based snowflake that actually looks quite realistic because of the way
With this, we now create an animation by rotating the data array downward:
So you have to wait several seconds for the frames to be generated. Here is the result:
By choosing the
If you're really patient, you can add some sideways wind as Rojo was suggesting in his
This is a snow storm. The reason why this takes so much longer to create is that I can't take the
Edit: making a GIF into a dynamic animated notebook display
Since the question asked about
The second step is now to re-import the
The output cell can be copied anywhere you like, even into a new notebook. To reiterate: you only need to copy the output by selecting its cell bracket, without having to regenerate the movie by re-evaluating the input. So the function
An important ingredient in this function is actually not really used in this context: the ability to have a varying frame rate. This utilizes a solution by Heike to the question When importing GIF animation, how to find the correct list of “DisplayDurations”?.
This could be a start for someone who wants to play around in v9
To animate snowflakes, we first need to create them. Here's a simple way to create snowflake-like objects:
This uses the fact that multiplication by $\exp(i\phi)$ is a rotation by $\phi$ in the complex plane to successively rotate a straight line to create one arm of the flake, then rotating the whole thing a few times to create the whole flaks.
Here's how it looks:
Some might say that this looks more like a spaceship than a snowflake. Maybe it does.
This may be animated using a minimal modification of faleichik's code (minimal means that I left everything alone except what I had to change, so bits are redundant):
You may be wondering where all the snow seen in the brilliant and amazing answers above (assuming you've sorted answers by votes) ends up... The answer is, down here, on the floor. Sadly, I can't upload this riveting movie in its full unabridged splendour, although at least my cat enjoys watching the full 3-hour version.
This is how it starts:
and here is the epic finale:
I created some (semi-random) snow for a Christmas related notebook I recently wrote. Thought it was worth sharing:
The final output of the notebook also adds some (again semi-randomly placed) trees and hills, along with Santa himself
Part of the answer lies in generating snowflakes.
If one is truly interested in a random-generated snowflake, I suggest using varying initial conditions and rules for a 2D Cellular Automaton on a hexagonal grid to generate them. A demonstration for this already exists.