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  for more info on viewing WPFe applications
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″/>
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