Post filed in Uncategorized

Silverlight Circular Motion Animation

In this sample I demonstrate how to take a series of UserControls (Simple ellipses) and rotate each in a counter-clockwise circular motion.

The first step in the process is to define a user control and expose both the TranslateTransform and RotateTransform from the TransformGroup object.  This allows us to rotate and move each user control on a specified tick (DispatcherTimer tick).  The timer is controlled by the main page.xaml.

In this example, I start with a single “ball”, begin rotating it, and every second add an additional ball to the animation.  Instead of having each user control have its own animation, I have chosen to use a single DispatcherTimer that iterates over a generic collection of UserControls, to generate the circular motion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Page_Loaded(object sender, RoutedEventArgs e)
{
    _centerX = this.Width/2
    _centerY = this.Height / 2
    _timerAnimation.Interval = TimeSpan.FromMilliseconds(20)
    _timerAnimation.Tick += new EventHandler(_timer_Tick)
 
    _timerInserter.Interval = TimeSpan.FromSeconds(1)
    _timerInserter.Tick += new EventHandler(_timer2_Tick)
 
    PlaceBall("Bo")
 
    _timerAnimation.Start()
    _timerInserter.Start()
}

In this handler I determine the center of my circle, place the first control, and define two DispatcherTimers, one for the animation, and one for inserting additional controls into the main Grid. Since the speed of rotation is consistent for each “ball”, I am able to use a single timer which iterates over a generic collection of UserControls. Each time the Animation timer fires, I will call the following method.

1
2
3
4
5
6
7
8
9
10
11
12
void _timer_Tick(object sender, EventArgs e)
{
    foreach(KeyValuePair<string ,BALL> ball in _balls)
    {
        ball.Value.Rotate.Angle -= 5
        ball.Value.Rotate.Angle %= 360
        // Transform angle degrees to radian value
        double radians = ((ball.Value.Rotate.Angle / 180) * Math.PI)
        ball.Value.Translate.X = _centerX + Math.Cos(radians) * _radius
        ball.Value.Translate.Y = _centerY + Math.Sin(radians) * _radius
    }
}

The math in this method is pretty basic, on each tick I rotate the ball between 1 and 360 degrees. The angle I am looking for is the remainder of the angle of my rotation from 360 degrees. To calculate this, I apply the modulus assignment operator to my new angle. To determine the appropriate X and Y position I transform my angle into Radians and apply a bit of trigonometry to calculate X/Y based on the sin and cosine of the radian. Thanks again to Paul Ortchanian flash site, reflektions for a Flash sample I could translate into Silverlight.

Code: CircularMotion.zip

Creepy Girl From MotionPortrait

I wish I could remember where I stumbled upon this, but you have to check out this creepy Flash demo. Move your mouse around and watch the model. The movement is not super fluid, but impressive nonetheless. A company by the name of MotionPortrait created the demo.

Security lapse exposes Facebook photos

welcome_3.gifCheck out this article on Cnn that describes the recent privacy breach that caught Facebook with there pants down.  A security lapse allowed strangers to access photos of Facebook member and their friends, even if the privacy settings were set to restrict who could see the photos.

With over 67 million active users, Facebook will always be suspect to hackers looking for a way to circumvent its user privacy.  For reasons beyond my comprehension, our generation of Internet users have little trepidation about what information we place in the hands of others.   When Facebook made the decision to open ups its platform they put upon them self a huge risk that someday the breach will be very serious.   Privacy is not a setting, but a caution we should all take before we choose to upload a private photo or other personal information to the 5th most-trafficked website in the world .

Quote of the Day

“There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”
—C.A.R. Hoare

Apollo

Check out this new product from Adobe Labs. It’s a cross-operating system runtime being developed that allows developers to leverage Flash, Flex, HTML, JavaScript, and Ajax to build and deploy rich Internet applications (RIAs) to the desktop.

http://labs.adobe.com/technologies/apollo/

Introduction

My name is Joel, and I am a Microsoft.NET system architect and Director of Development for a leading interactive development firm located in Tempe, Arizona. Our firm designs and develops a wide range of custom web applications which leverage Flash, Ajax, ASP.NET and the Microsoft.Net Framework.