Current version: 1.0
This program was created to visualize a fractal pattern which was used to render a cosmological model by Hoyle mentioned on page 218 of The Fractal Geometry of Nature by Mandelbrot. The pictures in that book are a bit hard to visualize for the 3-d case, hence this program. Also, this was a good project to do some OpenGL/Objective-C/Cocoa coding.
How the program works and what's it's doing
This program does not show a true fractal (technically, no fractal program does) but several iterations of a pattern which, if fleshed out, would be a true fractal geometric figure. The iteration depth is controllable, but that depth is set to a low limit based on the video processing power that exists in most computers. The pattern is formed by having a cube sub-divided into some number of cells (also controllable to some extent), the exact ones of which are determined at random. What you do see are those cubes which have been selected last in the iteration process, and within which the fractal pattern would continue if you let it.
You'll notice that the pattern is harder and harder to see by itself as you let the iteration depth grow (apart from slowing down while your machine tries to render it). The limit of this fractal pattern itself would be completely unviewable, even in principle, so it's just as well that it gets stopped at some point. To see the construction technique, how the program subdivides cubes within cubes, select "subcells." Besides, it's a beautiful effect. (For reasons of how OpenGL does its rendering, showing subcells often speeds up the drawing to the screen.) You may want to turn off the automatic rotation of the cube and move it by hand to understand better what's going on. From there zoom in and out, and push it around by hand, and you'll really get a feel for the pattern. The "spheres" option was left in the program purely for aesthetic reasons. It has no good correlation to the fractal being studied here.
Notes about the code
The code itself is very sparsely commented, but shouldn't be too hard to follow (famous last words). It may help people who are having trouble getting a Cocoa app to handle OpenGL drawing better. That said, I'm sure it could be refactored or otherwise architected better than it is. But hey, it works and is reasonably clean.
Random interesting note: The program has gone through several iterations, including a 2-d Java and Objective-C version. There was a serious increase in rendering speed when I switched the code from Java to Objective-C/Quartz, and the speed increase was even greater when I switched to OpenGL. It really put in to perspective how slow the Java GUI libraries are. Also, OpenGL and Objective-C make a very nice fit for one another, though you end up writing some wrapper code for OpenGL's non-OO functions.
Comments about writing this:
Cocoa/Objective-C/OpenGL is a very compatible set of tools.
The code ends up conceptually cleaner than what I see in many OpenGL tutorials.
- Xcode / Interface Builder (free with OS X)
- Cocoa Browser (free) to quickly look up all things Cocoa (Actually, as of Panther, use Docoa Browser, still free)
Charged Spheres is licensed under the BSD license. Use it, redistribute it, pass it around, check out the code, enjoy it.-Jeff