First time at my blog? Check out the table of contents! x
posted on Monday, May 04, 2009 11:43 AM | Filed Under [ Silverlight ]

So a friend of mine gave me an old Flash animation book called Flash Math Creativity. The book is published by FriendsofED, the same publisher that put out Foundation Silverlight 2 Animation. In Flash Math Creativity, several different ActionScript programmers demonstrate how to do some pretty complex animations, all from within code. Now implementing the examples from the book in ActionScript is a pretty trivial task. You just type out the code from the book an run it. Rewriting and running them in Silverlight though is a different story.

As an exercise to learn the best ways to do complex animations in Silverlight, I’ve begun implementing my own versions of the examples from Flash Math Creativity using Silverlight. I will be posting my results here on the blog.

And here is the first animation from the book!

Oscillating Ellipses

image

This animation was originally created by Jamie MacDonald using ActionScript . Here it is using Silverlight 2.

In this animation I used the DispatcherTimer class to create a new red ball every 100

milliseconds. The movement of the balls is done from within an event handler in each ball instance. In essence, there is a loose-coupling between the main Page class which creates the red balls, and the actual ball classes. Once the balls are created, each instance manages its own animation and removes itself from the LayoutRoot when its opacity becomes 0.

The other key to this animation is that each ball subscribes to the CompositionTarget.Rendering event. I found that using this event to animate on works much better because it runs on a separate thread. On the other hand the DispatcherTimer.Tick event is managed and dispatched from within the UI thread, and so it doesn’t keep pace as well as the CompositionTarget.Rendering event.

Download the source code here.

Edit: View part I.I of the Silverlight Math Creativity series here.

 

Comments Leave Yours...
Adam Kinney
5/4/2009 12:09 PM
# re: Silverlight Math Creativity Part I

Great idea! I was thinking about doing this myself with the Math Creativity book. It would be interesting to see you try thi with Silverlight 3 Beta, as well. I'm looking forward to seeing your next samples.

Adam Kinney
5/4/2009 12:14 PM
# re: Silverlight Math Creativity Part I

Oh hey, would you mind sharing the code for your experiments, too? Its great to see the results running, but the code is helpful too.

Richard
5/5/2009 4:22 AM
# re: Silverlight Math Creativity Part I

Hi,

I started looking at this a while back (http://sprydon.com/dnn/Home/tabid/36/EntryID/13/Default.aspx) - but your example is much more in keeping with the book sample - nice work, look forward to the others!

Richard

The Infinite Foray
5/5/2009 2:47 PM
# Silverlight Math Creativity Part I.I

Silverlight Math Creativity Part I.I

Tukang Nggame
6/27/2009 4:02 AM
# re: Silverlight Math Creativity Part I

I thinks you make great idea, thanks for taking the time to sharing your idea for us, this very useful.

Post Your Comment

Title
Required
Name
Required
Email
Optional
Url
Optional
Comment  
Please add 7 and 2 and type the answer here:

Who Is Rafe

rafe

Rafe Kemmis

I am an audacious web developer with a double bachelor of science in Computer Science and Mathematics. I specialize in Microsoft ASP.Net, Silverlight, and Adobe ActionScript.

Questions?

Always a thoughtful response. You may post your question on an article, or contact me directly.

Hire Me.

I provide custom solutions to complex problems. I can help your business no matter how large or small.

Contact me now.

Subscribe