Feed on

Technorati tags: ,

My friend K. Scott Allen writes a great blog on ASP.NET topics.  But Scott dabbles in a many other interesting technologies too.  Last week he put together his first WPFe(Silverlight) application, a version of the classic ‘Game of Life”

I wanted to put a link to his app but all I could find was his source code.  So I put the finished app up on a server for you to look at.    Naturally I had to look at the code and I made one small change in the colors of the gradient fills. 

See the finished Game of Life

See resources [1] for more info on viewing WPFe applications

JavaScript Code Changes

GameOfLife.prototype.CreateBrush = function()
var r = Math.random();
var xaml = ‘<RadialGradientBrush><GradientStop Color=”White”
Offset=”0.0″/><GradientStop Color=”Red” Offset=”0.1″ />
<GradientStop Color=”sc# 1,’ + r + ‘,.9,0″ Offset=”0.9″/>
return this.agControl.createFromXaml(xaml);

So what is happening in the code?  First I get a random number (between 0 and 1).  Then I use the random number to set the Red value for one of the gradient stops. One of the nice features of WPF is that it can use doubles instead of integers to set colors.  So instead of have to know that the value for 20% Red = 51 you can set the value to 0.25.  Much simpler!

In XAML you specify this value using this syntax

Color=”sc# 1, 0.25, .05, 0.8″

Arguments are Alpha, Red, Green, Blue 

[1] Resources

Viewing WPFe samples:  Install the runtime – download
Writing WPFe applications: Install the SDK – download

- Walt

6 Responses to “WPFe (Silverlight) Example – the game of life”

  1. [...] at http://wpfwonderland.wordpress.com&nbsp; – Subscribed! Check out XAML to IL Explained Part 1, WPF/e Example – Game of LifeWCF/Indigo/SOANicholas Allan has his best of 2006 (and what a year it was for him/them!). Also check [...]

  2. [...] Wonderland Learning more about WPF (Windows Presentation Foundation) « WPFe Example – the game of life How would you rename WPFe? » WPFe Example – Happy New Year 2007 January 1st, [...]

  3. [...] changes.  Unfortunately I think there is a mistake in the article.  I updated the Game Of Life sample today to work with the new CTP and could not get it to work based on the syntax in the [...]

  4. [...] to catch up with the latest Silverlight release. With the WPF/E release last year I dabbled with Conway’s Game Of Life, but instead of porting old code I decided to try something new. During my short stint in the video [...]