Context Free Art

Tutorials/Fractals

From Context Free Art

Jump to: navigation, search

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.

Image:Trifra.jpg

startshape fract
 
rule fract {
TRIANGLE { }
fract { y .288 s .5 b .1}
fract { x -.25 y -.144 s .5 b .1}
fract { x .25 y -.144 s .5 b .1}
}

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.

Image:Trifrb.jpg

rule fract2 {
TRIANGLE { }
fract2 { y .288 s .5 b .1}
fract2 { s .5 r 180 b .1}
fract2 { x -.25 y -.144 s .5 b -.1}
fract2 { x .25 y -.144 s .5 b .1}
}

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.

rule fract {
TRIANGLE { }
fract { y .288 s .5 b 1}
fract { s .5 r 180 b -1 }
fract { x -.25 y -.144 s .5 b 1}
fract { x .25 y -.144 s .5 b 1}
}
rule fract .5 {}

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:

Image:Trifr2a.jpg

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.

rule tripaint {
30* { } fract { hue 80 sat .6 a -.8 } }
 
rule fract {
TRIANGLE { }
fract { y .288 s .5 b 1}
fract { s .5 r 180 b -1 }
fract { x -.25 y -.144 s .5 b 1}
fract { x .25 y -.144 s .5 b 1}
}
rule fract .7 {}

Image:Trifr2b.jpg

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.


startshape realmessfoury4 
 
// 'layer 3'
 
rule somebox3 {somebox3{hue -10}}
rule somebox3 {somebox3{r 1}}
rule somebox3 {somebox3{r -1}}
rule somebox3 { SQUARE {hue 15} } 
rule somebox3 { SQUARE {hue -15} } 
rule somebox3 .1 { somebox3 {hue 50 b 1} }
rule somebox3 { SQUARE {b -.5 sat -.1} } 
rule somebox3 { SQUARE {sat .9 b .3} } 
 
// 'layer 2'
 
rule foury4 {
somebox3{}
foury4{x .25 y .25 s .5 r 1 z .01}
foury4{x .25 y -.25 s .5 r 1 z .01}
foury4{x -.25 y .25 s .5 r 1 z .01}
foury4{x -.25 y -.25 s .5 r 1 z .01}
}
rule foury4 { foury4 {r 2 } }
rule foury4 { foury4 {r -2 } }
rule foury4  1.5 { }
 
// 'layer 1'
 
rule realmessfoury4{ 60*{} foury4 { } }

Image:Squarefilla.png

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

startshape towers
 
rule CUBE {2*{s -1 1 b .5 hue 10}SIDE{ b -.25}TOP{}}  // increase the contrast between the cube sides slightly...
 
rule SIDE {FACE{skew 0 30 b .5}}
 
rule TOP {FACE[s 1.413 .816 r 135 b .9]}
 
rule FACE {realmessfoury4{x .5 y -.5 }}  // here is the only change we actually need to do
 
 
rule cubes {
 
   CUBE { }
   cubes { s 1.01 z 1 y 1 }
   spread { } }
rule cubes .3 { }
 
rule spread {
   cubes { s 0.99 z -1 x 1 y .58 }
   cubes { s 0.99 z -1 x -1 y .58 } }
rule spread {
   cubes { s 1.01 z 1 x 1 y -.58 }
   cubes { s 1.01 z 1 x -1 y -.58 } }
rule spread 15 { } 
 
rule towers {
 3* { x 2 y .2 z -1 r -3} cubes { hue 250 b .4 sat .8 a -.5} }  // some additional color definition
 
 
// the filling
 
rule somebox3 {somebox3{hue -10}}
rule somebox3 {somebox3{r 1}}
rule somebox3 {somebox3{r -1}}
rule somebox3 { SQUARE {hue 15} } 
rule somebox3 { SQUARE {hue -15} } 
rule somebox3 .1 { somebox3 {hue 50 b 2} }
rule somebox3 { SQUARE {b -.5 sat -.1} } 
rule somebox3 { SQUARE {sat .9 b .3} } 
 
 
rule foury4 {
somebox3{}
foury4{x .25 y .25 s .5 r 1 z .01}
foury4{x .25 y -.25 s .5 r -1 z .01}
foury4{x -.25 y .25 s .5 r -1 z .01}
foury4{x -.25 y -.25 s .5 r 1 z .01}
}
rule foury4 { foury4 {r 2 } }
rule foury4 { foury4 {r -2 } }
rule foury4  1.5 { }
 
rule realmessfoury4{ 60*{} foury4 { } }

Image:Towerscfdg3.jpg

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.

Views
Personal tools
Navigation
Toolbox
MediaWiki
Attribution-Share Alike 2.5
book coverSee our book:
Community of Variation