While reading the Mandelbrot set chapter in Dewdney’s The New Turing Omnibus, I realized that this would be a great test application for Microsoft’s new interactive Web application framework Silverlight. Below is the component, its source code, and a few things I learned along the way.
Beware: the Mandelbrot set is computationally expensive and may appear to lock up your web browser. If a “Stop running this script?” dialog pops up, please click no to allow the calculations to finish.
Silverlight 1.0 Mandelbrot Set Control
Here is a Silverlight 1.0 control which draws the Mandelbrot set. Left-click to zoom in on a particular region.
Source Code
The source code to the Silverlight Mandelbrot set consists of the following pieces:
- SilverlightMandelbrot.js — The code for instantiating the Silverlight Mandelbrot control and binding it to a
div - SilverlightMandelbrotEvents.js — The event handlers for the Silverlight Mandelbrot control, including the drawing code itself (performed on canvas load)
- mandelbrot.xaml — The XAML which defines the visual layout of the control
- Silverlight.js — the Silverlight code itself
Notable Findings
- Overall responsiveness is rather slow, especially on the mousemove event. Perhaps I’m pushing Silverlight too hard too early, but this slowness makes me highly reluctant to adopt Silverlight yet.
- I can’t figure out how to do progressive (e.g. line-by-line) rendering to give the user feedback.
- There is no facility for directly painting an individual pixel within Silverlight. Instead, you must draw 1 by 1 colored XAML rectangle controls. Because individual XAML rectangles are quite heavyweight, I coalesce multiple pixels of the same color in the same row into one rectangle.
- I wanted to use right-click to zoom out, but there doesn’t appear to be a way to capture the right click event from within Silverlight.
About the Mandelbrot Set
For more information on the Mandelbrot set, see its Wikipedia article.
March 12th, 2008 at 10:55 pm
[...] on Steven Engelhardt’s blog there’s a mandelbrot viewer written using silverlight 1.0 (meaning just xaml + javascript). In his post he listed a few [...]
March 12th, 2008 at 10:56 pm
Just wanted to let you know that I solved your progressive rendering problem. Check it out here: http://squeedlyspooch.com/mandel-sl10/foo.html