March 7th, 2009

Silverlight Rain Effect – Playing with Random

All Silverlight Examples, Silverlight 2 tutorials, Silverlight C# Tutorials, Silverlight Effects, by Gavin Wignall.

Using the Random command in Silverlight we can simulate rain falling with out risking a repetitive effect.

In the above example a single control houses the rain drop graphic and its storyboard animating from the top of the screen to the bottom. I then use the Random command in Silverlight to decide where the rain drop will fall, what angle it will fall at and how deep (using scale) into the image it will appear to be.


The slider controls the amount of rain drops that fall per second. At the left end of the slider there will be 1 rain drop produced every 40th of a second, at the right end there will be 10 rain drops produced every 40th of a second. This is done using a ‘For’ loop, the amount of loops being controlled by the slider.

Possible enhancements

A control/slider could be added to control the wind direction and speed.
An effect placed on the background to simulate less light as rain fall increases.

Get the code

Feel free to grab the code here and start playing!

Back Top

Responses to “Silverlight Rain Effect – Playing with Random”

  1. Nice work. Never thought about this kind of effect. Very nice indeed.

  2. It looks similar to the flying numbers on my website :)
    I had much trouble with the using of the Random-class because the generated numbers were not random enouth for my application. So i decided to make a RealRandom-class by myself whitch delivers very good random numbers.

  1. No trackbacks yet.

Leave a Reply

Back Top