Self-similar structures

Back to Codes of Nature


Author: Zsófia Ruttkay Version: 1.0 Date: 25.2.2009

In nature you often see that parts of a structure are smaller - exact or slightly changed - copies of the entire structure. Think of branching trees, snow-flakes or clouds.

The basic principle is self-similarity which can be programmed elegantly by using recursion .

Self-similarity

../Sketches/CourseSketches/Recursion/Rec1/Rec1.jpg Two circles inside one

The recursive production rule is to draw two half-sized circles in the 'parent'.

src: CourseSketches/Recursion/Rec1/Rec1.pde

ellipse()
../Sketches/CourseSketches/Recursion/Rec1_1/Rec1_1.jpg

Same rule as above, but the location of the smaller circles is changed.

src: CourseSketches/Recursion/Rec1_1/Rec1_1.pde

../Sketches/CourseSketches/Recursion/Rec1_2/Rec1_2.jpg

Watch out! Is this structure self-similar? Could you alter the code to produce a recursive one?

src: CourseSketches/Recursion/Rec1_2/Rec1_2.pde

../Sketches/CourseSketches/Recursion/Rec1_3/Rec1_3.jpg

How about this one?

src: CourseSketches/Recursion/Rec1_3/Rec1_3.pde

../Sketches/CourseSketches/Recursion/Rec1_4/Rec1_4.jpg

Explain why the previously seen logarithmic spiral is a recursive structure.

src: CourseSketches/Recursion/Rec1_4/Rec1_4.pde

../Sketches/CourseSketches/Recursion/Rec1_4g/Rec1_4g.jpg

Same as the previous structure, but triangles are drawn. Looks like a shelf.

src: CourseSketches/Recursion/Rec1_4g/Rec1_4g.pde

Trees

../Sketches/CourseSketches/Trees/Tree0/Tree0.jpg Tree by D. Shiffman

A fully symmetrical tree.

src: CourseSketches/Trees/Tree0/Tree0.pde

pushMatrix(), popMatrix(), translate(), rotate()
../Sketches/CourseSketches/Trees/Tree0_1/Tree0_1.jpg Asymmetric tree

.. with different angles for left and right branching.

src: CourseSketches/Trees/Tree0_1/Tree0_1.pde

../Sketches/CourseSketches/Trees/Tree0_2/Tree0_2.jpg Asymmetric tree driven by mouse

Mouse Y defines basic branching, mouseX the amount of asymmetry.

src: CourseSketches/Trees/Tree0_2/Tree0_2.pde

../Sketches/CourseSketches/Trees/Tree0_3/Tree0_3.jpg Tree with leaves

Square leaves added to Tree0.

src: CourseSketches/Trees/Tree0_3/Tree0_3.pde

../Sketches/CourseSketches/Trees/Tree0_4/Tree0.jpg Naked tree of Pythagoras

Left and right branching angles add up to PI/2. What is the scale?

src: CourseSketches/Trees/Tree0/Tree0.pde

../Sketches/CourseSketches/Trees/Tree0_5/Tree0_5.jpg

As above, but left and right branch scales differ.

src: CourseSketches/Trees/Tree0_5/Tree0_5.pde

../Sketches/CourseSketches/Trees/Tree0_6/Tree0_6.jpg Tree with random variation

src: CourseSketches/Trees/Tree0_6/Tree0_6.pde

../Sketches/CourseSketches/Trees/Tree0_7/Tree0_7.jpg Make a forest

On mouse-click a new tree is planted. Size is proportional to y location.

src: CourseSketches/Trees/Tree0_7/Tree0_7.pde

../Sketches/CourseSketches/Trees/Tree1/Tree1.jpg Symmetrical, generalized Pythagoras tree

Angle is decided by mouseX.

src: CourseSketches/Trees/Tree1/Tree1.pde

../Sketches/CourseSketches/Trees/Tree2/Tree2.jpg Asymmetrical tree or Pythagoras

src: CourseSketches/Trees/Tree2/Tree2.pde

../Sketches/CourseSketches/Trees/Tree3/Tree3.jpg A different visualisation of the tree of Pythagoras

src: CourseSketches/Trees/Tree3/Tree3.pde

../Sketches/CourseSketches/Trees/Tree4/Tree4.jpg Tree of Pythagoras with alternating left-right angles

Create variants with moving the mouse. Looks like a fern!

src: CourseSketches/Trees/Tree4/Tree4.pde

On-line learning resources

Further links