Tutorials/Fractals

Fractals
What is more enchanting than fractals, those self-similar things?

Actually context free fractals are a special subset of fractals, though amazing results can be produced with this subset already.

Fractal patterning
Fractal definitions can be used to fill in predefined shapes.

Context free basic shapes pretty much define what kind of fractal shapes are most useful: the square, the triangle, and the circle.

With Context free, much about the mathematical qualities of fractals can be skipped. (Tutorials and other material should be available elsewhere.) A simple idea suffices: how to subdivide a shape into smaller portions. All kinds of graphical adjustments can be done on each subdivision round, ending in good results.

Fractal treatises often begin with the Sierpinski triangle. So be it.



This is actually a curious alteration on Sierpinski. Each triangle is subdivided into three triangles of half the size (one fourth the area), leaving an upside-down triangle-formed hole in the center. Here, each round of subdivision brings about a gradual brightening ( b .1 ). That is what is strange in this Sierpinski. It is really only an approximate ( the figures could be more precise too, but for our purposes the geometry is really not needed ).

Lets try something else with the same triangle.

It is painted. Voilá. Bon voyage. One of the subdividing triangles was adjusted with ( b -.1), others with brightness increase.

One obvious objection pops up: it is awfully slow and inefficient most of the time (1,398,101 shapes for an image 442 x 390 pixels).

We don't really need to go to 'the bottom' all the way to get graphically appealing textures.

We'll try throwing in some randomness and examine two more advanced techniques.

Let's stick with the triangle form for some more time. Now, there was an additional ( fract ) rule, cropping some of the branches out of the execution. Shapes? 41,629 which is much much nicer. With this definition we most of the time get something like the following:



It's nice in its way, but if we need a more uniform surface texture than that, it's all crappy for our purposes. Should we go back to one million primitive shapes? Never, never, never! Uncle William instructs for something else.

Let's try placing some of these random-triangles on top of each other.



Notice the ( 30* ) rule, with alpha set down to .2. 175,661 shapes is not so bad, and it is not even optimized. Note that if you paint smaller areas, they will require less subdivisions, so these figures give a rough estimate for the overall screen area as well.

Layering
In the following code, a square shape is filled with an irregular, grainy material. The brush is composed of three 'layers' of definition ( it is easy to conceive for example five too ). All the drawing is done with the rule somebox which, apparently, draws a box with some random properties: hue alteration, slight turning to either direction (this contributes to the roughness), a small chance for a bright spot of different color, and, finally, a rather dark altrnative or either a brighter and more saturated one.

This 'third layer' rule is called from the 'second layer' fractal rule ( like TRIANGLE from [ fract ] in the previous example ). Notice the ( z .01 ) directives in the recursive calls. They serve to ensure that smallest particles will be visible on the top, be there however many layers of the same fractal, so it in a sense sorts out the pile of primitive shapes according to our wishes.

The generating 'layer one' rule calls the previous rule sixty times in order to give a good chance for not too big grains.



Now we'll try and use this pattern as the texture for a 3D shape.

73,000 shapes, almost nothing at all...

There are the basic things to get started with fractal patterning. Experimentation will bring interesting results any time one cares to take the trouble.