Mandelbrot Zoomer in WPF
Written by Mike James   
Tuesday, 20 July 2010
Article Index
Mandelbrot Zoomer in WPF
Displaying the result
Using the byte array
Zooming
Final touches

All that remains is the mouseup event handler and this is comparatively easy. It simply has to cancel the selection operation, make the rectangle invisible again and compute the new view of the Mandelbrot set using the new Rectangle:

private void Canvas1_MouseLeftButtonUp(
object sender, MouseButtonEventArgs e)
{
mousedown = false;
selection.Visibility=Visibility.Collapsed;

To compute the new view of the Mandelbrot set we first need to convert the bitmap position as specified by selection into a Rect in terms of x,y co-ordinates. This is just the same calculation we have already performed in converting px,py to x,y in the drawSet method:

double xscale = (area.Right-area.Left)/
image1.Width;
double yscale = (area.Top-area.Bottom)/
image1.Height;
Point TopLeft= new Point(area.Left +
Canvas.GetLeft(selection) * xscale,
area.Top-Canvas.GetTop(
selection)*yscale);
Point BottomRight = TopLeft+new Vector(
selection.Width*xscale,
-selection.Height*yscale);  
area=new Rect(TopLeft,BottomRight);

The only clever parts are the use of a Vector displacement to compute the bottom right corner rather than converting its co-ordinates from scratch.

Finally we can compute the new view:

 image1.Source = drawSet(area);
}

Now the user can zoom in on any area of the set. Notice that because WPF is a persistent vector graphic system we don't have to worry about drawing and erasing the rectangle that indicates the selected area - the system takes care of it. All we have to do is set its position and size.

Banner

Where next?

With the program as described above you can go exploring the Mandelbrot set to your heart’s content.

There’s a lot to see but be warned areas that are mostly blue take a long time to plot because these take the iteration loop to a full 1000 times around!

The fact that the computation takes so long makes it an ideal candidate for running on a thread other than the UI thread. You may notice that the UI freezes when the set is being computed and the only way to keep the application responsive is to use a worker thread.

When you are just trying to get it all working it is worth making the Image control small so that plots occur quickly.

You can add some additional features to make the program more usable – a plot interrupt button, for example, a pan, and so on..

 

mand2

There are lots of interesting areas to explore.

 

There is one small feature that I should warn you about before it wastes a lot of time when you try to “debug” the program. There are no limits on how far you can zoom in on any given region of the Mandelbrot set. You will discover that you can indeed use very high zooms but sooner or later you will select a very small region and the result will not look fractal but “blocky”. No you haven’t discovered that there is a limit to the structure of the Mandelbrot set!

What is happening is that you have zoomed to the point where double precision variables aren’t accurate enough to represent the position of each point. The result is that you get the same answer for whole rectangular regions for the iteration and hence the blocky structure in the final plot. The solution to the problem is fairly simple – increase the precision - but this is easier said than done and you just hit another limit sooner or later. .

 

mand3

No not the end of fractals – you’ve just zoomed too far.

 

To access the code for this project, once you have registered,  click on CodeBin.

 

Banner


Dealing With Forum & Mailing List Spam

Forum spam is a big problem and very difficult to combat. There are some solutions, none perfect, but this one might help reduce the burden on spam in your forum or mailing list.



Getting Started with Google Earth

Google Earth is more capable than Google Maps, but to use it you have to download a plug-in and learn a new API. This article explains that it's not so difficult and there are some easy to understand  [ ... ]


Other Projects

 

<ASIN:1430224819>

<ASIN:0470477229>

<ASIN:1430272058>

<ASIN:1430272406>

<ASIN:1430225394>

all the code


Last Updated ( Tuesday, 03 December 2013 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.