Welcome to MSDN Blogs Sign in | Join | Help

Matrix Falling Characters in Silverlight

Once you start working with a good design tool enough, it changes the way you think and see the world.  Learning to draw nude figures gave me an appreciation for drawing and  then seeing shade and shadow.    With demonstrating and using Microsoft Expression Blend with Silverlight, that has happened to me.  In my previous post, I was explaining how I could see MindManager maps in the XML and how it was similar to the scene in the Matrix.  Why couldn't I show what I meant with Silverlight?  It was remarkably easy: about 20 minutes of my time.

I created one XAML file for the background and one for a character.  The background was just black.  The character had the size, coloring, gradient opacity, and animation.  All I would do is continually create characters and put them in randomly:

function DropCharacter()

{

    var host = m_root.getHost();

    var character = host.content.createFromXaml(m_characterXaml, true);

    var text = character.findName("Characters"); 

    var Charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*()_+{}|[]\:\";'<>?,./";

    text.Text = "";

    for (var index = 0; index < 10; index++)

    { 

         var charIndex = Math.floor(Math.random() * Charset.length);

         text.Text = text.Text + "\n" + Charset.charAt(charIndex);

    }

    var dropCharacter = character.findName("DropCharacter");

    dropCharacter.addEventListener("completed", function(animation, nullArg)

    {

        m_root.children.remove(character);

    });

    var left = Math.random() * m_root.Width;

    var top = Math.random() * m_root.Height;

    character["Canvas.Left"] = left;

    character["Canvas.Top"] = top;

    m_root.children.Add(character);

    setTimeout(DropCharacter, m_frequency);

}

I have attached the source code so you can see how it's done.  If you want to put the falling characters on your site or blog, just put this tag in the HTML:

<iframe align="right" src="http://silverlight.services.live.com/invoke/216/matrix/iframe.html" frameborder="0" width="150" scrolling="no" height="100"></iframe>

All I ask is that you link back here.

Note: 10/8/2007 the code above causes a memory leak in the browser it's hosted in.  See this post to download code that doesn't leak.

Published Friday, September 28, 2007 9:51 AM by Michael S. Scherotter
Attachment(s): Matrix.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Techy News Blog &raquo; Matrix Falling Characters in Silverlight

Friday, September 28, 2007 1:09 PM by Techy News Blog » Matrix Falling Characters in Silverlight

# re: Matrix Falling Characters in Silverlight

Nice, but there's one catch... the browser's CPU usage spikes to around 45%... ouch!  :-(

Friday, September 28, 2007 1:39 PM by dmurillo

# re: Matrix Falling Characters in Silverlight

So when can I check this type of thing out on Linux or OS X?

Friday, September 28, 2007 2:15 PM by Rudolf Olah

# re: Matrix Falling Characters in Silverlight

Rudolf,

Silverlight works today using Safari on OSX.  On Linux you can take a look at the Moonlight project: http://www.mono-project.com/Moonlight

Michael

Friday, September 28, 2007 2:51 PM by Michael S. Scherotter

# Fixing Memory Leaks in Silverlight Code

I did something bad. I put some sample code for a Silverlight application on my blog that ate memory

Monday, October 08, 2007 7:21 PM by Synergist

# Fixing Memory Leaks in Silverlight Code

I did something bad. I put some sample code for a Silverlight application on my blog that ate memory

Monday, October 08, 2007 7:41 PM by Noticias externas

# re: Matrix Falling Characters in Silverlight

I love all the MS haters looking for something to hate here.

Personally i've never been a computer lover.. let alone a platform lover, but silverlight rocks.

Good work MS.

Wednesday, December 05, 2007 5:10 PM by rich

# re: Matrix Falling Characters in Silverlight

But really what's with that CPU hogging?!

Tuesday, July 22, 2008 3:28 AM by Tony

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker