3D Fractal Cube
January 31, 2007
New York, N.Y.
There's nothing quite like a fractal program to bring a graphics system to its knees. The FractalCube program displays a spinning 3D cube, then creates 6 more cubes of half size on its faces, and then 5 cubes on the 5 visible faces of those cubes, and so forth. At the end of several generations, it looks something like this:
This qualifies as a fractal because while the volume of the figure has an upper-limit, the surface area increases without bounds. Of course, you won't get anywhere close to the "without bounds" part. You can run the program from here:
You need to click the button at the top of the page for each new generation. The cubes in each generation grow from nothing to their full size over the course of a minute. You'll probably start noticing some performance degradation when you click the button labeled "Generation 4: Create 750 new cubes", and almost surely when you click "Generation 5: Create 3,750 new cubes." Go beyond Generation 5 at your own risk!
Because it has a lot of movement and animated growth, this program looks terrible when 3D anti-aliasing isn't enabled. That'll be the case if you're running this program under Windows XP with .NET 3.0, or under Vista without a Tier 2 graphics board. For that reason, the program uses RenderCapability.Tier to display a little message at the bottom of the page regarding your particular graphics capability. (Here's an overview of Vista graphics rendering tiers, including lists of graphics coprocessors that you should look for if you need to upgrade your video board for 3D anti-aliasing and a complete Vista Aero experience.)
Only a tiny part of this program is written in XAML. Here's the FractalCubeApp.xaml application definition file and the FractalCube.xaml page layout. Virtually everything is done in C# in the file FractalCube.cs, so this might be useful to people who are interested in generating 3D objects and animations at runtime. Finally, here's the FractalCube.csproj Visual Studio project file.
I've recently been studying an essential article on Maximizing WPF 3D Performance on Tier-2 Hardware. I'm pleased to say that FractalCube creates just one shared GeometryModel3D object that is re-used for all the cubes. In each generation, a single animated ScaleTransform3D is shared among all the cubes of that generation. Only the ScaleX property is animated; the ScaleY and ScaleZ properties are bound to ScaleX. (I assume this is more efficient than three separate animations, but I could be wrong.) So, at any time, at most there are only 2 animations: the one expanding that generation's cubes, and the one spinning the whole caboodle.