Foundation Silverlight 3 Animation- P15: Silverlight has really come a long way since I started using it. It’s kind of interesting to look back a mere two years (roughly) and think about how the workflow has changed. Of even more interest is the staggering speed at which new features are being added. In the time I’ve been using Silverlight, it has grown from a somewhat limited toolset to an ever-more-impressive technology that has really started to come into its own. | PARTICLE SYSTEMS 9. Compile and run the program. You will see something like what is shown in Figure 10-3. Figure 10-3. The particles now have random color scale and opacity. 10. So the particle generator is in place and does a pretty good job of randomizing our particles but at this point they re static. We need to make them move. Let s start by adding age and life span to each particle. Open the file and add the following lines of code before the Particle constructor. These are two simple publicly accessible properties that will be used to track a particle s age and life span. public int Age get set public int LiteSpan get set 11. Back in add the following two lines at the bottom of the MainPage constructor. These lines of code will set up an event listener for our Timer storyboard and start the storyboard running. new EventHandler MoveParticles 401 CHAPTER 10 12. Inside the CreateParticles function add the following line which will create a random life span between 0 and 120 frames for each particle as it is created. At 30 frames per second that should be a maximum of 4 seconds that any given particle is on the screen. 120 13. The MoveParticles event handler is shown following. This code uses the foreach loop to step through each particle in the Particles List increment the age and test to see if the particle has reached its life span. If so the particle is removed from the main canvas. private void MoveParticles object sender EventArgs e foreach Particle particle in Particles 1 if particle 14. Compile and run the project. The particles will be drawn and after a second or so will start disappearing from the screen until they re all gone. 15. Each time a particle dies we ll create a new one. To do this we ll first need to make a change to the MoveParticles code however. The foreach loop locks up