Fractal programming

I’m a sucker for art with high self similarity and detail/texture. Fractal art has these things in abundance, so it wasn’t long after I started coding that I made a simple fractal explorer. It let you zoom into interesting areas, save screenshots, adjust the color rendering etc. Here are some examples of fractals I generated:



Below is a similar project I coded up in JavaScript in college so I could put it on webpages. Go ahead and click around, see if you can find some cool patterns! (Hint, the program slows down if you have lots of the big black areas in the frame. Because of the escape-time algorithm I’m using, you have to loop up to 1,000 for every pixel in the dark areas and clearly that can take a while)


I really liked videos like this on Youtube where it would render a video of exploring cool parts of fractals. After graduating college I redid the project in python with this feature so I could make similar videos.

Enter scalability challenges. Instead of rendering one image at a time I now needed 60 images per second of video for a 60 FPS video. And I wanted more than a few seconds of footage! Now that I would be rendering thousands of frames of fractals, however, I opted to learn some CUDA and offload the heavy lifting to my GPU. This has massive performance gains, since GPU's are designed for crunching floating point calculations quickly.

The next challenge of course was turning all of those image frames into a video. Usually I like to keep my projects platform independent, so when my research pointed to the linux utility ffmpeg I got a little shy. I chose instead to play with OpenCV, which was frankly massive overkill for what I needed. While it is a very powerful and impressive tool, and also took a fair amount of work and configuration to download and compile properly.

I did get it working, though, and produced some nice videos like this:

fractal



They’re still a little choppy, though. Not to mention the coloring is very basic escape-time stuff. This leads to very discrete bands in the color instead of the nice color gradients. You can see the contrast in these example pictures from the Wikipedia Mandelbrot article below.

fractal
Fractal colored with escape time algorithm, which produces bands of colors.
fractal
Fractal colored with a continuous smoothing pattern.



Future improvements on this project could include
  • Introducing concurrency for faster fractal rendering (every frame of the video can be processed independently. Every pixel of every frame can also be rendered separately, for that matter!)
  • More sophisticated color mapping. My knowledge of coloring and what looks good is novice at best. I'm also red-green color blind, so that doesn't help. Doing a little research and using defaults/translations that more color-savvy people have found would make for much nicer images.