prog: (rotwang)
prog ([personal profile] prog) wrote2008-07-07 11:20 am
Entry tags:

Mandelbrot rokk

Here is a nice animation by [livejournal.com profile] mrmorse of a Mandelbrot set zoom-in synchronized to a Freezepop song.

[identity profile] mrmorse.livejournal.com 2008-07-08 01:08 am (UTC)(link)
I wrote my own generator to create this animation, so I did a fair amount of waiting this time around as well. The fastest images generated in a few seconds, but ones towards the end, especially when they had a lot of black pixels, took up to half an hour each.

[identity profile] ubiquity.livejournal.com 2008-07-09 03:19 am (UTC)(link)
What algorithm did you use?

[identity profile] mrmorse.livejournal.com 2008-07-09 04:35 pm (UTC)(link)
I'm not quite sure what you're asking, so I'll basically tell you what I did and hope this covers your question.

Every frame of the animation has the same center, approximately -1.75+0i. The center, starting magnification, and ending magnification were all determined experimentally. The height of the first frame is around 180 and the height of the last frame is on the order of 10-12. Unfortunately, I don't have the exact numbers in front of me at the moment. The zoom from each frame to the next was calculated based on the duration of each measure of music. I can't really claim that the calculation I used made sense, but I played around with it until I got results I liked.

For each frame of the animation, each pixel corresponds to a complex number c. For each c, I iterated zi+1=zi2+c. If the magnitude of zi ever exceeds 2, the pixel is colored based on i. The hue is set by i mod 256, giving the rainbow effect with red corresponding to an i that's a multiple of 256. The saturation starts at 100% and decreases to 0% (pure white) at i = 8192.

As an aside, my original intent was to just vary the hue and get rainbow striping. This works when i does not change much between adjacent pixels, but as the magnification increases, i starts changing too fast and the picture looks less like rainbows and more like confetti. I originally intended the fade to white to cover the confetti, but found that the all white background was a convenient stopping point for the animation as well.

Pixels are colored black if |zi| does not exceed 2 for a large value of i. The limit where I colored the pixel black depends on the magnification, and is calculated as π divided by the distance between two adjacent points, but not greater than 2 million. (The point -0.75+0i is on the left edge of the central heart shape of the Mandelbrot set. It is in the Mandelbrot set, but -0.75+ai is not in the Mandelbrot set for any a>0. For the point -0.75+ai, the value of i where |zi|>2 is given by π/a. I decided that was as good a formula as any to determine the limit to color pixels black.)

There are many optimizations that can be applied to this calculation, but the only one I bothered with was checking for cycling. For most (maybe all, I don't know) points in the Mandelbrot set, zi converges on a pattern. This is not necessarily a single value. Often it's a repeating sequence of values. I checked for repeated numbers, and if one was found, I immediately bailed out and colored the pixel black.

With all that in place, I started my program running, and about 48 hours later I had 1200 images which I then converted to this animation.

[identity profile] ubiquity.livejournal.com 2008-07-11 04:17 pm (UTC)(link)
Cool. *nods* That makes sense. Thanks for explaining! Also, I like your icon. (: