Subscribe to RSS
get email updates
home | about | pixDif AIR app | video tutorials
polyGeek.com

Register for 360Flex in DC using the ad below and you will automatically be entered in a drawing for a free ticket. Read more.
place your ad here

Web Premium





An interactive exploration of the relationship between the Mandelbrot set and Julia sets with Actionscript ( a.k.a. looking at pretty pixels )

July 16th, 2008 . by polygeek

There is a beautiful relationship between the Mandelbrot set and Julia sets. Namely, when creating a Julia set with a point that is contained inside the Mandelbrot set you end up with a Julia set that is contiguous. But pick a point outside of the Mandelbrot set and your Julia set will start to form islands and will no longer be contiguous. ( I’m sure there are really cool mathematical terms for that but I don’t know them. )

Move your mouse over the Mandelbrot set ( top ) and watch the Julia set ( bottom ) change form.

view source

Back in college in the mid 80s I saw a video about the Mandelbrot set that illustrated just this relationship that you see here. A large Mandelbrot set was displayed on screen and in one corner was a display of a Julia set. A point floating over the Mandelbrot set moved around – like you do with your mouse above – and the Julia set would be created with the points corresponding to the ( a + ib ) point of the Mandelbrot set. As the point moved near the center of the Mandelbrot set the Julia set became nearly circular. Moving out toward the edge of the Mandelbrot set caused the Julia set to become more complex. And finally the Julia set became wildly dispersed as the point moved far away from the edge of the Mandelbrot set.

What the video showed was a rendering of the Julia sets changing because few if any computers at the time has the power to crunch out Julia sets that fast in real time. Since then I’ve always wanted to recreate that visual but in an interactive way, not something that is pre-rendered.

My wife and I went on a camping trip this weekend and I took the opportunity to hammer it out. I had created a class to display the Mandelbrot set months ago. So all I had to do was handle the Julia set and interactions. Turns out it is very easy to create a Julia set and the caculations do not requrie recursion so it renders much faster than the Mandelbrot set which does require recursion.

About the code
Of course the source code is available in case you would like to poke around with this yourself. I got the pseudo code from ThinkQuest.com. In the JuliaSet class I left the pseudo code comments around the Actionscript translation so it should be very easy to follow.

Every time the mouse moves across the Mandelbrot set a listener fires and passes the current ( a + ib ) coordinates to the JuliaSet class. If the JuliaSet class is still calculating from a previous call it will just return the BitmapData of the last rendered Julia set. Otherwise it will create a new Julia set with the new coordinates and return that. So it’s best to move your mouse around somewhat slowly. Mileage may vary depending on various factors. It seems to zip along pretty well on my laptop running Ubuntu on a 2.2Ghz processor.

The colors are calculated based on the number of iterations it takes to create the Julia set, or Mandelbrot set. For instance, points inside the Mandelbrot set are always black. But points very near the edge vary in color depending on the number of recursive loops it took before the breakout condition was met: x^2 + y^2 > 4.

The color assignment is found by simply multiplying ‘white’ 0xFFFFFF times iterations/max_iterations. It isn’t the best method of assigning colors but it is quick and easy to impliment. The colors for the Julia set are assigned in a similar manner.

When I strike it rich with one of my crazy startup ideas I’m going to retire to an island somewhere and just explore mathematical algorithms like this one. :-)

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

   



polyGeek.com

© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites
Local Directory for Los Angeles, CA

Better Tag Cloud