Aug 30

This sample is extracted previously from my Silverlight Project. The source codes are highly configurable and you may customize it for you needs. Though it’s pretty simple but yet very good to act as a background for you application.

Comparison

Flash implementation: 40 Minutes
Silverlight implementation: 1 hour
Blog writing: 30 Minutes
Code variation in the source code:

  • Color Setting: RGB to int [AS3] vs Color.FromArgb [C#]

Source codes

Flash

Silverlight

Color Setting: RGB to int [AS3] vs Color.FromArgb [C#]

In AS3, there is not class for converting an RGB value to int value. However, it’s not too difficult to calculate the color value from RGB. Below is an example in creating an ellipse by an given RGB variables (I have also included the conversion code of color value to RGB value as well).

// AS3, creating an ellipse
var ellipse : Shape = new Shape();

// RGB value to color value
var color:uint = red * 0x010000 + green * (0x000100) + blue;
ellipse.graphics.beginFill(color, alpha);
ellipse.graphics.drawEllipse(0, 0, size, size);

// color value to RGB value
var red:int = ( color & 0xFF0000 ) >> 16;
var green:int = ( color & 0x00FF00 ) >> 8;
var bblue:int = color & 0x0000FF;

In the case of C#, you may use the static function FromArgb and create the Ellipse on the fly. 

// C#, creating an ellipse
Ellipse ellipse = new Ellipse();
ellipse.Width = size;
ellipse.Height = size;
ellipse.Fill = new SolidColorBrush(Color.FromArgb(alpha, red, green, blue));