This is an IFS (iterated function system) fractal using three affine transformations. Give it a minute.

Your browser does not support Java, so nothing is displayed.

You should see a big black circle, three smaller black circles, probably some light blue circles, and a fractal in black. Sometimes the picture fills in in stages. Sometimes it looks like Da Vinci's man in the square. I've tried this applet on Firefox 1.5, Explorer 5.2, and Safari 1.3.1, all on Mac OS X 10.3.9. All the browsers run it much slower than AppletViewer does; Firefox is the worst.

Samurai Jack
If you're not into the math of IFS fractals, enjoy the pictures! For another fractal, hit your browser's refresh button.

For you fractal math fans, here are some clues to encourage you to look at the source code.

The three transformations for the fractal are picked at random, but only sets whose fractal dimension (as I calculate it, see below) is between 1.4 and 3 are used.

The Black Circles

The big black circle is calculated as the smallest circle that encloses the three smaller black circles. The smaller black circles are the big circle taken through each of the transformations of the fractal. Wait, isn't that, well, circular? Yes, in the same way that IFS fractals are.

The program plugs expressions for the centers and radii of the transformations of the big circle into the set of three equations for the smallest-circle-enclosing-three-circles. That produces three quadratic equations that boil down to one, which gets solved and back-substituted. When there are two solutions, the program uses the smaller of the two. The solution for the big circle, run through the transformations, produces the smaller black circles that enclose what I call the "parts": the subsets of the fractal corresponding to each of the transformations.

The idea was to get an easy-to-calculate, small enough, but not too-small bounding shape for a fractal, to help place and scale the fractal on a page. (People who have worked with random IFS fractals may understand the kind of guesswork methods I was avoiding.) I think this method does pretty well.

You may notice that sometimes the fractal is over to one side of the circle and the circle could be noticeably smaller and still enclose the whole fractal. That's partly because the method insists that the big circle touch all three smaller circles. Sometimes it would seem possible to use a circle that touches only two of the smaller circles, and the third would still be inside. Haven't tried that yet.

...and it's called The Moon

The Light Blue Circles

The light blue circles are "crumbs" of the fractal. When one or more of the transformations has a scale that is large (say, .9), both recursive and "chaotic" methods of drawing IFS fractals have problems with the long tails that large scale factors produce. If the biggest scale factor of any of the transformations is greater than .5, I replace that transformation by the current set of transformations, each through the transformation being replaced. Now instead of n transformations I have 2n - 1 transformations that represent an equivalent fractal. I keep doing that until the scale of the largest transformation is less than .5. The blue circles are the big circle through the transformed transformations.

Method for the Fractal Dimension

The fractal dimension of a fractal is roughly its density, from sparse to squiggly to lumpy. The fractal dimension helps set the relative "weight" of each transformation, the fraction of points to draw for that transformation. If you don't get this right, the fractal won't look evenly shaded. Also the fractal dimension helps decide how many points to draw altogether, to give it the right-looking density.

I've seen some difficult-looking methods of determining the fractal dimension, so I thought I'd describe this simple one. Say we have three transformations, each with a scale factor sn. Then this equation can be solved for the fractal dimension d:

s1d + s2d + s3d = 1

This is just a power law relating the "amount of stuff" in a part of the fractal to the linear scale of that part's transformation. Each snd is the weight of one part, the fraction of stuff in that part. I calculate d with a binary search.

Source Code

The source is in davinci.tgz (tar, gzipped). The main file is, and there are a lot of small files, one to a class, mostly a library for doing graphics and geometry in a way that works in Java 1.1. In AffineFractalApplet there is also a commented-out section for writing a postscript file that produces the same picture. Enjoy.


Working for the Weekend